Class: Rbgraph::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rbgraph/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject

Returns the value of attribute attributes.



6
7
8
# File 'lib/rbgraph/node.rb', line 6

def attributes
  @attributes
end

#edgesObject

Returns the value of attribute edges.



8
9
10
# File 'lib/rbgraph/node.rb', line 8

def edges
  @edges
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/rbgraph/node.rb', line 5

def id
  @id
end

#neighborsObject

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

#hashObject



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