Class: CherryTree::Node
- Inherits:
-
Object
- Object
- CherryTree::Node
- Defined in:
- lib/ursa/cherry-tree/node.rb
Constant Summary collapse
- DEEPNESS_SYMBOL =
'----'
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#data ⇒ Object
Returns the value of attribute data.
-
#deepness ⇒ Object
Returns the value of attribute deepness.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(data, parent, deepness) ⇒ Node
constructor
A new instance of Node.
- #to_s ⇒ Object
Constructor Details
#initialize(data, parent, deepness) ⇒ Node
Returns a new instance of Node.
7 8 9 10 11 12 |
# File 'lib/ursa/cherry-tree/node.rb', line 7 def initialize(data, parent, deepness) self.data = data self.parent = parent self.deepness = deepness self.children = [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
3 4 5 |
# File 'lib/ursa/cherry-tree/node.rb', line 3 def children @children end |
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/ursa/cherry-tree/node.rb', line 3 def data @data end |
#deepness ⇒ Object
Returns the value of attribute deepness.
3 4 5 |
# File 'lib/ursa/cherry-tree/node.rb', line 3 def deepness @deepness end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/ursa/cherry-tree/node.rb', line 3 def parent @parent end |
Instance Method Details
#to_s ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ursa/cherry-tree/node.rb', line 14 def to_s str = "" str << "#{DEEPNESS_SYMBOL * deepness}#{DEEPNESS_SYMBOL}#{data}\n" if children.any? children.each do |child| str << child.to_s end end str end |