Class: Trainworks::Route
- Inherits:
-
Object
- Object
- Trainworks::Route
- Defined in:
- lib/trainworks/route.rb
Overview
Route is used to group together the information of an edge of a graph. From and To are two nodes and distance is the weight between them
Instance Attribute Summary collapse
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#from ⇒ Object
Returns the value of attribute from.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns
trueifother.from,other.toandother.distancehave the same value asself. -
#initialize(from:, to:, distance:) ⇒ Route
constructor
fromandtomust respond to#to_sanddistancemust respond to#to_f.
Constructor Details
#initialize(from:, to:, distance:) ⇒ Route
from and to must respond to #to_s and distance must respond to #to_f
13 14 15 16 17 |
# File 'lib/trainworks/route.rb', line 13 def initialize(from:, to:, distance:) self.from = from.to_s self.to = to.to_s self.distance = distance.to_f end |
Instance Attribute Details
#distance ⇒ Object
Returns the value of attribute distance.
6 7 8 |
# File 'lib/trainworks/route.rb', line 6 def distance @distance end |
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/trainworks/route.rb', line 6 def from @from end |
#to ⇒ Object
Returns the value of attribute to.
6 7 8 |
# File 'lib/trainworks/route.rb', line 6 def to @to end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if other.from, other.to and other.distance have the same value as self
22 23 24 25 26 |
# File 'lib/trainworks/route.rb', line 22 def ==(other) from == other.from && to == other.to && distance == other.distance end |