geogle 0.3.1 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -1
- data/lib/geogle/model/route.rb +22 -0
- data/lib/geogle/parametizer.rb +1 -0
- data/lib/geogle/version.rb +1 -1
- data/spec/fixtures/cassettes/directions_by_address.yml +897 -792
- data/spec/fixtures/cassettes/directions_by_address_no_results.yml +6 -6
- data/spec/fixtures/cassettes/directions_by_latlng.yml +897 -793
- data/spec/geogle/model/leg_spec.rb +23 -0
- data/spec/geogle/parser_spec.rb +213 -213
- metadata +4 -2
@@ -0,0 +1,23 @@
|
|
1
|
+
describe Geogle::Model::Leg do
|
2
|
+
let(:route) do
|
3
|
+
VCR.use_cassette('directions_by_address') do
|
4
|
+
Geogle::Directions.new.routes("Valencia", "Madrid", { region: "es" }).first
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
it "duration" do
|
9
|
+
expect(route.duration).to eq(12745)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "distance" do
|
13
|
+
expect(route.distance).to eq(355040)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "origin" do
|
17
|
+
expect(route.origin).to eq("Valencia, Valencia, Spain")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "destination" do
|
21
|
+
expect(route.destination).to eq("Madrid, Madrid, Spain")
|
22
|
+
end
|
23
|
+
end
|
data/spec/geogle/parser_spec.rb
CHANGED
@@ -1,325 +1,325 @@
|
|
1
1
|
describe 'Parser' do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
describe "places" do
|
4
|
+
let(:places) do
|
5
|
+
VCR.use_cassette('geocode_by_latlng') do
|
6
|
+
Geogle::Geocoder.new.latlng(39.4699075, -0.3762881)
|
8
7
|
end
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
it "returns an array of Geogle::Model::Places" do
|
11
|
+
expect(places).to be_kind_of(Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "each element is Geogle::Model::Place" do
|
15
|
+
expect(places.first).to be_kind_of(Geogle::Model::Place)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "place" do
|
19
|
+
let(:place) { places.first }
|
20
|
+
|
21
|
+
it "geo_location" do
|
22
|
+
expect(place.geo_location.to_s).to eq("39.4701016,-0.3761823")
|
12
23
|
end
|
13
24
|
|
14
|
-
it "
|
15
|
-
expect(
|
25
|
+
it "street" do
|
26
|
+
expect(place.street).to eq("Plaza Ayuntamiento")
|
16
27
|
end
|
17
28
|
|
18
|
-
|
19
|
-
|
29
|
+
it "locality" do
|
30
|
+
expect(place.locality).to eq("Valencia")
|
31
|
+
end
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
it "city" do
|
34
|
+
expect(place.city).to eq("Valencia")
|
35
|
+
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
37
|
+
it "state" do
|
38
|
+
expect(place.state).to eq("Valencian Community")
|
39
|
+
end
|
28
40
|
|
29
|
-
|
30
|
-
|
31
|
-
|
41
|
+
it "country" do
|
42
|
+
expect(place.country).to eq("Spain")
|
43
|
+
end
|
32
44
|
|
33
|
-
|
34
|
-
|
35
|
-
|
45
|
+
it "country_code" do
|
46
|
+
expect(place.country_code).to eq("ES")
|
47
|
+
end
|
36
48
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
49
|
+
describe "geometry" do
|
50
|
+
let(:geometry) { place.geometry }
|
40
51
|
|
41
|
-
it "
|
42
|
-
expect(
|
52
|
+
it "location_type" do
|
53
|
+
expect(geometry.location_type).to eq("ROOFTOP")
|
43
54
|
end
|
44
55
|
|
45
|
-
|
46
|
-
|
56
|
+
describe "location" do
|
57
|
+
let(:location) { geometry.location }
|
58
|
+
|
59
|
+
it "has latitude" do
|
60
|
+
expect(location.lat).to eq(39.4701016)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has longitude" do
|
64
|
+
expect(location.lng).to eq(-0.3761823)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "to_s" do
|
68
|
+
expect(location.to_s).to eq("39.4701016,-0.3761823")
|
69
|
+
end
|
47
70
|
end
|
48
71
|
|
49
|
-
describe "
|
50
|
-
let(:
|
72
|
+
describe "bounds" do
|
73
|
+
let(:bounds) { geometry.bounds }
|
51
74
|
|
52
|
-
it "
|
53
|
-
expect(
|
75
|
+
it "they are nil when there are not" do
|
76
|
+
expect(bounds).to be_nil
|
54
77
|
end
|
78
|
+
end
|
55
79
|
|
56
|
-
|
57
|
-
|
80
|
+
describe "viewport" do
|
81
|
+
let(:viewport) { geometry.viewport }
|
82
|
+
|
83
|
+
describe "southwest" do
|
84
|
+
let(:southwest) { viewport.southwest }
|
58
85
|
|
59
86
|
it "has latitude" do
|
60
|
-
expect(
|
87
|
+
expect(southwest.lat).to eq(39.4687526197085)
|
61
88
|
end
|
62
89
|
|
63
90
|
it "has longitude" do
|
64
|
-
expect(
|
65
|
-
end
|
66
|
-
|
67
|
-
it "to_s" do
|
68
|
-
expect(location.to_s).to eq("39.4701016,-0.3761823")
|
91
|
+
expect(southwest.lng).to eq(-0.3775312802915021)
|
69
92
|
end
|
70
93
|
end
|
71
94
|
|
72
|
-
describe "
|
73
|
-
let(:
|
95
|
+
describe "northeast" do
|
96
|
+
let(:northeast) { viewport.northeast }
|
74
97
|
|
75
|
-
it "
|
76
|
-
expect(
|
98
|
+
it "has latitude" do
|
99
|
+
expect(northeast.lat).to eq(39.4714505802915)
|
77
100
|
end
|
78
|
-
end
|
79
101
|
|
80
|
-
|
81
|
-
|
102
|
+
it "has longitude" do
|
103
|
+
expect(northeast.lng).to eq(-0.374833319708498)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
82
108
|
|
83
|
-
|
84
|
-
|
109
|
+
describe "address" do
|
110
|
+
let(:address) { place.address }
|
85
111
|
|
86
|
-
|
87
|
-
|
88
|
-
|
112
|
+
it "has a street_number" do
|
113
|
+
expect(address.street_number).to eq("S/N")
|
114
|
+
end
|
89
115
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
116
|
+
it "has a street" do
|
117
|
+
expect(address.street).to eq("Plaza Ayuntamiento")
|
118
|
+
end
|
94
119
|
|
95
|
-
|
96
|
-
|
120
|
+
it "has a locality" do
|
121
|
+
expect(address.locality).to eq("Valencia")
|
122
|
+
end
|
97
123
|
|
98
|
-
|
99
|
-
|
100
|
-
|
124
|
+
it "has a area_level_1" do
|
125
|
+
expect(address.area_level_1).to eq("Valencian Community")
|
126
|
+
end
|
101
127
|
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
128
|
+
it "has a area_level_1_code" do
|
129
|
+
expect(address.area_level_1_code).to eq("Valencian Community")
|
107
130
|
end
|
108
131
|
|
109
|
-
|
110
|
-
|
132
|
+
it "has a area_level_2" do
|
133
|
+
expect(address.area_level_2).to eq("Valencia")
|
134
|
+
end
|
111
135
|
|
112
|
-
|
113
|
-
|
114
|
-
|
136
|
+
it "has a area_level_2_code" do
|
137
|
+
expect(address.area_level_2_code).to eq("V")
|
138
|
+
end
|
115
139
|
|
116
|
-
|
117
|
-
|
118
|
-
|
140
|
+
it "has a country" do
|
141
|
+
expect(address.country).to eq("Spain")
|
142
|
+
end
|
119
143
|
|
120
|
-
|
121
|
-
|
122
|
-
|
144
|
+
it "has a country_code" do
|
145
|
+
expect(address.country_code).to eq("ES")
|
146
|
+
end
|
123
147
|
|
124
|
-
|
125
|
-
|
126
|
-
|
148
|
+
it "has a formatted" do
|
149
|
+
expect(address.formatted).to eq("Plaza Ayuntamiento, S/N, 46002 Valencia, Valencia, Spain")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
127
154
|
|
128
|
-
|
129
|
-
|
130
|
-
|
155
|
+
describe 'routes' do
|
156
|
+
let(:routes) do
|
157
|
+
VCR.use_cassette('directions_by_address') do
|
158
|
+
Geogle::Directions.new.routes("Valencia", "Madrid", { region: "es" })
|
159
|
+
end
|
160
|
+
end
|
131
161
|
|
132
|
-
|
133
|
-
|
134
|
-
|
162
|
+
it "returns an array" do
|
163
|
+
expect(routes).to be_kind_of(Array)
|
164
|
+
end
|
135
165
|
|
136
|
-
|
137
|
-
|
138
|
-
|
166
|
+
it "each element is Geogle::Model::Route" do
|
167
|
+
expect(routes.first).to be_kind_of(Geogle::Model::Route)
|
168
|
+
end
|
139
169
|
|
140
|
-
|
141
|
-
|
142
|
-
end
|
170
|
+
describe "route" do
|
171
|
+
let(:route) { routes.first }
|
143
172
|
|
144
|
-
|
145
|
-
|
146
|
-
|
173
|
+
it "summary" do
|
174
|
+
expect(route.summary).to eq("A-3")
|
175
|
+
end
|
147
176
|
|
148
|
-
|
149
|
-
|
150
|
-
end
|
151
|
-
end
|
177
|
+
describe "overview_polyline" do
|
178
|
+
pending
|
152
179
|
end
|
153
|
-
end
|
154
180
|
|
155
|
-
|
156
|
-
|
157
|
-
VCR.use_cassette('directions_by_address') do
|
158
|
-
Geogle::Directions.new.routes("Valencia", "Madrid", { region: "es" })
|
159
|
-
end
|
181
|
+
it "copyrights" do
|
182
|
+
expect(route.copyrights).to eq("Map data ©2014 Google, basado en BCN IGN España")
|
160
183
|
end
|
161
184
|
|
162
|
-
|
163
|
-
|
185
|
+
describe "warnings" do
|
186
|
+
pending
|
164
187
|
end
|
165
188
|
|
166
|
-
it "
|
167
|
-
|
189
|
+
it "waypoint_order" do
|
190
|
+
pending
|
191
|
+
expect(route.waypoint_order).to be_kind_of([])
|
168
192
|
end
|
169
193
|
|
170
|
-
describe "
|
171
|
-
let(:
|
194
|
+
describe "bounds" do
|
195
|
+
let(:bounds) { route.bounds }
|
172
196
|
|
173
|
-
|
174
|
-
|
197
|
+
describe "southwest" do
|
198
|
+
let(:southwest) { bounds.southwest }
|
199
|
+
|
200
|
+
it "has latitude" do
|
201
|
+
expect(southwest.lat).to eq(39.4289607)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "has longitude" do
|
205
|
+
expect(southwest.lng).to eq(-3.7047624)
|
206
|
+
end
|
175
207
|
end
|
176
208
|
|
177
|
-
describe "
|
178
|
-
|
209
|
+
describe "northeast" do
|
210
|
+
let(:northeast) { bounds.northeast }
|
211
|
+
|
212
|
+
it "has latitude" do
|
213
|
+
expect(northeast.lat).to eq(40.4167158)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "has longitude" do
|
217
|
+
expect(northeast.lng).to eq(-0.3759178)
|
218
|
+
end
|
179
219
|
end
|
220
|
+
end
|
180
221
|
|
181
|
-
|
182
|
-
|
222
|
+
describe "legs" do
|
223
|
+
let(:leg) { route.legs.first }
|
224
|
+
|
225
|
+
it "is an array" do
|
226
|
+
expect(route.legs).to be_kind_of(Array)
|
183
227
|
end
|
184
228
|
|
185
|
-
|
186
|
-
|
229
|
+
it "start_address" do
|
230
|
+
expect(leg.start_address).to eq("Valencia, Valencia, Spain")
|
187
231
|
end
|
188
232
|
|
189
|
-
it "
|
190
|
-
|
191
|
-
expect(route.waypoint_order).to be_kind_of([])
|
233
|
+
it "end_address" do
|
234
|
+
expect(leg.end_address).to eq("Madrid, Madrid, Spain")
|
192
235
|
end
|
193
236
|
|
194
|
-
|
195
|
-
|
237
|
+
it "start_location" do
|
238
|
+
expect(leg.start_location.to_s).to eq("39.4699889,-0.3759178")
|
239
|
+
end
|
196
240
|
|
197
|
-
|
198
|
-
|
241
|
+
it "end_location" do
|
242
|
+
expect(leg.end_location.to_s).to eq("40.4167158,-3.7037799")
|
243
|
+
end
|
199
244
|
|
200
|
-
|
201
|
-
|
202
|
-
end
|
245
|
+
describe "distance" do
|
246
|
+
let(:distance) { leg.distance }
|
203
247
|
|
204
|
-
|
205
|
-
|
206
|
-
end
|
248
|
+
it "value" do
|
249
|
+
expect(distance.value).to eq(355040)
|
207
250
|
end
|
208
251
|
|
209
|
-
|
210
|
-
|
252
|
+
it "text" do
|
253
|
+
expect(distance.text).to eq("355 km")
|
254
|
+
end
|
255
|
+
end
|
211
256
|
|
212
|
-
|
213
|
-
|
214
|
-
end
|
257
|
+
describe "duration" do
|
258
|
+
let(:duration) { leg.duration }
|
215
259
|
|
216
|
-
|
217
|
-
|
218
|
-
end
|
260
|
+
it "value" do
|
261
|
+
expect(duration.value).to eq(12745)
|
219
262
|
end
|
263
|
+
|
264
|
+
it "text" do
|
265
|
+
expect(duration.text).to eq("3 hours 32 mins")
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe "arrival_time" do
|
270
|
+
let(:arrival_time) { leg.arrival_time }
|
271
|
+
pending
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "departure_time" do
|
275
|
+
let(:departure_time) { leg.departure_time }
|
276
|
+
pending
|
220
277
|
end
|
221
278
|
|
222
|
-
describe "
|
223
|
-
let(:
|
279
|
+
describe "steps" do
|
280
|
+
let(:step) { leg.steps.first }
|
224
281
|
|
225
282
|
it "is an array" do
|
226
283
|
expect(route.legs).to be_kind_of(Array)
|
227
284
|
end
|
228
285
|
|
229
|
-
it "
|
230
|
-
expect(
|
286
|
+
it "html_instructions" do
|
287
|
+
expect(step.html_instructions).to eq("Head <b>north</b> on <b>Plaça de l'Ajuntament</b>")
|
231
288
|
end
|
232
289
|
|
233
|
-
it "
|
234
|
-
expect(
|
290
|
+
it "travel_mode" do
|
291
|
+
expect(step.travel_mode).to eq("DRIVING")
|
235
292
|
end
|
236
293
|
|
237
294
|
it "start_location" do
|
238
|
-
expect(
|
295
|
+
expect(step.start_location.to_s).to eq("39.4699889,-0.3759178")
|
239
296
|
end
|
240
297
|
|
241
298
|
it "end_location" do
|
242
|
-
expect(
|
299
|
+
expect(step.end_location.to_s).to eq("39.4701816,-0.3759889")
|
243
300
|
end
|
244
301
|
|
245
302
|
describe "distance" do
|
246
|
-
let(:distance) { leg.distance }
|
247
|
-
|
248
303
|
it "value" do
|
249
|
-
expect(distance.value).to eq(
|
304
|
+
expect(step.distance.value).to eq(22)
|
250
305
|
end
|
251
306
|
|
252
307
|
it "text" do
|
253
|
-
expect(distance.text).to eq("
|
308
|
+
expect(step.distance.text).to eq("22 m")
|
254
309
|
end
|
255
310
|
end
|
256
311
|
|
257
312
|
describe "duration" do
|
258
|
-
let(:duration) { leg.duration }
|
259
|
-
|
260
313
|
it "value" do
|
261
|
-
expect(duration.value).to eq(
|
314
|
+
expect(step.duration.value).to eq(2)
|
262
315
|
end
|
263
316
|
|
264
317
|
it "text" do
|
265
|
-
expect(duration.text).to eq("
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
describe "arrival_time" do
|
270
|
-
let(:arrival_time) { leg.arrival_time }
|
271
|
-
pending
|
272
|
-
end
|
273
|
-
|
274
|
-
describe "departure_time" do
|
275
|
-
let(:departure_time) { leg.departure_time }
|
276
|
-
pending
|
277
|
-
end
|
278
|
-
|
279
|
-
describe "steps" do
|
280
|
-
let(:step) { leg.steps.first }
|
281
|
-
|
282
|
-
it "is an array" do
|
283
|
-
expect(route.legs).to be_kind_of(Array)
|
284
|
-
end
|
285
|
-
|
286
|
-
it "html_instructions" do
|
287
|
-
expect(step.html_instructions).to eq("Head <b>north</b> on <b>Plaça de l'Ajuntament</b>")
|
288
|
-
end
|
289
|
-
|
290
|
-
it "travel_mode" do
|
291
|
-
expect(step.travel_mode).to eq("DRIVING")
|
292
|
-
end
|
293
|
-
|
294
|
-
it "start_location" do
|
295
|
-
expect(step.start_location.to_s).to eq("39.4699889,-0.3759178")
|
296
|
-
end
|
297
|
-
|
298
|
-
it "end_location" do
|
299
|
-
expect(step.end_location.to_s).to eq("39.4701816,-0.3759889")
|
300
|
-
end
|
301
|
-
|
302
|
-
describe "distance" do
|
303
|
-
it "value" do
|
304
|
-
expect(step.distance.value).to eq(22)
|
305
|
-
end
|
306
|
-
|
307
|
-
it "text" do
|
308
|
-
expect(step.distance.text).to eq("22 m")
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
describe "duration" do
|
313
|
-
it "value" do
|
314
|
-
expect(step.duration.value).to eq(2)
|
315
|
-
end
|
316
|
-
|
317
|
-
it "text" do
|
318
|
-
expect(step.duration.text).to eq("1 min")
|
319
|
-
end
|
318
|
+
expect(step.duration.text).to eq("1 min")
|
320
319
|
end
|
321
320
|
end
|
322
321
|
end
|
323
322
|
end
|
324
323
|
end
|
325
|
-
end
|
324
|
+
end
|
325
|
+
end
|