Class: Newral::Graphs::Edge

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: nil, start_node: nil, end_node: nil, directed: false, cost: nil, data: nil) ⇒ Edge

Returns a new instance of Edge.



5
6
7
8
9
10
11
12
13
# File 'lib/newral/graphs/edge.rb', line 5

def initialize( key:nil, start_node: nil, end_node: nil, directed: false, cost: nil, data:nil )
  @key = key
  @start_node = start_node
  @end_node = end_node
  @directed = directed
  @cost = cost
  @data = data
  
end

Instance Attribute Details

#costObject

Returns the value of attribute cost.



4
5
6
# File 'lib/newral/graphs/edge.rb', line 4

def cost
  @cost
end

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/newral/graphs/edge.rb', line 4

def data
  @data
end

#directedObject

Returns the value of attribute directed.



4
5
6
# File 'lib/newral/graphs/edge.rb', line 4

def directed
  @directed
end

#end_nodeObject

Returns the value of attribute end_node.



4
5
6
# File 'lib/newral/graphs/edge.rb', line 4

def end_node
  @end_node
end

#start_nodeObject

Returns the value of attribute start_node.



4
5
6
# File 'lib/newral/graphs/edge.rb', line 4

def start_node
  @start_node
end

Instance Method Details

#keyObject



15
16
17
# File 'lib/newral/graphs/edge.rb', line 15

def key 
  @key || "#{ @start_node }#{ directed ? '=>' : '<=>' }#{ @end_node }"
end

#to_sObject



19
20
21
# File 'lib/newral/graphs/edge.rb', line 19

def to_s 
  key
end