Class: Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyplb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Node

Returns a new instance of Node.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rubyplb.rb', line 35

def initialize(data)
  @data = data
  @level = data.select{|b| b != "_"}.size
  if @level == 0 
    @leaf = true
  else
    @leaf = false
  end
  @children = []
  @parents = []
  @num_instances = 1
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



34
35
36
# File 'lib/rubyplb.rb', line 34

def children
  @children
end

#dataObject

Returns the value of attribute data.



34
35
36
# File 'lib/rubyplb.rb', line 34

def data
  @data
end

#leafObject

Returns the value of attribute leaf.



34
35
36
# File 'lib/rubyplb.rb', line 34

def leaf
  @leaf
end

#levelObject

Returns the value of attribute level.



34
35
36
# File 'lib/rubyplb.rb', line 34

def level
  @level
end

#num_instancesObject

Returns the value of attribute num_instances.



34
35
36
# File 'lib/rubyplb.rb', line 34

def num_instances
  @num_instances
end

#parentsObject

Returns the value of attribute parents.



34
35
36
# File 'lib/rubyplb.rb', line 34

def parents
  @parents
end

Instance Method Details

#children_instancesObject



48
49
50
# File 'lib/rubyplb.rb', line 48

def children_instances
  @children.inject(0) { |sum, child| sum += child.num_instances }
end