Class: MapQuest::Services::Directions::Response

Inherits:
Response
  • Object
show all
Defined in:
lib/mapquest/services/directions.rb

Instance Attribute Summary

Attributes inherited from Response

#params, #response, #valid

Instance Method Summary collapse

Methods inherited from Response

#copyright, #info, #options, #status, #valid_request?

Constructor Details

#initialize(response_string, params = {}) ⇒ Response

Returns a new instance of Response.



28
29
30
# File 'lib/mapquest/services/directions.rb', line 28

def initialize(response_string, params = {})
  super
end

Instance Method Details

#distanceObject

Returns the calculated distance of the route in miles



42
43
44
45
46
# File 'lib/mapquest/services/directions.rb', line 42

def distance
  if valid
    route[:distance].to_i
  end
end

#locationsObject



48
49
50
51
52
# File 'lib/mapquest/services/directions.rb', line 48

def locations
  if valid
    route[:locations]
  end
end

#maneuversObject

Returns a hash of the maneuvers in the route



55
56
57
58
59
# File 'lib/mapquest/services/directions.rb', line 55

def maneuvers
  if valid
    route[:legs].first[:maneuvers]
  end
end

#narrativeObject

Returns only the narratives for the route as a list



62
63
64
65
66
# File 'lib/mapquest/services/directions.rb', line 62

def narrative
  if valid
    route[:legs].first[:maneuvers].map { |maneuver| maneuver[:narrative] }
  end
end

#routeObject



32
33
34
# File 'lib/mapquest/services/directions.rb', line 32

def route
  response[:route]
end

#timeObject

Returns the drive time in minutes



37
38
39
# File 'lib/mapquest/services/directions.rb', line 37

def time
  (route[:time].to_i / 60).ceil
end