Class: HierarchicalGraph::Node
- Inherits:
-
Object
- Object
- HierarchicalGraph::Node
- Defined in:
- lib/hierarchical_graph/node.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #ancestors ⇒ Object
- #children ⇒ Object
- #descendants ⇒ Object
-
#initialize(graph, id, data = {}) ⇒ Node
constructor
A new instance of Node.
- #parents ⇒ Object
- #root? ⇒ Boolean
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(graph, id, data = {}) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 |
# File 'lib/hierarchical_graph/node.rb', line 6 def initialize(graph, id, data={}) @graph = graph @id = id @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/hierarchical_graph/node.rb', line 4 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/hierarchical_graph/node.rb', line 4 def id @id end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/hierarchical_graph/node.rb', line 12 def [](key) data[key] end |
#[]=(key, value) ⇒ Object
16 17 18 |
# File 'lib/hierarchical_graph/node.rb', line 16 def []=(key, value) data[key] = value end |
#ancestors ⇒ Object
28 29 30 |
# File 'lib/hierarchical_graph/node.rb', line 28 def ancestors graph.ancestors_of id end |
#children ⇒ Object
24 25 26 |
# File 'lib/hierarchical_graph/node.rb', line 24 def children graph.children_of id end |
#descendants ⇒ Object
32 33 34 |
# File 'lib/hierarchical_graph/node.rb', line 32 def descendants graph.descendants_of id end |
#parents ⇒ Object
20 21 22 |
# File 'lib/hierarchical_graph/node.rb', line 20 def parents graph.parents_of id end |
#root? ⇒ Boolean
36 37 38 |
# File 'lib/hierarchical_graph/node.rb', line 36 def root? parents.empty? end |
#to_s ⇒ Object Also known as: inspect
40 41 42 |
# File 'lib/hierarchical_graph/node.rb', line 40 def to_s "<#{self.class.name} #{id} parents:[#{parents.map(&:id).join(', ')}] children:[#{children.map(&:id).join(', ')}]>" end |