-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.rb
63 lines (49 loc) · 1.02 KB
/
response.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
require 'active_support/core_ext/hash/slice'
module GoogleMapsJuice
class Directions::Response < GoogleMapsJuice::Endpoint::Response
def results
self['routes']
end
def routes
results.map { |r| Route.new(r) }
end
def first
routes.first
end
class Route
attr_reader :route, :first_leg
def initialize(route)
@route = route
@first_leg = route['legs'].first
end
def legs
route['legs']
end
def summary
route['summary']
end
def steps
first_leg['steps']
end
def duration
first_leg['duration']
end
def distance
first_leg['distance']
end
def start_location
first_leg['start_location']
end
def end_location
first_leg['end_location']
end
def start_address
first_leg['start_address']
end
def end_address
first_leg['end_address']
end
end
end
end