Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/pomona/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#node ⇒ Object
Returns the value of attribute node.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
Instance Method Summary collapse
- #has_children? ⇒ Boolean
- #has_grandchildren? ⇒ Boolean
-
#initialize(data_hash, id, parent_id) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(data_hash, id, parent_id) ⇒ Node
Returns a new instance of Node.
7 8 9 10 11 12 13 |
# File 'lib/pomona/node.rb', line 7 def initialize(data_hash, id, parent_id) @id = id node_data = { id: @id, children: [] } @node = data_hash.merge(node_data) @children = @node[:children] @parent_id = parent_id end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/pomona/node.rb', line 5 def children @children end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/pomona/node.rb', line 4 def id @id end |
#node ⇒ Object
Returns the value of attribute node.
5 6 7 |
# File 'lib/pomona/node.rb', line 5 def node @node end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
4 5 6 |
# File 'lib/pomona/node.rb', line 4 def parent_id @parent_id end |
Instance Method Details
#has_children? ⇒ Boolean
15 16 17 |
# File 'lib/pomona/node.rb', line 15 def has_children? children.any? end |
#has_grandchildren? ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/pomona/node.rb', line 19 def has_grandchildren? if has_children? children.select { |child| child.has_children? }.any? else false end end |