Class: Rbgraph::Edge

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node1, node2, attributes = {}) ⇒ Edge

Returns a new instance of Edge.



10
11
12
13
14
15
# File 'lib/rbgraph/edge.rb', line 10

def initialize(node1, node2, attributes = {})
  self.node1 = node1
  self.node2 = node2
  self.attributes = attributes
  self.id = attributes[:id] || "#{node1.id}=#{self.class}=#{node2.id}"
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#node1Object

Returns the value of attribute node1.



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

def node1
  @node1
end

#node2Object

Returns the value of attribute node2.



7
8
9
# File 'lib/rbgraph/edge.rb', line 7

def node2
  @node2
end

Instance Method Details

#hashObject



22
23
24
# File 'lib/rbgraph/edge.rb', line 22

def hash
  id
end

#merge(edge) ⇒ Object



26
27
28
29
# File 'lib/rbgraph/edge.rb', line 26

def merge(edge)
  attributes.merge!(edge.attributes.reject { |k, v| k == :id })
  self
end