barometer 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +78 -70
- data/VERSION.yml +2 -2
- data/bin/barometer +100 -37
- data/lib/barometer.rb +12 -8
- data/lib/barometer/base.rb +48 -20
- data/lib/barometer/data.rb +5 -1
- data/lib/barometer/data/current.rb +23 -15
- data/lib/barometer/data/distance.rb +15 -5
- data/lib/barometer/data/forecast.rb +23 -5
- data/lib/barometer/data/geo.rb +16 -54
- data/lib/barometer/data/local_datetime.rb +137 -0
- data/lib/barometer/data/local_time.rb +134 -0
- data/lib/barometer/data/location.rb +6 -1
- data/lib/barometer/data/measurement.rb +71 -42
- data/lib/barometer/data/night.rb +69 -0
- data/lib/barometer/data/pressure.rb +15 -5
- data/lib/barometer/data/speed.rb +16 -5
- data/lib/barometer/data/sun.rb +8 -20
- data/lib/barometer/data/temperature.rb +22 -9
- data/lib/barometer/data/units.rb +10 -19
- data/lib/barometer/data/zone.rb +135 -9
- data/lib/barometer/formats.rb +12 -0
- data/lib/barometer/formats/coordinates.rb +42 -0
- data/lib/barometer/formats/format.rb +46 -0
- data/lib/barometer/formats/geocode.rb +51 -0
- data/lib/barometer/formats/icao.rb +37 -0
- data/lib/barometer/formats/postalcode.rb +22 -0
- data/lib/barometer/formats/short_zipcode.rb +17 -0
- data/lib/barometer/formats/weather_id.rb +107 -0
- data/lib/barometer/formats/zipcode.rb +31 -0
- data/lib/barometer/query.rb +61 -232
- data/lib/barometer/services.rb +14 -4
- data/lib/barometer/translations/icao_country_codes.yml +9 -0
- data/lib/barometer/translations/weather_country_codes.yml +17 -0
- data/lib/barometer/weather.rb +51 -30
- data/lib/barometer/{services → weather_services}/google.rb +23 -26
- data/lib/barometer/weather_services/noaa.rb +6 -0
- data/lib/barometer/{services → weather_services}/service.rb +101 -92
- data/lib/barometer/weather_services/weather_bug.rb +6 -0
- data/lib/barometer/weather_services/weather_dot_com.rb +261 -0
- data/lib/barometer/{services → weather_services}/wunderground.rb +58 -76
- data/lib/barometer/{services → weather_services}/yahoo.rb +91 -121
- data/lib/barometer/web_services/geocode.rb +33 -0
- data/lib/barometer/web_services/weather_id.rb +37 -0
- data/lib/barometer/web_services/web_service.rb +32 -0
- data/lib/demometer/demometer.rb +31 -4
- data/lib/demometer/views/forecast.erb +20 -0
- data/lib/demometer/views/index.erb +10 -3
- data/lib/demometer/views/measurement.erb +8 -3
- data/lib/demometer/views/readme.erb +63 -24
- data/spec/barometer_spec.rb +18 -36
- data/spec/{data_current_spec.rb → data/current_spec.rb} +73 -49
- data/spec/{data_distance_spec.rb → data/distance_spec.rb} +30 -30
- data/spec/{data_forecast_spec.rb → data/forecast_spec.rb} +57 -15
- data/spec/data/geo_spec.rb +91 -0
- data/spec/data/local_datetime_spec.rb +269 -0
- data/spec/data/local_time_spec.rb +239 -0
- data/spec/{data_location_spec.rb → data/location_spec.rb} +12 -1
- data/spec/{data_measurement_spec.rb → data/measurement_spec.rb} +135 -66
- data/spec/data/night_measurement_spec.rb +136 -0
- data/spec/{data_pressure_spec.rb → data/pressure_spec.rb} +29 -29
- data/spec/{data_speed_spec.rb → data/speed_spec.rb} +30 -30
- data/spec/data/sun_spec.rb +49 -0
- data/spec/{data_temperature_spec.rb → data/temperature_spec.rb} +44 -44
- data/spec/{units_spec.rb → data/units_spec.rb} +6 -6
- data/spec/{data_zone_spec.rb → data/zone_spec.rb} +15 -15
- data/spec/fixtures/formats/weather_id/90210.xml +1 -0
- data/spec/fixtures/formats/weather_id/atlanta.xml +1 -0
- data/spec/fixtures/formats/weather_id/from_USGA0028.xml +1 -0
- data/spec/fixtures/formats/weather_id/new_york.xml +1 -0
- data/spec/fixtures/{geocode_40_73.xml → geocode/40_73.xml} +0 -0
- data/spec/fixtures/{geocode_90210.xml → geocode/90210.xml} +0 -0
- data/spec/fixtures/{geocode_T5B4M9.xml → geocode/T5B4M9.xml} +0 -0
- data/spec/fixtures/geocode/atlanta.xml +1 -0
- data/spec/fixtures/{geocode_calgary_ab.xml → geocode/calgary_ab.xml} +0 -0
- data/spec/fixtures/{geocode_ksfo.xml → geocode/ksfo.xml} +0 -0
- data/spec/fixtures/{geocode_newyork_ny.xml → geocode/newyork_ny.xml} +0 -0
- data/spec/fixtures/{google_calgary_ab.xml → services/google/calgary_ab.xml} +0 -0
- data/spec/fixtures/services/weather_dot_com/90210.xml +1 -0
- data/spec/fixtures/{current_calgary_ab.xml → services/wunderground/current_calgary_ab.xml} +0 -0
- data/spec/fixtures/{forecast_calgary_ab.xml → services/wunderground/forecast_calgary_ab.xml} +0 -0
- data/spec/fixtures/{yahoo_90210.xml → services/yahoo/90210.xml} +0 -0
- data/spec/formats/coordinates_spec.rb +158 -0
- data/spec/formats/format_spec.rb +73 -0
- data/spec/formats/geocode_spec.rb +179 -0
- data/spec/formats/icao_spec.rb +61 -0
- data/spec/formats/postalcode_spec.rb +59 -0
- data/spec/formats/short_zipcode_spec.rb +53 -0
- data/spec/formats/weather_id_spec.rb +191 -0
- data/spec/formats/zipcode_spec.rb +111 -0
- data/spec/query_spec.rb +261 -288
- data/spec/spec_helper.rb +128 -4
- data/spec/{service_google_spec.rb → weather_services/google_spec.rb} +46 -46
- data/spec/weather_services/services_spec.rb +1118 -0
- data/spec/weather_services/weather_dot_com_spec.rb +327 -0
- data/spec/weather_services/wunderground_spec.rb +332 -0
- data/spec/{service_yahoo_spec.rb → weather_services/yahoo_spec.rb} +65 -81
- data/spec/weather_spec.rb +73 -61
- data/spec/web_services/geocode_spec.rb +45 -0
- data/spec/web_services/web_services_spec.rb +26 -0
- metadata +88 -36
- data/lib/barometer/services/noaa.rb +0 -6
- data/lib/barometer/services/weather_bug.rb +0 -6
- data/lib/barometer/services/weather_dot_com.rb +0 -6
- data/spec/data_geo_spec.rb +0 -94
- data/spec/data_sun_spec.rb +0 -76
- data/spec/service_wunderground_spec.rb +0 -330
- data/spec/services_spec.rb +0 -1106
data/spec/query_spec.rb
CHANGED
@@ -3,7 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe "Query" do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@
|
6
|
+
@short_zipcode = "90210"
|
7
|
+
@zipcode = @short_zipcode
|
8
|
+
@long_zipcode = "90210-5555"
|
9
|
+
@weather_id = "USGA0028"
|
7
10
|
@postal_code = "T5B 4M9"
|
8
11
|
@coordinates = "40.756054,-73.986951"
|
9
12
|
@geocode = "New York, NY"
|
@@ -12,47 +15,19 @@ describe "Query" do
|
|
12
15
|
# actual conversions
|
13
16
|
@zipcode_to_coordinates = "34.1030032,-118.4104684"
|
14
17
|
@zipcode_to_geocode = "Beverly Hills, CA, USA"
|
18
|
+
@zipcode_to_weather_id = "USCA0090"
|
15
19
|
@postalcode_to_coordinates = "53.570447,-113.456083"
|
16
20
|
@geocode_to_coordinates = "40.756054,-73.986951"
|
21
|
+
@geocode_to_weather_id = "USNY0996"
|
17
22
|
@coordinates_to_geocode = "New York, NY, USA"
|
23
|
+
@coordinates_to_weather_id = "USNY0996"
|
24
|
+
@icao_to_coordinates = "37.615223,-122.389979"
|
25
|
+
@icao_to_geocode = "San Francisco Airport, USA"
|
18
26
|
|
19
27
|
Barometer.google_geocode_key = nil
|
20
|
-
Barometer::Query.google_geocode_key = nil
|
21
28
|
#Barometer.skip_graticule = true
|
22
29
|
end
|
23
30
|
|
24
|
-
describe "the class methods" do
|
25
|
-
|
26
|
-
it "detects a zipcode" do
|
27
|
-
Barometer::Query.is_us_zipcode?(@zipcode).should be_true
|
28
|
-
Barometer::Query.is_us_zipcode?(@postal_code).should be_false
|
29
|
-
Barometer::Query.is_us_zipcode?(@coordinates).should be_false
|
30
|
-
Barometer::Query.is_coordinates?(@icao).should be_false
|
31
|
-
end
|
32
|
-
|
33
|
-
it "detects a postalcode" do
|
34
|
-
Barometer::Query.is_canadian_postcode?(@postal_code).should be_true
|
35
|
-
Barometer::Query.is_canadian_postcode?(@zipcode).should be_false
|
36
|
-
Barometer::Query.is_canadian_postcode?(@coordinates).should be_false
|
37
|
-
Barometer::Query.is_coordinates?(@icao).should be_false
|
38
|
-
end
|
39
|
-
|
40
|
-
it "detects a coordinates" do
|
41
|
-
Barometer::Query.is_coordinates?(@coordinates).should be_true
|
42
|
-
Barometer::Query.is_coordinates?(@zipcode).should be_false
|
43
|
-
Barometer::Query.is_coordinates?(@postal_code).should be_false
|
44
|
-
Barometer::Query.is_coordinates?(@icao).should be_false
|
45
|
-
end
|
46
|
-
|
47
|
-
it "detects an ICAO" do
|
48
|
-
Barometer::Query.is_icao?(@coordinates).should be_false
|
49
|
-
Barometer::Query.is_icao?(@zipcode).should be_false
|
50
|
-
Barometer::Query.is_icao?(@postal_code).should be_false
|
51
|
-
Barometer::Query.is_icao?(@icao).should be_true
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
31
|
describe "determines the query format" do
|
57
32
|
|
58
33
|
before(:each) do
|
@@ -60,18 +35,20 @@ describe "Query" do
|
|
60
35
|
@query.country_code.should be_nil
|
61
36
|
end
|
62
37
|
|
38
|
+
it "recognizes a short zip code" do
|
39
|
+
@query.q = @short_zipcode
|
40
|
+
@query.format.should be_nil
|
41
|
+
@query.analyze!
|
42
|
+
@query.format.to_sym.should == :short_zipcode
|
43
|
+
@query.country_code.should == "US"
|
44
|
+
end
|
45
|
+
|
63
46
|
it "recognizes a zip code" do
|
64
|
-
@query.q = @
|
47
|
+
@query.q = @long_zipcode
|
65
48
|
@query.format.should be_nil
|
66
49
|
@query.analyze!
|
67
50
|
@query.format.to_sym.should == :zipcode
|
68
|
-
|
69
51
|
@query.country_code.should == "US"
|
70
|
-
@query.zipcode?.should be_true
|
71
|
-
@query.postalcode?.should be_false
|
72
|
-
@query.icao?.should be_false
|
73
|
-
@query.coordinates?.should be_false
|
74
|
-
@query.geocode?.should be_false
|
75
52
|
end
|
76
53
|
|
77
54
|
it "recognizes a postal code" do
|
@@ -79,13 +56,7 @@ describe "Query" do
|
|
79
56
|
@query.format.should be_nil
|
80
57
|
@query.analyze!
|
81
58
|
@query.format.to_sym.should == :postalcode
|
82
|
-
|
83
59
|
@query.country_code.should == "CA"
|
84
|
-
@query.zipcode?.should be_false
|
85
|
-
@query.postalcode?.should be_true
|
86
|
-
@query.icao?.should be_false
|
87
|
-
@query.coordinates?.should be_false
|
88
|
-
@query.geocode?.should be_false
|
89
60
|
end
|
90
61
|
|
91
62
|
it "recognizes icao" do
|
@@ -93,13 +64,15 @@ describe "Query" do
|
|
93
64
|
@query.format.should be_nil
|
94
65
|
@query.analyze!
|
95
66
|
@query.format.to_sym.should == :icao
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
@query.
|
101
|
-
@query.
|
102
|
-
@query.
|
67
|
+
@query.country_code.should == "US"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "recognizes weather_id" do
|
71
|
+
@query.q = @weather_id
|
72
|
+
@query.format.should be_nil
|
73
|
+
@query.analyze!
|
74
|
+
@query.format.to_sym.should == :weather_id
|
75
|
+
@query.country_code.should == "US"
|
103
76
|
end
|
104
77
|
|
105
78
|
it "recognizes latitude/longitude" do
|
@@ -107,13 +80,7 @@ describe "Query" do
|
|
107
80
|
@query.format.should be_nil
|
108
81
|
@query.analyze!
|
109
82
|
@query.format.to_sym.should == :coordinates
|
110
|
-
|
111
83
|
@query.country_code.should be_nil
|
112
|
-
@query.zipcode?.should be_false
|
113
|
-
@query.postalcode?.should be_false
|
114
|
-
@query.icao?.should be_false
|
115
|
-
@query.coordinates?.should be_true
|
116
|
-
@query.geocode?.should be_false
|
117
84
|
end
|
118
85
|
|
119
86
|
it "defaults to a general geo_location" do
|
@@ -121,13 +88,7 @@ describe "Query" do
|
|
121
88
|
@query.format.should be_nil
|
122
89
|
@query.analyze!
|
123
90
|
@query.format.to_sym.should == :geocode
|
124
|
-
|
125
91
|
@query.country_code.should be_nil
|
126
|
-
@query.zipcode?.should be_false
|
127
|
-
@query.postalcode?.should be_false
|
128
|
-
@query.icao?.should be_false
|
129
|
-
@query.coordinates?.should be_false
|
130
|
-
@query.geocode?.should be_true
|
131
92
|
end
|
132
93
|
|
133
94
|
end
|
@@ -142,10 +103,6 @@ describe "Query" do
|
|
142
103
|
@query.q.should be_nil
|
143
104
|
end
|
144
105
|
|
145
|
-
# it "responds to geo" do
|
146
|
-
# @query.geo.should be_nil
|
147
|
-
# end
|
148
|
-
|
149
106
|
it "responds to format" do
|
150
107
|
@query.format.should be_nil
|
151
108
|
end
|
@@ -165,24 +122,13 @@ describe "Query" do
|
|
165
122
|
end
|
166
123
|
|
167
124
|
it "responds to google_api_key" do
|
168
|
-
Barometer
|
169
|
-
end
|
170
|
-
|
171
|
-
it "sets the google_api_key" do
|
172
|
-
key = "KEY"
|
173
|
-
Barometer::Query.google_geocode_key = key
|
174
|
-
Barometer::Query.google_geocode_key.should == key
|
125
|
+
Barometer.google_geocode_key.should be_nil
|
175
126
|
end
|
176
127
|
|
177
128
|
it "defaults to the Module geocode key" do
|
178
129
|
key = "KEY"
|
179
|
-
Barometer::Query.google_geocode_key.should be_nil
|
180
130
|
Barometer.google_geocode_key = key
|
181
|
-
Barometer
|
182
|
-
end
|
183
|
-
|
184
|
-
it "responds to preferred" do
|
185
|
-
@query.preferred.should be_nil
|
131
|
+
Barometer.google_geocode_key.should == key
|
186
132
|
end
|
187
133
|
|
188
134
|
it "responds to geo" do
|
@@ -191,168 +137,6 @@ describe "Query" do
|
|
191
137
|
|
192
138
|
end
|
193
139
|
|
194
|
-
use_graticule = true
|
195
|
-
|
196
|
-
if use_graticule
|
197
|
-
describe "when converting queries" do
|
198
|
-
|
199
|
-
before(:each) do
|
200
|
-
@key = KEY
|
201
|
-
url_start = "http://maps.google.com/maps/geo?"
|
202
|
-
#
|
203
|
-
# for Graticule and/or HTTParty geocoding
|
204
|
-
#
|
205
|
-
FakeWeb.register_uri(:get,
|
206
|
-
"#{url_start}gl=US&key=#{@key}&output=xml&q=90210",
|
207
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
208
|
-
'fixtures',
|
209
|
-
'geocode_90210.xml')
|
210
|
-
)
|
211
|
-
)
|
212
|
-
FakeWeb.register_uri(:get,
|
213
|
-
"#{url_start}gl=CA&key=#{@key}&output=xml&q=T5B%204M9",
|
214
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
215
|
-
'fixtures',
|
216
|
-
'geocode_T5B4M9.xml')
|
217
|
-
)
|
218
|
-
)
|
219
|
-
#
|
220
|
-
# for Graticule geocoding
|
221
|
-
#
|
222
|
-
FakeWeb.register_uri(:get,
|
223
|
-
"#{url_start}gl=&key=#{@key}&output=xml&q=New%20York,%20NY",
|
224
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
225
|
-
'fixtures',
|
226
|
-
'geocode_newyork_ny.xml')
|
227
|
-
)
|
228
|
-
)
|
229
|
-
FakeWeb.register_uri(:get,
|
230
|
-
"#{url_start}gl=&key=#{@key}&output=xml&q=40.756054,-73.986951",
|
231
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
232
|
-
'fixtures',
|
233
|
-
'geocode_40_73.xml')
|
234
|
-
)
|
235
|
-
)
|
236
|
-
#
|
237
|
-
# for HTTParty geocoding
|
238
|
-
#
|
239
|
-
FakeWeb.register_uri(:get,
|
240
|
-
"#{url_start}output=xml&q=New%20York%2C%20NY&gl=&key=#{@key}",
|
241
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
242
|
-
'fixtures',
|
243
|
-
'geocode_newyork_ny.xml')
|
244
|
-
)
|
245
|
-
)
|
246
|
-
FakeWeb.register_uri(:get,
|
247
|
-
"#{url_start}gl=&output=xml&q=#{CGI.escape("40.756054,-73.986951")}&key=#{@key}",
|
248
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
249
|
-
'fixtures',
|
250
|
-
'geocode_40_73.xml')
|
251
|
-
)
|
252
|
-
)
|
253
|
-
FakeWeb.register_uri(:get,
|
254
|
-
"#{url_start}output=xml&q=KSFO&gl=&key=#{@key}",
|
255
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
256
|
-
'fixtures',
|
257
|
-
'geocode_ksfo.xml')
|
258
|
-
)
|
259
|
-
)
|
260
|
-
end
|
261
|
-
|
262
|
-
describe "to coordinates," do
|
263
|
-
|
264
|
-
before(:each) do
|
265
|
-
Barometer::Query.google_geocode_key = @key
|
266
|
-
end
|
267
|
-
|
268
|
-
it "skips conversion unless Graticule enabled or no API key" do
|
269
|
-
Barometer::Query.google_geocode_key = nil
|
270
|
-
Barometer::Query.google_geocode_key.should be_nil
|
271
|
-
Barometer.google_geocode_key = nil
|
272
|
-
Barometer.google_geocode_key.should be_nil
|
273
|
-
Barometer::Query.to_coordinates(@geocode, :geocode).should be_nil
|
274
|
-
end
|
275
|
-
|
276
|
-
it "attempts conversion if Graticule enabled and has API key" do
|
277
|
-
Barometer::Query.to_coordinates(@geocode, :geocode).should_not be_nil
|
278
|
-
end
|
279
|
-
|
280
|
-
it "converts from geocode" do
|
281
|
-
Barometer::Query.to_coordinates(@geocode, :geocode).first.should == "40.756054,-73.986951"
|
282
|
-
end
|
283
|
-
|
284
|
-
it "converts from zipcode" do
|
285
|
-
Barometer::Query.to_coordinates(@zipcode, :zipcode).first.should == "34.1030032,-118.4104684"
|
286
|
-
end
|
287
|
-
|
288
|
-
it "converts from postalcode" do
|
289
|
-
Barometer::Query.to_coordinates(@postal_code, :postalcode).first.should == "53.570447,-113.456083"
|
290
|
-
end
|
291
|
-
|
292
|
-
it "converts from icao" do
|
293
|
-
Barometer::Query.to_coordinates(@icao, :icao).first.should == "37.615223,-122.389979"
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|
297
|
-
|
298
|
-
describe "to geocode" do
|
299
|
-
|
300
|
-
before(:each) do
|
301
|
-
Barometer::Query.google_geocode_key = @key
|
302
|
-
end
|
303
|
-
|
304
|
-
describe "when Graticule enabled," do
|
305
|
-
|
306
|
-
it "converts from coordinates" do
|
307
|
-
Barometer::Query.to_geocode(@coordinates, :coordinates).first.should == "New York, NY, USA"
|
308
|
-
end
|
309
|
-
|
310
|
-
it "converts from zipcode" do
|
311
|
-
Barometer::Query.to_geocode(@zipcode, :zipcode).first.should == "Beverly Hills, CA, USA"
|
312
|
-
end
|
313
|
-
|
314
|
-
it "converts from postalcode" do
|
315
|
-
Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
|
316
|
-
end
|
317
|
-
|
318
|
-
it "converts from icao" do
|
319
|
-
Barometer::Query.to_geocode(@icao, :icao).first.should == "San Francisco Airport, USA"
|
320
|
-
end
|
321
|
-
|
322
|
-
end
|
323
|
-
|
324
|
-
describe "when Graticule disabled," do
|
325
|
-
|
326
|
-
it "uses coordinates" do
|
327
|
-
Barometer::Query.google_geocode_key = nil
|
328
|
-
Barometer::Query.google_geocode_key.should be_nil
|
329
|
-
Barometer.google_geocode_key = nil
|
330
|
-
Barometer.google_geocode_key.should be_nil
|
331
|
-
Barometer::Query.to_geocode(@coordinates, :coordinates).first.should == @coordinates
|
332
|
-
end
|
333
|
-
|
334
|
-
it "uses zipcode" do
|
335
|
-
Barometer::Query.google_geocode_key = nil
|
336
|
-
Barometer::Query.google_geocode_key.should be_nil
|
337
|
-
Barometer.google_geocode_key = nil
|
338
|
-
Barometer.google_geocode_key.should be_nil
|
339
|
-
Barometer::Query.to_geocode(@zipcode, :zipcode).first.should == @zipcode
|
340
|
-
end
|
341
|
-
|
342
|
-
it "uses postalcode" do
|
343
|
-
Barometer::Query.google_geocode_key = nil
|
344
|
-
Barometer::Query.google_geocode_key.should be_nil
|
345
|
-
Barometer.google_geocode_key = nil
|
346
|
-
Barometer.google_geocode_key.should be_nil
|
347
|
-
Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
|
348
|
-
end
|
349
|
-
|
350
|
-
end
|
351
|
-
|
352
|
-
end
|
353
|
-
|
354
|
-
end
|
355
|
-
|
356
140
|
describe "when returning the query to a Weather API" do
|
357
141
|
|
358
142
|
it "raises an error if there are NO acceptable formats" do
|
@@ -364,62 +148,146 @@ describe "Query" do
|
|
364
148
|
lambda { query.convert!(acceptable_formats) }.should raise_error
|
365
149
|
end
|
366
150
|
|
367
|
-
describe "and the query is already
|
151
|
+
describe "and the query is already the preferred format" do
|
368
152
|
|
369
|
-
|
370
|
-
|
371
|
-
|
153
|
+
it "returns the short_zipcode untouched" do
|
154
|
+
preferred = [:short_zipcode]
|
155
|
+
query = Barometer::Query.new(@short_zipcode)
|
156
|
+
query.convert!(preferred).q.should == @short_zipcode
|
157
|
+
query.country_code.should == "US"
|
372
158
|
end
|
373
159
|
|
374
|
-
it "returns the
|
375
|
-
|
376
|
-
query.
|
160
|
+
it "returns the long_zipcode untouched" do
|
161
|
+
preferred = [:zipcode]
|
162
|
+
query = Barometer::Query.new(@long_zipcode)
|
163
|
+
query.convert!(preferred).q.should == @long_zipcode
|
377
164
|
query.country_code.should == "US"
|
378
165
|
end
|
379
166
|
|
380
167
|
it "returns the postalcode untouched" do
|
168
|
+
preferred = [:postalcode]
|
381
169
|
query = Barometer::Query.new(@postal_code)
|
382
|
-
query.convert!(
|
170
|
+
query.convert!(preferred).q.should == @postal_code
|
383
171
|
query.country_code.should == "CA"
|
384
172
|
end
|
385
173
|
|
174
|
+
it "returns the icao untouched" do
|
175
|
+
preferred = [:icao]
|
176
|
+
query = Barometer::Query.new(@icao)
|
177
|
+
query.convert!(preferred).q.should == @icao
|
178
|
+
end
|
179
|
+
|
386
180
|
it "returns the coordinates untouched" do
|
181
|
+
preferred = [:coordinates]
|
387
182
|
query = Barometer::Query.new(@coordinates)
|
388
|
-
query.convert!(
|
183
|
+
query.convert!(preferred).q.should == @coordinates
|
389
184
|
end
|
390
185
|
|
391
186
|
it "returns the geocode untouched" do
|
187
|
+
preferred = [:geocode]
|
392
188
|
query = Barometer::Query.new(@geocode)
|
393
|
-
query.convert!(
|
189
|
+
query.convert!(preferred).q.should == @geocode
|
394
190
|
end
|
395
191
|
|
396
192
|
end
|
397
193
|
|
398
194
|
describe "and the query needs converting" do
|
399
195
|
|
196
|
+
describe "with an intial format of :short_zipcode," do
|
197
|
+
|
198
|
+
before(:each) do
|
199
|
+
@query = Barometer::Query.new(@short_zipcode)
|
200
|
+
Barometer.google_geocode_key = KEY
|
201
|
+
end
|
202
|
+
|
203
|
+
it "converts to zipcode" do
|
204
|
+
acceptable_formats = [:zipcode]
|
205
|
+
query = @query.convert!(acceptable_formats)
|
206
|
+
query.q.should == @zipcode
|
207
|
+
query.country_code.should == "US"
|
208
|
+
end
|
209
|
+
|
210
|
+
it "converts to coordinates" do
|
211
|
+
acceptable_formats = [:coordinates]
|
212
|
+
query = @query.convert!(acceptable_formats)
|
213
|
+
query.q.should == @zipcode_to_coordinates
|
214
|
+
query.country_code.should == "US"
|
215
|
+
end
|
216
|
+
|
217
|
+
it "converts to geocode" do
|
218
|
+
acceptable_formats = [:geocode]
|
219
|
+
query = @query.convert!(acceptable_formats)
|
220
|
+
query.q.should == @zipcode_to_geocode
|
221
|
+
query.country_code.should == "US"
|
222
|
+
end
|
223
|
+
|
224
|
+
it "converts to weather_id" do
|
225
|
+
acceptable_formats = [:weather_id]
|
226
|
+
query = @query.convert!(acceptable_formats)
|
227
|
+
query.q.should == @zipcode_to_weather_id
|
228
|
+
query.country_code.should == "US"
|
229
|
+
end
|
230
|
+
|
231
|
+
it "skips converting to icao" do
|
232
|
+
acceptable_formats = [:icao]
|
233
|
+
query = @query.convert!(acceptable_formats)
|
234
|
+
query.should be_nil
|
235
|
+
end
|
236
|
+
|
237
|
+
it "skips converting to postalcode" do
|
238
|
+
acceptable_formats = [:postalcode]
|
239
|
+
query = @query.convert!(acceptable_formats)
|
240
|
+
query.should be_nil
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
400
245
|
describe "with an intial format of :zipcode," do
|
401
246
|
|
402
247
|
before(:each) do
|
403
248
|
@query = Barometer::Query.new(@zipcode)
|
404
|
-
Barometer
|
249
|
+
Barometer.google_geocode_key = KEY
|
250
|
+
Barometer.force_geocode = false
|
405
251
|
end
|
406
252
|
|
407
253
|
it "converts to coordinates" do
|
408
254
|
acceptable_formats = [:coordinates]
|
409
|
-
@query.convert!(acceptable_formats)
|
410
|
-
|
255
|
+
query = @query.convert!(acceptable_formats)
|
256
|
+
query.q.should == @zipcode_to_coordinates
|
257
|
+
query.country_code.should == "US"
|
411
258
|
end
|
412
259
|
|
413
260
|
it "converts to geocode" do
|
414
261
|
acceptable_formats = [:geocode]
|
415
|
-
@query.convert!(acceptable_formats)
|
416
|
-
|
262
|
+
query = @query.convert!(acceptable_formats)
|
263
|
+
query.q.should == @zipcode_to_geocode
|
264
|
+
query.country_code.should == "US"
|
265
|
+
end
|
266
|
+
|
267
|
+
it "skips converting to icao" do
|
268
|
+
acceptable_formats = [:icao]
|
269
|
+
query = @query.convert!(acceptable_formats)
|
270
|
+
query.should be_nil
|
417
271
|
end
|
418
272
|
|
419
273
|
it "skips converting to postalcode" do
|
420
274
|
acceptable_formats = [:postalcode]
|
421
|
-
@query.convert!(acceptable_formats)
|
422
|
-
|
275
|
+
query = @query.convert!(acceptable_formats)
|
276
|
+
query.should be_nil
|
277
|
+
end
|
278
|
+
|
279
|
+
it "skips converting to short_zipcode" do
|
280
|
+
@query = Barometer::Query.new(@long_zipcode)
|
281
|
+
acceptable_formats = [:short_zipcode]
|
282
|
+
query = @query.convert!(acceptable_formats)
|
283
|
+
query.should be_nil
|
284
|
+
end
|
285
|
+
|
286
|
+
it "converts to weather_id" do
|
287
|
+
acceptable_formats = [:weather_id]
|
288
|
+
query = @query.convert!(acceptable_formats)
|
289
|
+
query.q.should == @zipcode_to_weather_id
|
290
|
+
query.country_code.should == "US"
|
423
291
|
end
|
424
292
|
|
425
293
|
end
|
@@ -428,52 +296,138 @@ describe "Query" do
|
|
428
296
|
|
429
297
|
before(:each) do
|
430
298
|
@query = Barometer::Query.new(@postal_code)
|
431
|
-
Barometer
|
299
|
+
Barometer.google_geocode_key = KEY
|
432
300
|
end
|
433
301
|
|
434
302
|
it "converts to coordinates" do
|
435
303
|
acceptable_formats = [:coordinates]
|
436
|
-
@query.convert!(acceptable_formats)
|
437
|
-
|
304
|
+
query = @query.convert!(acceptable_formats)
|
305
|
+
query.q.should == @postalcode_to_coordinates
|
306
|
+
query.country_code.should == "CA"
|
438
307
|
end
|
439
308
|
|
440
309
|
it "skips converting to geocode" do
|
441
310
|
acceptable_formats = [:geocode]
|
442
|
-
@query.convert!(acceptable_formats)
|
443
|
-
|
311
|
+
query = @query.convert!(acceptable_formats)
|
312
|
+
query.should be_nil
|
313
|
+
end
|
314
|
+
|
315
|
+
it "skips converting to icao" do
|
316
|
+
acceptable_formats = [:icao]
|
317
|
+
query = @query.convert!(acceptable_formats)
|
318
|
+
query.should be_nil
|
319
|
+
end
|
320
|
+
|
321
|
+
it "skips converting to short_zipcode" do
|
322
|
+
acceptable_formats = [:short_zipcode]
|
323
|
+
query = @query.convert!(acceptable_formats)
|
324
|
+
query.should be_nil
|
325
|
+
end
|
326
|
+
|
327
|
+
it "skips converting to weather_id" do
|
328
|
+
acceptable_formats = [:weather_id]
|
329
|
+
query = @query.convert!(acceptable_formats)
|
330
|
+
query.should be_nil
|
444
331
|
end
|
445
332
|
|
446
333
|
it "skips converting to zipcode" do
|
447
334
|
acceptable_formats = [:zipcode]
|
448
|
-
@query.convert!(acceptable_formats)
|
449
|
-
|
335
|
+
query = @query.convert!(acceptable_formats)
|
336
|
+
query.should be_nil
|
450
337
|
end
|
451
338
|
|
452
339
|
end
|
453
340
|
|
454
|
-
describe "with an intial format of :
|
341
|
+
describe "with an intial format of :icao," do
|
455
342
|
|
456
343
|
before(:each) do
|
457
|
-
@query = Barometer::Query.new(@
|
458
|
-
Barometer
|
344
|
+
@query = Barometer::Query.new(@icao)
|
345
|
+
Barometer.google_geocode_key = KEY
|
459
346
|
end
|
460
347
|
|
461
348
|
it "converts to coordinates" do
|
462
349
|
acceptable_formats = [:coordinates]
|
463
|
-
@query.convert!(acceptable_formats)
|
464
|
-
|
350
|
+
query = @query.convert!(acceptable_formats)
|
351
|
+
query.q.should == @icao_to_coordinates
|
352
|
+
query.country_code.should == "US"
|
353
|
+
end
|
354
|
+
|
355
|
+
it "converts to geocode" do
|
356
|
+
acceptable_formats = [:geocode]
|
357
|
+
query = @query.convert!(acceptable_formats)
|
358
|
+
query.q.should == @icao_to_geocode
|
359
|
+
query.country_code.should == "US"
|
360
|
+
end
|
361
|
+
|
362
|
+
it "skips converting to postalcode" do
|
363
|
+
acceptable_formats = [:postalcode]
|
364
|
+
query = @query.convert!(acceptable_formats)
|
365
|
+
query.should be_nil
|
366
|
+
end
|
367
|
+
|
368
|
+
it "skips converting to short_zipcode" do
|
369
|
+
acceptable_formats = [:short_zipcode]
|
370
|
+
query = @query.convert!(acceptable_formats)
|
371
|
+
query.should be_nil
|
372
|
+
end
|
373
|
+
|
374
|
+
it "skips converting to weather_id" do
|
375
|
+
acceptable_formats = [:weather_id]
|
376
|
+
query = @query.convert!(acceptable_formats)
|
377
|
+
query.should be_nil
|
465
378
|
end
|
466
379
|
|
467
380
|
it "skips converting to zipcode" do
|
468
381
|
acceptable_formats = [:zipcode]
|
469
|
-
@query.convert!(acceptable_formats)
|
470
|
-
|
382
|
+
query = @query.convert!(acceptable_formats)
|
383
|
+
query.should be_nil
|
384
|
+
end
|
385
|
+
|
386
|
+
end
|
387
|
+
|
388
|
+
describe "with an intial format of :geocode," do
|
389
|
+
|
390
|
+
before(:each) do
|
391
|
+
@query = Barometer::Query.new(@geocode)
|
392
|
+
Barometer.google_geocode_key = KEY
|
393
|
+
end
|
394
|
+
|
395
|
+
it "converts to coordinates" do
|
396
|
+
acceptable_formats = [:coordinates]
|
397
|
+
query = @query.convert!(acceptable_formats)
|
398
|
+
query.q.should == @geocode_to_coordinates
|
399
|
+
query.country_code.should == "US"
|
400
|
+
end
|
401
|
+
|
402
|
+
it "skips converting to icao" do
|
403
|
+
acceptable_formats = [:icao]
|
404
|
+
query = @query.convert!(acceptable_formats)
|
405
|
+
query.should be_nil
|
471
406
|
end
|
472
407
|
|
473
408
|
it "skips converting to postalcode" do
|
474
409
|
acceptable_formats = [:postalcode]
|
475
|
-
@query.convert!(acceptable_formats)
|
476
|
-
|
410
|
+
query = @query.convert!(acceptable_formats)
|
411
|
+
query.should be_nil
|
412
|
+
end
|
413
|
+
|
414
|
+
it "skips converting to short_zipcode" do
|
415
|
+
acceptable_formats = [:short_zipcode]
|
416
|
+
query = @query.convert!(acceptable_formats)
|
417
|
+
query.should be_nil
|
418
|
+
end
|
419
|
+
|
420
|
+
it "converts to weather_id" do
|
421
|
+
acceptable_formats = [:weather_id]
|
422
|
+
query = @query.convert!(acceptable_formats)
|
423
|
+
query.q.should == @geocode_to_weather_id
|
424
|
+
query.country_code.should == "US"
|
425
|
+
end
|
426
|
+
|
427
|
+
it "skips converting to zipcode" do
|
428
|
+
acceptable_formats = [:zipcode]
|
429
|
+
query = @query.convert!(acceptable_formats)
|
430
|
+
query.should be_nil
|
477
431
|
end
|
478
432
|
|
479
433
|
end
|
@@ -482,25 +436,45 @@ describe "Query" do
|
|
482
436
|
|
483
437
|
before(:each) do
|
484
438
|
@query = Barometer::Query.new(@coordinates)
|
485
|
-
Barometer
|
439
|
+
Barometer.google_geocode_key = KEY
|
486
440
|
end
|
487
441
|
|
488
442
|
it "converts to geocode" do
|
489
443
|
acceptable_formats = [:geocode]
|
490
|
-
@query.convert!(acceptable_formats)
|
491
|
-
|
444
|
+
query = @query.convert!(acceptable_formats)
|
445
|
+
query.q.should == @coordinates_to_geocode
|
446
|
+
query.country_code.should == "US"
|
492
447
|
end
|
493
448
|
|
494
|
-
it "skips converting to
|
495
|
-
acceptable_formats = [:
|
496
|
-
@query.convert!(acceptable_formats)
|
497
|
-
|
449
|
+
it "skips converting to icao" do
|
450
|
+
acceptable_formats = [:icao]
|
451
|
+
query = @query.convert!(acceptable_formats)
|
452
|
+
query.should be_nil
|
498
453
|
end
|
499
454
|
|
500
455
|
it "skips converting to postalcode" do
|
501
456
|
acceptable_formats = [:postalcode]
|
502
|
-
@query.convert!(acceptable_formats)
|
503
|
-
|
457
|
+
query = @query.convert!(acceptable_formats)
|
458
|
+
query.should be_nil
|
459
|
+
end
|
460
|
+
|
461
|
+
it "skips converting to short_zipcode" do
|
462
|
+
acceptable_formats = [:short_zipcode]
|
463
|
+
query = @query.convert!(acceptable_formats)
|
464
|
+
query.should be_nil
|
465
|
+
end
|
466
|
+
|
467
|
+
it "converts to weather_id" do
|
468
|
+
acceptable_formats = [:weather_id]
|
469
|
+
query = @query.convert!(acceptable_formats)
|
470
|
+
query.q.should == @coordinates_to_weather_id
|
471
|
+
query.country_code.should == "US"
|
472
|
+
end
|
473
|
+
|
474
|
+
it "skips converting to zipcode" do
|
475
|
+
acceptable_formats = [:zipcode]
|
476
|
+
query = @query.convert!(acceptable_formats)
|
477
|
+
query.should be_nil
|
504
478
|
end
|
505
479
|
|
506
480
|
end
|
@@ -508,6 +482,5 @@ describe "Query" do
|
|
508
482
|
end
|
509
483
|
|
510
484
|
end
|
511
|
-
end
|
512
485
|
|
513
486
|
end
|