Class: TodoNext::Tree::Node
- Inherits:
-
Object
- Object
- TodoNext::Tree::Node
- Defined in:
- lib/todo_next/tree/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #example? ⇒ Boolean
- #has_children? ⇒ Boolean
-
#initialize(text, parent = nil) ⇒ Node
constructor
A new instance of Node.
- #make_me_a_leaf ⇒ Object
- #remove_from_parent_children ⇒ Object
- #terminal? ⇒ Boolean
Constructor Details
#initialize(text, parent = nil) ⇒ Node
Returns a new instance of Node.
6 7 8 9 |
# File 'lib/todo_next/tree/node.rb', line 6 def initialize(text, parent=nil) @text, @parent = text, parent @children = [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/todo_next/tree/node.rb', line 5 def children @children end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/todo_next/tree/node.rb', line 5 def parent @parent end |
#text ⇒ Object
Returns the value of attribute text.
5 6 7 |
# File 'lib/todo_next/tree/node.rb', line 5 def text @text end |
Instance Method Details
#example? ⇒ Boolean
12 |
# File 'lib/todo_next/tree/node.rb', line 12 def example? ; false end |
#has_children? ⇒ Boolean
14 15 16 |
# File 'lib/todo_next/tree/node.rb', line 14 def has_children? !children.empty? end |
#make_me_a_leaf ⇒ Object
24 25 26 27 28 |
# File 'lib/todo_next/tree/node.rb', line 24 def make_me_a_leaf me_as_leaf = Tree::LI.new(text, parent) idx = parent.children.find_index(self) parent.children[idx] = me_as_leaf end |
#remove_from_parent_children ⇒ Object
18 19 20 21 22 |
# File 'lib/todo_next/tree/node.rb', line 18 def remove_from_parent_children parent.children.delete_if do |child| child==self end end |
#terminal? ⇒ Boolean
11 |
# File 'lib/todo_next/tree/node.rb', line 11 def terminal? ; false end |