Class: Djikstra::Edge
- Inherits:
-
Object
- Object
- Djikstra::Edge
- Defined in:
- lib/djikstra/edge.rb
Instance Attribute Summary collapse
-
#graph ⇒ Object
Returns the value of attribute graph.
-
#start ⇒ Object
Returns the value of attribute start.
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(graph, start, stop, weight, line = 0) ⇒ Edge
constructor
A new instance of Edge.
Constructor Details
#initialize(graph, start, stop, weight, line = 0) ⇒ Edge
Returns a new instance of Edge.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/djikstra/edge.rb', line 5 def initialize(graph,start,stop,weight,line=0) raise ParseError, "Invalid edge on line #{line}" unless start && stop && weight @graph = graph @start = graph.find_node(start.to_s.upcase) @stop = graph.find_node(stop.to_s.upcase) @weight = Integer(weight) @start.neighbor_of(@stop, @weight) @stop.neighbor_of(@start, @weight) rescue TypeError, ArgumentError # Integer may raise this, so reraise as a ParseError raise ParseError, "Invalid weight on line #{line}" end |
Instance Attribute Details
#graph ⇒ Object
Returns the value of attribute graph.
3 4 5 |
# File 'lib/djikstra/edge.rb', line 3 def graph @graph end |
#start ⇒ Object
Returns the value of attribute start.
3 4 5 |
# File 'lib/djikstra/edge.rb', line 3 def start @start end |
#stop ⇒ Object
Returns the value of attribute stop.
3 4 5 |
# File 'lib/djikstra/edge.rb', line 3 def stop @stop end |
#weight ⇒ Object
Returns the value of attribute weight.
3 4 5 |
# File 'lib/djikstra/edge.rb', line 3 def weight @weight end |