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.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubyplb.rb', line 30

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.



29
30
31
# File 'lib/rubyplb.rb', line 29

def children
  @children
end

#dataObject

Returns the value of attribute data.



29
30
31
# File 'lib/rubyplb.rb', line 29

def data
  @data
end

#leafObject

Returns the value of attribute leaf.



29
30
31
# File 'lib/rubyplb.rb', line 29

def leaf
  @leaf
end

#levelObject

Returns the value of attribute level.



29
30
31
# File 'lib/rubyplb.rb', line 29

def level
  @level
end

#num_instancesObject

Returns the value of attribute num_instances.



29
30
31
# File 'lib/rubyplb.rb', line 29

def num_instances
  @num_instances
end

#parentsObject

Returns the value of attribute parents.



29
30
31
# File 'lib/rubyplb.rb', line 29

def parents
  @parents
end

Instance Method Details

#children_instancesObject



43
44
45
# File 'lib/rubyplb.rb', line 43

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