Class: Rbgraph::Node
- Inherits:
-
Object
- Object
- Rbgraph::Node
- Defined in:
- lib/rbgraph/node.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#id ⇒ Object
Returns the value of attribute id.
-
#neighbors ⇒ Object
Returns the value of attribute neighbors.
Instance Method Summary collapse
- #connect_to(node, edge) ⇒ Object
- #hash ⇒ Object
-
#initialize(attributes = {}) ⇒ Node
constructor
A new instance of Node.
- #merge(node) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 15 16 |
# File 'lib/rbgraph/node.rb', line 10 def initialize(attributes = {}) self.attributes = attributes raise "Node should have an id attribute!" if attributes[:id].nil? self.id = attributes[:id] self.neighbors = {} self.edges = {} end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/rbgraph/node.rb', line 6 def attributes @attributes end |
#edges ⇒ Object
Returns the value of attribute edges.
8 9 10 |
# File 'lib/rbgraph/node.rb', line 8 def edges @edges end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/rbgraph/node.rb', line 5 def id @id end |
#neighbors ⇒ Object
Returns the value of attribute neighbors.
7 8 9 |
# File 'lib/rbgraph/node.rb', line 7 def neighbors @neighbors end |
Instance Method Details
#connect_to(node, edge) ⇒ Object
32 33 34 35 36 |
# File 'lib/rbgraph/node.rb', line 32 def connect_to(node, edge) neighbors[node.id] = node edges[edge.id] = edge self end |
#hash ⇒ Object
23 24 25 |
# File 'lib/rbgraph/node.rb', line 23 def hash id end |
#merge(node) ⇒ Object
27 28 29 30 |
# File 'lib/rbgraph/node.rb', line 27 def merge(node) attributes.merge!(node.attributes.reject { |k, v| k == :id }) self end |