Class: TodoNext::Tree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/todo_next/tree/node.rb

Direct Known Subclasses

EX, LI, OL

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/todo_next/tree/node.rb', line 5

def children
  @children
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/todo_next/tree/node.rb', line 5

def parent
  @parent
end

#textObject

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

Returns:

  • (Boolean)


12
# File 'lib/todo_next/tree/node.rb', line 12

def example?  ; false end

#has_children?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/todo_next/tree/node.rb', line 14

def has_children?
  !children.empty?
end

#make_me_a_leafObject



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_childrenObject



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

Returns:

  • (Boolean)


11
# File 'lib/todo_next/tree/node.rb', line 11

def terminal? ; false end