Class: AbsNode
- Inherits:
-
Object
- Object
- AbsNode
- Defined in:
- lib/tree_visitor/abs_node.rb
Overview
Nodo Astratto
Gerarchia delle classi
AbsNode ha un nome, un parent
| definisce un path
|
|- LeafNode
|
|- TreeNode
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
solo TreeNode puo’ scrivere vedi funzione add_leaf.
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_from_root ⇒ Object
- #prefix_path ⇒ Object
- #prefix_path=(prefix) ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(name) ⇒ AbsNode
Returns a new instance of AbsNode.
27 28 29 30 31 32 |
# File 'lib/tree_visitor/abs_node.rb', line 27 def initialize( name ) @parent = nil @name = name @prefix_path = nil invalidate end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/tree_visitor/abs_node.rb', line 20 def name @name end |
#next ⇒ Object
Returns the value of attribute next.
24 25 26 |
# File 'lib/tree_visitor/abs_node.rb', line 24 def next @next end |
#parent ⇒ Object
Returns the value of attribute parent.
19 20 21 |
# File 'lib/tree_visitor/abs_node.rb', line 19 def parent @parent end |
#prev ⇒ Object
solo TreeNode puo’ scrivere vedi funzione add_leaf
23 24 25 |
# File 'lib/tree_visitor/abs_node.rb', line 23 def prev @prev end |
Instance Method Details
#accept(visitor) ⇒ Object
106 107 108 |
# File 'lib/tree_visitor/abs_node.rb', line 106 def accept( visitor ) not_implemented end |
#depth ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/tree_visitor/abs_node.rb', line 96 def depth return @depth unless @depth.nil? if @parent.nil? @depth = 1 else @depth = @parent.depth + 1 end @depth end |
#invalidate ⇒ Object
invalidate cached info
37 38 39 40 41 |
# File 'lib/tree_visitor/abs_node.rb', line 37 def invalidate @path = nil @path_from_root = nil @depth = nil end |
#path ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tree_visitor/abs_node.rb', line 68 def path return @path unless @path.nil? if @parent.nil? if @prefix_path @path = @prefix_path + @name else @path = @name end else @path = File.join( @parent.path, @name ) end @path end |
#path_from_root ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/tree_visitor/abs_node.rb', line 82 def path_from_root return @path_from_root unless @path_from_root.nil? if @parent.nil? if @prefix_path @path_from_root = @prefix_path else @path_from_root = "" end else @path_from_root = File.join( @parent.path_from_root, @name ) end @path_from_root end |
#prefix_path ⇒ Object
43 44 45 46 47 48 |
# File 'lib/tree_visitor/abs_node.rb', line 43 def prefix_path if not @parent.nil? raise "Not root!!" end @prefix_path end |
#prefix_path=(prefix) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/tree_visitor/abs_node.rb', line 50 def prefix_path=( prefix ) if not @parent.nil? raise "Not root!!" end if prefix != @prefix_path @prefix_path = prefix invalidate end end |
#root ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/tree_visitor/abs_node.rb', line 60 def root if root? self else parent.root end end |