class RD::Tree

document tree

Constants

SYSTEM_NAME
SYSTEM_VERSION
TMP_DIR
VERSION

Attributes

document_struct[R]
filter[R]
filters[R]
include_path[RW]
include_path=[RW]
include_paths[RW]
root[R]
tmp_dir[RW]

Public Class Methods

new(document_struct, src_str = nil, include_paths = []) click to toggle source
# File lib/rd/tree.rb, line 39
def initialize(document_struct, src_str = nil, include_paths = [])
  @src = src_str
  @document_struct = document_struct
  @include_paths = include_paths
  @filters = Hash.new()
  @tmp_dir = TMP_DIR
  @root = nil
end
new_from_rdo(*rdos) click to toggle source
# File lib/rd/tree.rb, line 92
def Tree.new_from_rdo(*rdos) # rdos: IOs
  tree = Tree.new("", [], nil)
  tree_content = []
  rdos.each do |i|
    subtree = Marshal.load(i)
    tree_content.concat(subtree.root.blocks)
  end
  tree.root = DocumentElement.new(tree_content)
  tree
end
new_with_document_struct(document_struct, include_paths = []) click to toggle source
# File lib/rd/tree.rb, line 35
def Tree.new_with_document_struct(document_struct, include_paths = [])
  Tree.new(document_struct, nil, include_paths)
end
tmp_dir() click to toggle source
# File lib/rd/tree.rb, line 22
def Tree.tmp_dir
  TMP_DIR
end
version() click to toggle source
# File lib/rd/tree.rb, line 16
def Tree.version
  VERSION
end

Public Instance Methods

accept(visitor) click to toggle source
# File lib/rd/tree.rb, line 78
def accept(visitor)
  @root.accept(visitor)
end
check_valid() click to toggle source
# File lib/rd/tree.rb, line 69
def check_valid
  each_element do |i|
    raise RuntimeError,
      "mismatched document structure, #{i.parent} <-/- #{i}." unless
      @document_struct.is_valid?(i.parent, i)
  end
  true
end
each(&block)
Alias for: each_element
each_element(&block) click to toggle source
# File lib/rd/tree.rb, line 82
def each_element(&block)
  return nil unless @root
  @root.each(&block)
end
Also aliased as: each
make_root(&block) click to toggle source
# File lib/rd/tree.rb, line 62
def make_root(&block)
  child = DocumentElement.new
  set_root(child)
  child.build(&block) if block_given?
  child
end
parse() click to toggle source
# File lib/rd/tree.rb, line 48
def parse
  parser = RDParser.new
  src = @src.respond_to?(:to_a) ? @src.to_a : @src.split(/^/)
  set_root(parser.parse(src, self))
end
root=(element)
Alias for: set_root
set_root(element) click to toggle source
# File lib/rd/tree.rb, line 54
def set_root(element)
  raise ArgumentError, "#{element.class} can't be root." unless
    @document_struct.is_valid?(self, element)
  @root = element
  element.parent = self
end
Also aliased as: root=
tree() click to toggle source
# File lib/rd/tree.rb, line 88
def tree
  self
end