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.



9
10
11
12
# File 'lib/junoser/rule_tree/node.rb', line 9

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

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#<<(child) ⇒ Object



14
15
16
# File 'lib/junoser/rule_tree/node.rb', line 14

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


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

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