Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/rubyplb.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#data ⇒ Object
Returns the value of attribute data.
-
#leaf ⇒ Object
Returns the value of attribute leaf.
-
#level ⇒ Object
Returns the value of attribute level.
-
#num_instances ⇒ Object
Returns the value of attribute num_instances.
-
#parents ⇒ Object
Returns the value of attribute parents.
Instance Method Summary collapse
- #children_instances ⇒ Object
-
#initialize(data) ⇒ Node
constructor
A new instance of Node.
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
#children ⇒ Object
Returns the value of attribute children.
34 35 36 |
# File 'lib/rubyplb.rb', line 34 def children @children end |
#data ⇒ Object
Returns the value of attribute data.
34 35 36 |
# File 'lib/rubyplb.rb', line 34 def data @data end |
#leaf ⇒ Object
Returns the value of attribute leaf.
34 35 36 |
# File 'lib/rubyplb.rb', line 34 def leaf @leaf end |
#level ⇒ Object
Returns the value of attribute level.
34 35 36 |
# File 'lib/rubyplb.rb', line 34 def level @level end |
#num_instances ⇒ Object
Returns the value of attribute num_instances.
34 35 36 |
# File 'lib/rubyplb.rb', line 34 def num_instances @num_instances end |
#parents ⇒ Object
Returns the value of attribute parents.
34 35 36 |
# File 'lib/rubyplb.rb', line 34 def parents @parents end |
Instance Method Details
#children_instances ⇒ Object
48 49 50 |
# File 'lib/rubyplb.rb', line 48 def children_instances @children.inject(0) { |sum, child| sum += child.num_instances } end |