barometer 0.7.3 → 0.8.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/.gitignore +1 -0
- data/.travis.yml +7 -0
- data/LICENSE +1 -1
- data/{README.rdoc → README.md} +124 -110
- data/Rakefile +1 -21
- data/TODO +8 -9
- data/barometer.gemspec +20 -19
- data/bin/barometer +36 -83
- data/lib/barometer.rb +13 -11
- data/lib/barometer/base.rb +10 -10
- data/lib/barometer/data.rb +1 -1
- data/lib/barometer/data/distance.rb +25 -25
- data/lib/barometer/data/geo.rb +9 -9
- data/lib/barometer/data/local_datetime.rb +24 -20
- data/lib/barometer/data/local_time.rb +13 -13
- data/lib/barometer/data/location.rb +6 -6
- data/lib/barometer/data/pressure.rb +24 -24
- data/lib/barometer/data/speed.rb +28 -28
- data/lib/barometer/data/sun.rb +7 -7
- data/lib/barometer/data/temperature.rb +29 -29
- data/lib/barometer/data/units.rb +9 -9
- data/lib/barometer/data/zone.rb +19 -19
- data/lib/barometer/formats.rb +1 -1
- data/lib/barometer/formats/coordinates.rb +7 -7
- data/lib/barometer/formats/format.rb +6 -6
- data/lib/barometer/formats/geocode.rb +5 -5
- data/lib/barometer/formats/icao.rb +6 -6
- data/lib/barometer/formats/postalcode.rb +3 -3
- data/lib/barometer/formats/short_zipcode.rb +2 -2
- data/lib/barometer/formats/weather_id.rb +10 -10
- data/lib/barometer/formats/woe_id.rb +20 -20
- data/lib/barometer/formats/zipcode.rb +3 -3
- data/lib/barometer/key_file_parser.rb +20 -0
- data/lib/barometer/measurements/measurement.rb +32 -32
- data/lib/barometer/measurements/result.rb +39 -39
- data/lib/barometer/measurements/result_array.rb +12 -12
- data/lib/barometer/query.rb +15 -15
- data/lib/barometer/services.rb +3 -3
- data/lib/barometer/translations/icao_country_codes.yml +20 -20
- data/lib/barometer/translations/weather_country_codes.yml +1 -1
- data/lib/barometer/translations/zone_codes.yml +2 -2
- data/lib/barometer/version.rb +3 -0
- data/lib/barometer/weather.rb +27 -27
- data/lib/barometer/weather_services/noaa.rb +314 -3
- data/lib/barometer/weather_services/service.rb +32 -30
- data/lib/barometer/weather_services/weather_bug.rb +35 -33
- data/lib/barometer/weather_services/wunderground.rb +31 -29
- data/lib/barometer/weather_services/yahoo.rb +36 -35
- data/lib/barometer/web_services/geocode.rb +5 -7
- data/lib/barometer/web_services/noaa_station_id.rb +53 -0
- data/lib/barometer/web_services/placemaker.rb +11 -13
- data/lib/barometer/web_services/timezone.rb +5 -7
- data/lib/barometer/web_services/weather_id.rb +4 -6
- data/lib/barometer/web_services/web_service.rb +4 -4
- data/spec/barometer_spec.rb +25 -27
- data/spec/cassettes/Barometer.json +1 -0
- data/spec/cassettes/Query.json +1 -0
- data/spec/cassettes/Query_Format_Coordinates.json +1 -0
- data/spec/cassettes/Query_Format_Geocode.json +1 -0
- data/spec/cassettes/Query_Format_WeatherID.json +1 -0
- data/spec/cassettes/Query_Format_WoeID.json +1 -0
- data/spec/cassettes/WeatherService.json +1 -0
- data/spec/cassettes/WeatherService_Noaa.json +1 -0
- data/spec/cassettes/WeatherService_WeatherBug.json +1 -0
- data/spec/cassettes/WeatherService_Wunderground.json +1 -0
- data/spec/cassettes/WeatherService_Yahoo.json +1 -0
- data/spec/cassettes/WebService_Geocode.json +1 -0
- data/spec/cassettes/WebService_NoaaStation.json +1 -0
- data/spec/data/distance_spec.rb +60 -60
- data/spec/data/geo_spec.rb +23 -23
- data/spec/data/local_datetime_spec.rb +44 -44
- data/spec/data/local_time_spec.rb +47 -47
- data/spec/data/location_spec.rb +16 -16
- data/spec/data/pressure_spec.rb +61 -61
- data/spec/data/speed_spec.rb +69 -69
- data/spec/data/sun_spec.rb +25 -25
- data/spec/data/temperature_spec.rb +68 -68
- data/spec/data/units_spec.rb +21 -21
- data/spec/data/zone_spec.rb +35 -35
- data/spec/formats/coordinates_spec.rb +27 -27
- data/spec/formats/format_spec.rb +17 -25
- data/spec/formats/geocode_spec.rb +23 -31
- data/spec/formats/icao_spec.rb +26 -32
- data/spec/formats/postalcode_spec.rb +22 -28
- data/spec/formats/short_zipcode_spec.rb +20 -26
- data/spec/formats/weather_id_spec.rb +57 -67
- data/spec/formats/woe_id_spec.rb +59 -59
- data/spec/formats/zipcode_spec.rb +39 -47
- data/spec/key_file_parser_spec.rb +28 -0
- data/spec/measurements/measurement_spec.rb +79 -133
- data/spec/measurements/result_array_spec.rb +23 -38
- data/spec/measurements/result_spec.rb +100 -128
- data/spec/query_spec.rb +83 -100
- data/spec/spec_helper.rb +24 -6
- data/spec/weather_services/noaa_spec.rb +179 -0
- data/spec/weather_services/services_spec.rb +28 -36
- data/spec/weather_services/weather_bug_spec.rb +57 -77
- data/spec/weather_services/wunderground_spec.rb +36 -65
- data/spec/weather_services/yahoo_spec.rb +38 -60
- data/spec/weather_spec.rb +79 -79
- data/spec/web_services/geocode_spec.rb +7 -11
- data/spec/web_services/noaa_station_id_spec.rb +33 -0
- data/spec/web_services/placemaker_spec.rb +7 -12
- data/spec/web_services/web_services_spec.rb +3 -9
- metadata +214 -163
- data/VERSION.yml +0 -5
- data/lib/barometer/weather_services/google.rb +0 -142
- data/lib/barometer/weather_services/weather_dot_com.rb +0 -279
- data/spec/fakeweb_helper.rb +0 -179
- data/spec/fixtures/formats/weather_id/90210.xml +0 -7
- data/spec/fixtures/formats/weather_id/from_USGA0028.xml +0 -3
- data/spec/fixtures/formats/weather_id/ksfo.xml +0 -1
- data/spec/fixtures/formats/weather_id/manhattan.xml +0 -7
- data/spec/fixtures/formats/weather_id/new_york.xml +0 -1
- data/spec/fixtures/formats/weather_id/the_hills.xml +0 -1
- data/spec/fixtures/geocode/40_73_v3.json +0 -497
- data/spec/fixtures/geocode/90210_v3.json +0 -63
- data/spec/fixtures/geocode/T5B4M9_v3.json +0 -68
- data/spec/fixtures/geocode/atlanta_v3.json +0 -58
- data/spec/fixtures/geocode/calgary_ab_v3.json +0 -58
- data/spec/fixtures/geocode/ksfo_v3.json +0 -73
- data/spec/fixtures/geocode/newyork_ny_v3.json +0 -58
- data/spec/fixtures/services/google/calgary_ab.xml +0 -1
- data/spec/fixtures/services/placemaker/T5B4M9.xml +0 -65
- data/spec/fixtures/services/placemaker/atlanta.xml +0 -65
- data/spec/fixtures/services/placemaker/coords.xml +0 -65
- data/spec/fixtures/services/placemaker/ksfo.xml +0 -65
- data/spec/fixtures/services/placemaker/new_york.xml +0 -65
- data/spec/fixtures/services/placemaker/the_hills.xml +0 -65
- data/spec/fixtures/services/placemaker/w615702.xml +0 -47
- data/spec/fixtures/services/weather_bug/90210_current.xml +0 -93
- data/spec/fixtures/services/weather_bug/90210_forecast.xml +0 -76
- data/spec/fixtures/services/weather_dot_com/90210.xml +0 -1
- data/spec/fixtures/services/wunderground/current_calgary_ab.xml +0 -9
- data/spec/fixtures/services/wunderground/forecast_calgary_ab.xml +0 -13
- data/spec/fixtures/services/yahoo/90210.xml +0 -3
- data/spec/weather_services/google_spec.rb +0 -181
- data/spec/weather_services/weather_dot_com_spec.rb +0 -224
data/spec/data/zone_spec.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Data::Zone" do
|
4
|
-
|
4
|
+
|
5
5
|
# describe "and class methods" do
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# it "responds to now and returns Time object" do
|
8
8
|
# Data::Zone.respond_to?("now").should be_true
|
9
9
|
# Data::Zone.now.is_a?(Time).should be_true
|
10
10
|
# end
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# it "responds to today and returns Date object" do
|
13
13
|
# Data::Zone.respond_to?("today").should be_true
|
14
14
|
# Data::Zone.today.is_a?(Date).should be_true
|
15
15
|
# end
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# end
|
18
|
-
|
18
|
+
|
19
19
|
describe "when initialized" do
|
20
|
-
|
20
|
+
|
21
21
|
describe "with a full zone" do
|
22
|
-
|
22
|
+
|
23
23
|
before(:each) do
|
24
24
|
@utc = Time.now.utc
|
25
25
|
@timezone = "Europe/Paris"
|
26
26
|
@zone = Data::Zone.new(@timezone)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "responds to zone_full" do
|
30
30
|
@zone.zone_full.should_not be_nil
|
31
31
|
@zone.zone_full.should == @timezone
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "responds to zone_code" do
|
35
35
|
@zone.zone_code.should be_nil
|
36
36
|
end
|
@@ -41,22 +41,22 @@ describe "Data::Zone" do
|
|
41
41
|
|
42
42
|
it "responds to tz" do
|
43
43
|
lambda { Data::Zone.new("invalid timezone") }.should raise_error(ArgumentError)
|
44
|
-
|
44
|
+
|
45
45
|
zone = Data::Zone.new(@timezone)
|
46
46
|
zone.tz.should_not be_nil
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
it "responds to full" do
|
50
50
|
@zone.respond_to?("full").should be_true
|
51
51
|
zone = Data::Zone.new(@timezone)
|
52
52
|
zone.tz = nil
|
53
53
|
zone.tz.should be_nil
|
54
54
|
zone.full.should == @timezone
|
55
|
-
|
55
|
+
|
56
56
|
zone = Data::Zone.new(@timezone)
|
57
57
|
zone.full.should == @timezone
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "responds to code" do
|
61
61
|
@zone.respond_to?("code").should be_true
|
62
62
|
zone = Data::Zone.new(@timezone)
|
@@ -78,14 +78,14 @@ describe "Data::Zone" do
|
|
78
78
|
zone.tz.should be_nil
|
79
79
|
zone.dst?.should be_nil
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "responds to now" do
|
83
83
|
@zone.respond_to?("now").should be_true
|
84
84
|
@zone.now.is_a?(Time).should be_true
|
85
|
-
|
85
|
+
|
86
86
|
period = @zone.tz.period_for_utc(Time.now)
|
87
87
|
actual_now = Time.now.utc + period.utc_total_offset
|
88
|
-
|
88
|
+
|
89
89
|
now = @zone.now
|
90
90
|
now.hour.should == actual_now.hour
|
91
91
|
now.min.should == actual_now.min
|
@@ -94,40 +94,40 @@ describe "Data::Zone" do
|
|
94
94
|
now.month.should == actual_now.month
|
95
95
|
now.day.should == actual_now.day
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it "responds to today" do
|
99
99
|
@zone.respond_to?("today").should be_true
|
100
100
|
@zone.today.is_a?(Date).should be_true
|
101
|
-
|
101
|
+
|
102
102
|
period = @zone.tz.period_for_utc(Time.now)
|
103
103
|
actual_now = Time.now.utc + period.utc_total_offset
|
104
|
-
|
104
|
+
|
105
105
|
now = @zone.today
|
106
106
|
now.year.should == actual_now.year
|
107
107
|
now.month.should == actual_now.month
|
108
108
|
now.day.should == actual_now.day
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
it "converts local_time to utc" do
|
112
112
|
local_time = Time.now.utc
|
113
113
|
utc_time = @zone.local_to_utc(local_time)
|
114
|
-
|
114
|
+
|
115
115
|
offset = @zone.tz.period_for_utc(local_time).utc_total_offset
|
116
116
|
utc_time.should == (local_time - offset)
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
it "converts utc to local_time" do
|
120
120
|
utc_time = Time.now.utc
|
121
121
|
local_time = @zone.utc_to_local(utc_time)
|
122
|
-
|
122
|
+
|
123
123
|
offset = @zone.tz.period_for_utc(local_time).utc_total_offset
|
124
124
|
utc_time.should == (local_time - offset)
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
describe "with a zone code" do
|
130
|
-
|
130
|
+
|
131
131
|
before(:each) do
|
132
132
|
@utc = Time.now.utc
|
133
133
|
@timezone = "EAST"
|
@@ -226,9 +226,9 @@ describe "Data::Zone" do
|
|
226
226
|
end
|
227
227
|
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
describe "with a zone offset" do
|
231
|
-
|
231
|
+
|
232
232
|
before(:each) do
|
233
233
|
@utc = Time.now.utc
|
234
234
|
@timezone = 8.5
|
@@ -338,29 +338,29 @@ describe "Data::Zone" do
|
|
338
338
|
end
|
339
339
|
|
340
340
|
end
|
341
|
-
|
341
|
+
|
342
342
|
end
|
343
|
-
|
343
|
+
|
344
344
|
describe "when detecting zones" do
|
345
|
-
|
345
|
+
|
346
346
|
it "recognozes a full time zone format" do
|
347
347
|
Data::Zone.is_zone_full?("invalid").should be_false
|
348
348
|
Data::Zone.is_zone_full?("America/New York").should be_true
|
349
349
|
end
|
350
|
-
|
350
|
+
|
351
351
|
it "matches a zone offset" do
|
352
352
|
Data::Zone.is_zone_offset?("invalid").should be_false
|
353
353
|
Data::Zone.is_zone_offset?("MST").should be_false
|
354
354
|
Data::Zone.is_zone_offset?("10").should be_false
|
355
355
|
Data::Zone.is_zone_offset?(-10).should be_true
|
356
356
|
end
|
357
|
-
|
357
|
+
|
358
358
|
it "matches a zone code" do
|
359
359
|
Data::Zone.is_zone_code?("invalid").should be_false
|
360
360
|
Data::Zone.is_zone_code?("MST").should be_true
|
361
361
|
Data::Zone.is_zone_code?("EAST").should be_true
|
362
362
|
end
|
363
|
-
|
363
|
+
|
364
364
|
end
|
365
|
-
|
365
|
+
|
366
366
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
3
|
+
describe Barometer::Query::Format::Coordinates, :vcr => {
|
4
|
+
:cassette_name => "Query::Format::Coordinates"
|
5
|
+
} do
|
5
6
|
before(:each) do
|
6
7
|
@short_zipcode = "90210"
|
7
8
|
@zipcode = @short_zipcode
|
@@ -12,22 +13,21 @@ describe "Query::Coordinates" do
|
|
12
13
|
@geocode = "New York, NY"
|
13
14
|
@icao = "KSFO"
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
describe "and class methods" do
|
17
|
-
|
18
18
|
it "returns a format" do
|
19
19
|
Barometer::Query::Format::Coordinates.format.should == :coordinates
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "returns a country" do
|
23
23
|
Barometer::Query::Format::Coordinates.country_code.should be_nil
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "returns a regex" do
|
27
27
|
Barometer::Query::Format::Coordinates.regex.should_not be_nil
|
28
28
|
Barometer::Query::Format::Coordinates.regex.is_a?(Regexp).should be_true
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "returns the convertable_formats" do
|
32
32
|
Barometer::Query::Format::Coordinates.convertable_formats.should_not be_nil
|
33
33
|
Barometer::Query::Format::Coordinates.convertable_formats.is_a?(Array).should be_true
|
@@ -39,26 +39,23 @@ describe "Query::Coordinates" do
|
|
39
39
|
Barometer::Query::Format::Coordinates.convertable_formats.include?(:icao).should be_true
|
40
40
|
Barometer::Query::Format::Coordinates.convertable_formats.include?(:geocode).should be_true
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
describe "is?," do
|
44
|
-
|
45
44
|
before(:each) do
|
46
45
|
@valid = "40.756054,-73.986951"
|
47
46
|
@invalid = "invalid"
|
48
47
|
end
|
49
|
-
|
48
|
+
|
50
49
|
it "recognizes a valid format" do
|
51
50
|
Barometer::Query::Format::Coordinates.is?(@valid).should be_true
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
it "recognizes non-valid format" do
|
55
54
|
Barometer::Query::Format::Coordinates.is?(@invalid).should be_false
|
56
55
|
end
|
57
|
-
|
58
56
|
end
|
59
|
-
|
57
|
+
|
60
58
|
describe "when converting using 'to'," do
|
61
|
-
|
62
59
|
it "requires a Query::Format object" do
|
63
60
|
lambda { Barometer::Query::Format::Coordinates.to }.should raise_error(ArgumentError)
|
64
61
|
lambda { Barometer::Query::Format::Coordinates.to("invalid") }.should raise_error(ArgumentError)
|
@@ -66,7 +63,7 @@ describe "Query::Coordinates" do
|
|
66
63
|
query.is_a?(Barometer::Query).should be_true
|
67
64
|
lambda { Barometer::Query::Format::Coordinates.to(original_query) }.should_not raise_error(ArgumentError)
|
68
65
|
end
|
69
|
-
|
66
|
+
|
70
67
|
it "returns a Barometer::Query" do
|
71
68
|
query = Barometer::Query.new(@short_zipcode)
|
72
69
|
Barometer::Query::Format::Coordinates.to(query).is_a?(Barometer::Query).should be_true
|
@@ -107,7 +104,11 @@ describe "Query::Coordinates" do
|
|
107
104
|
query = Barometer::Query.new(@geocode)
|
108
105
|
query.format.should == :geocode
|
109
106
|
new_query = Barometer::Query::Format::Coordinates.to(query)
|
110
|
-
|
107
|
+
|
108
|
+
new_query_coords = new_query.q.split(',').map{|c| c.to_f}
|
109
|
+
new_query_coords[0].should be_within(0.00001).of(40.7143528)
|
110
|
+
new_query_coords[1].should be_within(0.00001).of(-74.0059731)
|
111
|
+
|
111
112
|
new_query.country_code.should == "US"
|
112
113
|
new_query.format.should == :coordinates
|
113
114
|
new_query.geo.should_not be_nil
|
@@ -117,7 +118,7 @@ describe "Query::Coordinates" do
|
|
117
118
|
query = Barometer::Query.new(@postal_code)
|
118
119
|
query.format.should == :postalcode
|
119
120
|
new_query = Barometer::Query::Format::Coordinates.to(query)
|
120
|
-
new_query.q.should == "53.
|
121
|
+
new_query.q.should == "53.5721719,-113.4551835"
|
121
122
|
new_query.country_code.should == "CA"
|
122
123
|
new_query.format.should == :coordinates
|
123
124
|
new_query.geo.should_not be_nil
|
@@ -137,30 +138,29 @@ describe "Query::Coordinates" do
|
|
137
138
|
query = Barometer::Query.new(@coordinates)
|
138
139
|
query.format.should == :coordinates
|
139
140
|
new_query = Barometer::Query::Format::Coordinates.to(query)
|
140
|
-
|
141
|
+
|
142
|
+
new_query_coords = new_query.q.split(',').map{|c| c.to_f}
|
143
|
+
new_query_coords[0].should be_within(0.00001).of(40.7560413)
|
144
|
+
new_query_coords[1].should be_within(0.00001).of(-73.9869192)
|
145
|
+
|
141
146
|
new_query.country_code.should == "US"
|
142
147
|
new_query.format.should == :coordinates
|
143
148
|
new_query.geo.should_not be_nil
|
144
149
|
end
|
145
|
-
|
146
150
|
end
|
147
|
-
|
151
|
+
|
148
152
|
describe "parsing" do
|
149
|
-
|
150
153
|
it "returns the latitude" do
|
151
154
|
Barometer::Query::Format::Coordinates.parse_latitude(@coordinates).should == "40.756054"
|
152
155
|
end
|
153
|
-
|
156
|
+
|
154
157
|
it "returns the longitude" do
|
155
158
|
Barometer::Query::Format::Coordinates.parse_longitude(@coordinates).should == "-73.986951"
|
156
159
|
end
|
157
|
-
|
160
|
+
|
158
161
|
it "returns nil when unknown" do
|
159
162
|
Barometer::Query::Format::Coordinates.parse_longitude(@short_zipcode).should be_nil
|
160
163
|
end
|
161
|
-
|
162
164
|
end
|
163
|
-
|
164
165
|
end
|
165
|
-
|
166
|
-
end
|
166
|
+
end
|
data/spec/formats/format_spec.rb
CHANGED
@@ -1,44 +1,38 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
3
|
+
describe Barometer::Query::Format do
|
5
4
|
describe "and class methods" do
|
6
|
-
|
7
5
|
describe "is?," do
|
8
|
-
|
9
6
|
it "requires a String" do
|
10
7
|
invalid = 1
|
11
8
|
lambda { Barometer::Query::Format.is?(invalid) }.should raise_error(ArgumentError)
|
12
|
-
|
9
|
+
|
13
10
|
valid = "string"
|
14
11
|
valid.is_a?(String).should be_true
|
15
12
|
lambda { Barometer::Query::Format.is?(valid) }.should_not raise_error(ArgumentError)
|
16
13
|
end
|
17
|
-
|
14
|
+
|
18
15
|
it "calls a stubbed undefined method" do
|
19
16
|
lambda { Barometer::Query::Format.is?("valid") }.should raise_error(NotImplementedError)
|
20
|
-
end
|
21
|
-
|
17
|
+
end
|
22
18
|
end
|
23
|
-
|
19
|
+
|
24
20
|
describe "converts?," do
|
25
|
-
|
26
21
|
it "requires a Query object" do
|
27
22
|
invalid = 1
|
28
23
|
Barometer::Query::Format.converts?(invalid).should be_false
|
29
|
-
|
24
|
+
|
30
25
|
valid = Barometer::Query.new
|
31
26
|
valid.is_a?(Barometer::Query).should be_true
|
32
27
|
lambda { Barometer::Query::Format.converts?(valid) }.should_not raise_error(ArgumentError)
|
33
28
|
end
|
34
|
-
|
29
|
+
|
35
30
|
it "returns false" do
|
36
31
|
valid = Barometer::Query.new
|
37
32
|
Barometer::Query::Format.converts?(valid).should be_false
|
38
|
-
end
|
39
|
-
|
33
|
+
end
|
40
34
|
end
|
41
|
-
|
35
|
+
|
42
36
|
it "detects a Query object" do
|
43
37
|
invalid = 1
|
44
38
|
Barometer::Query::Format.is_a_query?.should be_false
|
@@ -47,36 +41,34 @@ describe "Query::Format" do
|
|
47
41
|
valid.is_a?(Barometer::Query).should be_true
|
48
42
|
Barometer::Query::Format.is_a_query?(valid).should be_true
|
49
43
|
end
|
50
|
-
|
44
|
+
|
51
45
|
it "stubs regex" do
|
52
46
|
lambda { Barometer::Query::Format.regex }.should raise_error(NotImplementedError)
|
53
47
|
end
|
54
|
-
|
48
|
+
|
55
49
|
it "stubs format" do
|
56
50
|
lambda { Barometer::Query::Format.format }.should raise_error(NotImplementedError)
|
57
51
|
end
|
58
|
-
|
52
|
+
|
59
53
|
it "stubs to" do
|
60
54
|
Barometer::Query::Format.to.should be_nil
|
61
55
|
end
|
62
|
-
|
56
|
+
|
63
57
|
it "stubs country_code" do
|
64
58
|
Barometer::Query::Format.country_code.should be_nil
|
65
59
|
end
|
66
|
-
|
60
|
+
|
67
61
|
it "stubs convertable_formats" do
|
68
62
|
Barometer::Query::Format.convertable_formats.should == []
|
69
63
|
end
|
70
|
-
|
64
|
+
|
71
65
|
it "stubs convert_query" do
|
72
66
|
Barometer::Query::Format.respond_to?(:convert_query).should be_true
|
73
67
|
end
|
74
|
-
|
68
|
+
|
75
69
|
it "normally does nothing when converting a query" do
|
76
70
|
text = "this is a query"
|
77
71
|
Barometer::Query::Format.convert_query(text).should == text
|
78
72
|
end
|
79
|
-
|
80
73
|
end
|
81
|
-
|
82
|
-
end
|
74
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
3
|
+
describe Barometer::Query::Format::Geocode, :vcr => {
|
4
|
+
:cassette_name => "Query::Format::Geocode"
|
5
|
+
} do
|
5
6
|
before(:each) do
|
6
7
|
@short_zipcode = "90210"
|
7
8
|
@zipcode = @short_zipcode
|
@@ -12,17 +13,16 @@ describe "Query::Geocode" do
|
|
12
13
|
@geocode = "New York, NY"
|
13
14
|
@icao = "KSFO"
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
describe "and class methods" do
|
17
|
-
|
18
18
|
it "returns a format" do
|
19
19
|
Barometer::Query::Format::Geocode.format.should == :geocode
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "returns a country" do
|
23
23
|
Barometer::Query::Format::Geocode.country_code.should be_nil
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "returns the convertable_formats" do
|
27
27
|
Barometer::Query::Format::Geocode.convertable_formats.should_not be_nil
|
28
28
|
Barometer::Query::Format::Geocode.convertable_formats.is_a?(Array).should be_true
|
@@ -32,26 +32,23 @@ describe "Query::Geocode" do
|
|
32
32
|
Barometer::Query::Format::Geocode.convertable_formats.include?(:weather_id).should be_true
|
33
33
|
Barometer::Query::Format::Geocode.convertable_formats.include?(:icao).should be_true
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
describe "is?," do
|
37
|
-
|
38
37
|
before(:each) do
|
39
38
|
@valid = "New York, NY"
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
it "recognizes a valid format" do
|
43
42
|
Barometer::Query::Format::Geocode.is?(@valid).should be_true
|
44
43
|
Barometer::Query::Format::Geocode.is?.should be_false
|
45
44
|
end
|
46
|
-
|
47
45
|
end
|
48
|
-
|
46
|
+
|
49
47
|
describe "when converting using 'to'," do
|
50
|
-
|
51
48
|
before(:each) do
|
52
49
|
Barometer.force_geocode = false
|
53
50
|
end
|
54
|
-
|
51
|
+
|
55
52
|
it "requires a Barometer::Query object" do
|
56
53
|
lambda { Barometer::Query::Format::Geocode.to }.should raise_error(ArgumentError)
|
57
54
|
lambda { Barometer::Query::Format::Geocode.to("invalid") }.should raise_error(ArgumentError)
|
@@ -59,12 +56,12 @@ describe "Query::Geocode" do
|
|
59
56
|
query.is_a?(Barometer::Query).should be_true
|
60
57
|
lambda { Barometer::Query::Format::Geocode.to(query) }.should_not raise_error(ArgumentError)
|
61
58
|
end
|
62
|
-
|
59
|
+
|
63
60
|
it "returns a Barometer::Query" do
|
64
61
|
query = Barometer::Query.new(@short_zipcode)
|
65
62
|
Barometer::Query::Format::Geocode.to(query).is_a?(Barometer::Query).should be_true
|
66
63
|
end
|
67
|
-
|
64
|
+
|
68
65
|
it "converts from short_zipcode" do
|
69
66
|
query = Barometer::Query.new(@short_zipcode)
|
70
67
|
query.format.should == :short_zipcode
|
@@ -74,7 +71,7 @@ describe "Query::Geocode" do
|
|
74
71
|
new_query.format.should == :geocode
|
75
72
|
new_query.geo.should_not be_nil
|
76
73
|
end
|
77
|
-
|
74
|
+
|
78
75
|
it "converts from zipcode" do
|
79
76
|
query = Barometer::Query.new(@zipcode)
|
80
77
|
query.format = :zipcode
|
@@ -85,7 +82,7 @@ describe "Query::Geocode" do
|
|
85
82
|
new_query.format.should == :geocode
|
86
83
|
new_query.geo.should_not be_nil
|
87
84
|
end
|
88
|
-
|
85
|
+
|
89
86
|
it "converts from weather_id" do
|
90
87
|
query = Barometer::Query.new(@weather_id)
|
91
88
|
query.format.should == :weather_id
|
@@ -95,7 +92,7 @@ describe "Query::Geocode" do
|
|
95
92
|
new_query.format.should == :geocode
|
96
93
|
new_query.geo.should be_nil
|
97
94
|
end
|
98
|
-
|
95
|
+
|
99
96
|
it "converts from coordinates" do
|
100
97
|
query = Barometer::Query.new(@coordinates)
|
101
98
|
query.format.should == :coordinates
|
@@ -105,7 +102,7 @@ describe "Query::Geocode" do
|
|
105
102
|
new_query.format.should == :geocode
|
106
103
|
new_query.geo.should_not be_nil
|
107
104
|
end
|
108
|
-
|
105
|
+
|
109
106
|
it "converts from icao" do
|
110
107
|
query = Barometer::Query.new(@icao)
|
111
108
|
query.format.should == :icao
|
@@ -115,14 +112,14 @@ describe "Query::Geocode" do
|
|
115
112
|
new_query.format.should == :geocode
|
116
113
|
new_query.geo.should_not be_nil
|
117
114
|
end
|
118
|
-
|
115
|
+
|
119
116
|
it "does not convert postalcode" do
|
120
117
|
query = Barometer::Query.new(@postal_code)
|
121
118
|
query.format.should == :postalcode
|
122
119
|
new_query = Barometer::Query::Format::Geocode.to(query)
|
123
120
|
new_query.should be_nil
|
124
121
|
end
|
125
|
-
|
122
|
+
|
126
123
|
it "leaves geocode untouched" do
|
127
124
|
query = Barometer::Query.new(@geocode)
|
128
125
|
query.format.should == :geocode
|
@@ -132,11 +129,9 @@ describe "Query::Geocode" do
|
|
132
129
|
new_query.format.should == :geocode
|
133
130
|
new_query.geo.should be_nil
|
134
131
|
end
|
135
|
-
|
136
132
|
end
|
137
|
-
|
133
|
+
|
138
134
|
describe "when geocoding" do
|
139
|
-
|
140
135
|
it "requires a Barometer::Query object" do
|
141
136
|
lambda { Barometer::Query::Format::Geocode.geocode }.should raise_error(ArgumentError)
|
142
137
|
lambda { Barometer::Query::Format::Geocode.geocode("invalid") }.should raise_error(ArgumentError)
|
@@ -144,12 +139,12 @@ describe "Query::Geocode" do
|
|
144
139
|
query.is_a?(Barometer::Query).should be_true
|
145
140
|
lambda { Barometer::Query::Format::Geocode.geocode(original_query) }.should_not raise_error(ArgumentError)
|
146
141
|
end
|
147
|
-
|
142
|
+
|
148
143
|
it "returns a Barometer::Query" do
|
149
144
|
query = Barometer::Query.new(@short_zipcode)
|
150
145
|
Barometer::Query::Format::Geocode.geocode(query).is_a?(Barometer::Query).should be_true
|
151
146
|
end
|
152
|
-
|
147
|
+
|
153
148
|
it "converts from short_zipcode" do
|
154
149
|
query = Barometer::Query.new(@short_zipcode)
|
155
150
|
query.format.should == :short_zipcode
|
@@ -159,13 +154,10 @@ describe "Query::Geocode" do
|
|
159
154
|
new_query.format.should == :geocode
|
160
155
|
new_query.geo.should_not be_nil
|
161
156
|
end
|
162
|
-
|
163
157
|
end
|
164
|
-
|
158
|
+
|
165
159
|
it "doesn't define a regex" do
|
166
160
|
lambda { Barometer::Query::Format::Geocode.regex }.should raise_error(NotImplementedError)
|
167
161
|
end
|
168
|
-
|
169
162
|
end
|
170
|
-
|
171
|
-
end
|
163
|
+
end
|