Class: RD::Tree
Overview
document tree
Direct Known Subclasses
Constant Summary collapse
- SYSTEM_NAME =
"RDtool Framework -- Document Tree"
- SYSTEM_VERSION =
"$Version: "+RD::VERSION+"$"
- VERSION =
Version.new_from_version_string(SYSTEM_NAME, SYSTEM_VERSION)
- TMP_DIR =
"/tmp"
Instance Attribute Summary collapse
-
#document_struct ⇒ Object
readonly
Returns the value of attribute document_struct.
-
#filters ⇒ Object
(also: #filter)
readonly
Returns the value of attribute filters.
-
#include_paths ⇒ Object
(also: #include_path)
Returns the value of attribute include_paths.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
Class Method Summary collapse
-
.new_from_rdo(*rdos) ⇒ Object
rdos: IOs.
- .new_with_document_struct(document_struct, include_paths = []) ⇒ Object
- .tmp_dir ⇒ Object
- .version ⇒ Object
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #check_valid ⇒ Object
- #each_element(&block) ⇒ Object (also: #each)
-
#initialize(document_struct, src_str = nil, include_paths = []) ⇒ Tree
constructor
A new instance of Tree.
- #make_root(&block) ⇒ Object
- #parse ⇒ Object
- #set_root(element) ⇒ Object (also: #root=)
- #tree ⇒ Object
Constructor Details
#initialize(document_struct, src_str = nil, include_paths = []) ⇒ Tree
Returns a new instance of Tree.
39 40 41 42 43 44 45 46 |
# 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 |
Instance Attribute Details
#document_struct ⇒ Object (readonly)
Returns the value of attribute document_struct.
27 28 29 |
# File 'lib/rd/tree.rb', line 27 def document_struct @document_struct end |
#filters ⇒ Object (readonly) Also known as: filter
Returns the value of attribute filters.
31 32 33 |
# File 'lib/rd/tree.rb', line 31 def filters @filters end |
#include_paths ⇒ Object Also known as: include_path
Returns the value of attribute include_paths.
28 29 30 |
# File 'lib/rd/tree.rb', line 28 def include_paths @include_paths end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
26 27 28 |
# File 'lib/rd/tree.rb', line 26 def root @root end |
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
33 34 35 |
# File 'lib/rd/tree.rb', line 33 def tmp_dir @tmp_dir end |
Class Method Details
.new_from_rdo(*rdos) ⇒ Object
rdos: IOs
92 93 94 95 96 97 98 99 100 101 |
# 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 |
Instance Method Details
#accept(visitor) ⇒ Object
78 79 80 |
# File 'lib/rd/tree.rb', line 78 def accept(visitor) @root.accept(visitor) end |
#check_valid ⇒ Object
69 70 71 72 73 74 75 76 |
# 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_element(&block) ⇒ Object Also known as: each
82 83 84 85 |
# File 'lib/rd/tree.rb', line 82 def each_element(&block) return nil unless @root @root.each(&block) end |
#make_root(&block) ⇒ Object
62 63 64 65 66 67 |
# 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 ⇒ Object
48 49 50 51 52 |
# 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 |
#set_root(element) ⇒ Object Also known as: root=
54 55 56 57 58 59 |
# 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 |
#tree ⇒ Object
88 89 90 |
# File 'lib/rd/tree.rb', line 88 def tree self end |