class DocbookFiles::FileRef

A FileRef represents a file inclusion (<xi:include href=‘…’) or reference (<imagedata filref==‘…’) in DocBook. It points to a FileData instance, that represents the actual file. Multiple FileRefs can point to the same FileData.

A FileRef contains

Attributes

file_data[RW]

TODO file and line?

includes[R]
parent[RW]

TODO file and line?

refs[R]
rel_type[RW]

TODO file and line?

Public Class Methods

new(name,parent_dir=".",parent_file=nil) click to toggle source
# File lib/docbook_files/file_ref.rb, line 19
def initialize(name,parent_dir=".",parent_file=nil)
  @file_data = FileData.for(name,parent_dir)
  @parent = (parent_file.nil? ? nil : parent_file.name)
  @includes = []
  @refs = []
end

Public Instance Methods

find_non_existing_files() click to toggle source

Return the names and parent files of non-existing files

# File lib/docbook_files/file_ref.rb, line 68
def find_non_existing_files
  files = traverse([:name, :status, :parent])
  files.flatten.reject{|f| f[:status] != FileData::STATUS_NOT_FOUND}.map{|f| f.delete(:status); f}
end
includes=(incs) click to toggle source
# File lib/docbook_files/file_ref.rb, line 30
def includes=(incs)
  @includes = incs
  @file_data.add_includes(incs.map{|inc| inc.file_data})
end
method_missing(name, *args, &block) click to toggle source
# File lib/docbook_files/file_ref.rb, line 26
def method_missing(name, *args, &block)
  @file_data.send(name,*args, &block)
end
names() click to toggle source

Return a tree-like array with all names

# File lib/docbook_files/file_ref.rb, line 74
def names
  self.traverse([:name])
end
refs=(refs) click to toggle source
# File lib/docbook_files/file_ref.rb, line 35
def refs=(refs)
  @refs = refs
  @file_data.add_references(refs.map{|ref| ref.file_data})
end
to_hash(props,type) click to toggle source

Return a hash with the values for the passed symbols. The type is added.

Example: to_hash([:name, :mime]) would return

{:type => "main", :name => "name", :mime => "application/xml"}.
# File lib/docbook_files/file_ref.rb, line 46
def to_hash(props,type)
  me_hash = {:type => type}
  props.each {|p| me_hash[p] = self.send(p)}
  me_hash
end
traverse(props=[],type=FileRefTypes::TYPE_MAIN) click to toggle source

Return a tree-like array of maps with the requested properties (symbols)

# File lib/docbook_files/file_ref.rb, line 54
def traverse(props=[],type=FileRefTypes::TYPE_MAIN)
  me = self.to_hash(props,type)
  me2 = [me]
  unless self.refs.empty?()
    me2 += self.refs.map {|r| r.to_hash(props,FileRefTypes::TYPE_REFERENCE)}
  end
  if self.includes.empty?()
    me2
  else
    me2 + self.includes.map {|i| i.traverse(props,FileRefTypes::TYPE_INCLUDE)}
  end
end
traverse_as_table(props,level=0,type=FileRefTypes::TYPE_MAIN) click to toggle source

Return a table-like array of maps with the requested properties (symbols). Each entry gets a level indicator (:level) to show the tree-level.

# File lib/docbook_files/file_ref.rb, line 83
def traverse_as_table(props,level=0,type=FileRefTypes::TYPE_MAIN)
  me = self.to_hash(props,type)
  me[:level] = level
  me2 = [me]
  unless self.refs.empty?()
    me2 += self.refs.map {|r| x = r.to_hash(props,FileRefTypes::TYPE_REFERENCE); x[:level] = level+1; x}
  end
  unless self.includes.empty?()
    me2 += self.includes.map {|i| i.traverse_as_table(props,level+1,FileRefTypes::TYPE_INCLUDE)}
  end
  me2.flatten
end