Class: Junoser::RuleTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/junoser/rule_tree/node.rb

Constant Summary collapse

INDENT =
'    '

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Node

Returns a new instance of Node.



7
8
9
10
# File 'lib/junoser/rule_tree/node.rb', line 7

def initialize(name)
  @name = name
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/junoser/rule_tree/node.rb', line 5

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/junoser/rule_tree/node.rb', line 5

def name
  @name
end

Instance Method Details

#<<(child) ⇒ Object



12
13
14
# File 'lib/junoser/rule_tree/node.rb', line 12

def <<(child)
  @children << child
end


16
17
18
19
20
21
# File 'lib/junoser/rule_tree/node.rb', line 16

def print(level = 0)
  puts INDENT * level + "- #{@name}"
  @children.each do |child|
    child.print level + 1
  end
end