Class: Roadtrip::Trip
Instance Attribute Summary collapse
-
#cost_per_gallon ⇒ Object
Returns the value of attribute cost_per_gallon.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#mpg ⇒ Object
Returns the value of attribute mpg.
-
#start ⇒ Object
Returns the value of attribute start.
Instance Method Summary collapse
- #cost ⇒ Object
- #distance ⇒ Object
- #distance_in_miles ⇒ Object
- #duration ⇒ Object
-
#initialize(start, destination, cost_per_gallon, mpg) ⇒ Trip
constructor
A new instance of Trip.
- #round_trip_cost ⇒ Object
- #trip ⇒ Object
Constructor Details
#initialize(start, destination, cost_per_gallon, mpg) ⇒ Trip
Returns a new instance of Trip.
21 22 23 24 25 26 |
# File 'lib/roadtrip.rb', line 21 def initialize(start, destination, cost_per_gallon, mpg) @start = start @destination = destination @cost_per_gallon = cost_per_gallon @mpg = mpg end |
Instance Attribute Details
#cost_per_gallon ⇒ Object
Returns the value of attribute cost_per_gallon.
19 20 21 |
# File 'lib/roadtrip.rb', line 19 def cost_per_gallon @cost_per_gallon end |
#destination ⇒ Object
Returns the value of attribute destination.
19 20 21 |
# File 'lib/roadtrip.rb', line 19 def destination @destination end |
#mpg ⇒ Object
Returns the value of attribute mpg.
19 20 21 |
# File 'lib/roadtrip.rb', line 19 def mpg @mpg end |
#start ⇒ Object
Returns the value of attribute start.
19 20 21 |
# File 'lib/roadtrip.rb', line 19 def start @start end |
Instance Method Details
#cost ⇒ Object
49 50 51 |
# File 'lib/roadtrip.rb', line 49 def cost distance_in_miles * self.cost_per_gallon / mpg end |
#distance ⇒ Object
37 38 39 |
# File 'lib/roadtrip.rb', line 37 def distance trip["routes"][0]["legs"][0]["distance"]["text"] end |
#distance_in_miles ⇒ Object
45 46 47 |
# File 'lib/roadtrip.rb', line 45 def distance_in_miles MILES_PER_METER * trip["routes"][0]["legs"][0]["distance"]["value"] end |
#duration ⇒ Object
41 42 43 |
# File 'lib/roadtrip.rb', line 41 def duration trip["routes"][0]["legs"][0]["duration"]["text"] end |
#round_trip_cost ⇒ Object
53 54 55 |
# File 'lib/roadtrip.rb', line 53 def round_trip_cost self.cost * 2 end |
#trip ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/roadtrip.rb', line 28 def trip Trip.get('http://maps.google.com/maps/api/directions/json?', :query => { :origin => self.start, :destination => self.destination, :sensor => "false" }) end |