Class: AbsNode
- Inherits:
-
Object
- Object
- AbsNode
- Defined in:
- lib/treevisitor/abs_node.rb
Overview
Abstract Node
Class hierarchy
AbsNode has a name, a parent
^ and define a path i.e. concatenation ancestor names
|
|-- LeafNode
|
`-- TreeNode
Object diagram
TreeNode (parent: nil)
|
|--->[ LeafNode, LeafNode, LeafNode ]
|
|--->[ TreeNode, TreeNode ]
|
|--> [LeafNode]
|
`--> [TreeNode, TreeNode]
Class Attribute Summary collapse
-
.path_separator ⇒ Object
Returns the value of attribute path_separator.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#next ⇒ Object
Returns the value of attribute next.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#prev ⇒ Object
Returns the value of attribute prev.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #depth ⇒ Object
-
#initialize(name) ⇒ AbsNode
constructor
A new instance of AbsNode.
-
#invalidate ⇒ Object
invalidate cached info.
- #path ⇒ Object
- #path_with_prefix ⇒ Object
- #prefix_path ⇒ Object
- #prefix_path=(prefix) ⇒ Object
- #root ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ AbsNode
Returns a new instance of AbsNode.
40 41 42 43 44 45 |
# File 'lib/treevisitor/abs_node.rb', line 40 def initialize( name ) @parent = nil @name = name @prefix_path = nil invalidate end |
Class Attribute Details
.path_separator ⇒ Object
Returns the value of attribute path_separator.
30 31 32 |
# File 'lib/treevisitor/abs_node.rb', line 30 def path_separator @path_separator end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/treevisitor/abs_node.rb', line 35 def name @name end |
#next ⇒ Object
Returns the value of attribute next.
38 39 40 |
# File 'lib/treevisitor/abs_node.rb', line 38 def next @next end |
#parent ⇒ Object
Returns the value of attribute parent.
34 35 36 |
# File 'lib/treevisitor/abs_node.rb', line 34 def parent @parent end |
#prev ⇒ Object
Returns the value of attribute prev.
37 38 39 |
# File 'lib/treevisitor/abs_node.rb', line 37 def prev @prev end |
Instance Method Details
#accept(visitor) ⇒ Object
107 108 109 |
# File 'lib/treevisitor/abs_node.rb', line 107 def accept( visitor ) not_implemented end |
#depth ⇒ Object
101 102 103 104 105 |
# File 'lib/treevisitor/abs_node.rb', line 101 def depth return @depth unless @depth.nil? @depth = @parent.nil? ? 1 : @parent.depth + 1 @depth end |
#invalidate ⇒ Object
invalidate cached info
50 51 52 53 54 |
# File 'lib/treevisitor/abs_node.rb', line 50 def invalidate @path = nil @path_with_prefix = nil @depth = nil end |
#path ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/treevisitor/abs_node.rb', line 81 def path return @path unless @path.nil? if @parent.nil? @path = @name else @path = @parent.path + AbsNode::path_separator + @name end @path end |
#path_with_prefix ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/treevisitor/abs_node.rb', line 91 def path_with_prefix return @path_with_prefix unless @path_with_prefix.nil? if @parent.nil? @path_with_prefix = @prefix_path.nil? ? @name : @prefix_path + @name else @path_with_prefix = @parent.path_with_prefix + AbsNode::path_separator + @name end @path_with_prefix end |
#prefix_path ⇒ Object
56 57 58 59 60 61 |
# File 'lib/treevisitor/abs_node.rb', line 56 def prefix_path if not @parent.nil? raise "Not root!!" end @prefix_path end |
#prefix_path=(prefix) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/treevisitor/abs_node.rb', line 63 def prefix_path=( prefix ) if not @parent.nil? raise "Not root!!" end if prefix != @prefix_path @prefix_path = prefix invalidate end end |
#root ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/treevisitor/abs_node.rb', line 73 def root if root? self else parent.root end end |
#to_s ⇒ Object
111 112 113 |
# File 'lib/treevisitor/abs_node.rb', line 111 def to_s @name.to_s end |