Class: Lina::TreeNode
- Inherits:
-
Object
- Object
- Lina::TreeNode
- Defined in:
- lib/lina/tree.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #add_value(value) ⇒ Object
- #find_child(path) ⇒ Object
-
#initialize(path, parent = nil) ⇒ TreeNode
constructor
A new instance of TreeNode.
- #real_path ⇒ Object
- #root? ⇒ Boolean
Constructor Details
#initialize(path, parent = nil) ⇒ TreeNode
Returns a new instance of TreeNode.
69 70 71 72 73 74 |
# File 'lib/lina/tree.rb', line 69 def initialize(path, parent =nil) @path = path @children = [] @parent = parent @values = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
68 69 70 |
# File 'lib/lina/tree.rb', line 68 def children @children end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
68 69 70 |
# File 'lib/lina/tree.rb', line 68 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
68 69 70 |
# File 'lib/lina/tree.rb', line 68 def path @path end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
68 69 70 |
# File 'lib/lina/tree.rb', line 68 def values @values end |
Instance Method Details
#add_child(child) ⇒ Object
93 94 95 96 |
# File 'lib/lina/tree.rb', line 93 def add_child(child) @children << child child end |
#add_value(value) ⇒ Object
76 77 78 |
# File 'lib/lina/tree.rb', line 76 def add_value(value) @values << value end |
#find_child(path) ⇒ Object
98 99 100 |
# File 'lib/lina/tree.rb', line 98 def find_child(path) @children.find { |child| child.path == path } end |
#real_path ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/lina/tree.rb', line 80 def real_path ret_path = [ @path ] node = self while(node = node.parent) ret_path.unshift(node.path) end ret_path.join('/') end |
#root? ⇒ Boolean
89 90 91 |
# File 'lib/lina/tree.rb', line 89 def root? @parent.nil? end |