barometer 0.3.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query::Icao" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@valid = "KSFO"
|
7
|
+
@invalid = "invalid"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "and class methods" do
|
11
|
+
|
12
|
+
it "returns a format" do
|
13
|
+
Query::Format::Icao.format.should == :icao
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a country" do
|
17
|
+
Query::Format::Icao.country_code.should be_nil
|
18
|
+
Query::Format::Icao.country_code("KSFO").should == "US"
|
19
|
+
Query::Format::Icao.country_code("CYYC").should == "CA"
|
20
|
+
Query::Format::Icao.country_code("ETAA").should == "DE"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a regex" do
|
24
|
+
Query::Format::Icao.regex.should_not be_nil
|
25
|
+
Query::Format::Icao.regex.is_a?(Regexp).should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns the convertable_formats" do
|
29
|
+
Query::Format::Icao.convertable_formats.should_not be_nil
|
30
|
+
Query::Format::Icao.convertable_formats.is_a?(Array).should be_true
|
31
|
+
Query::Format::Icao.convertable_formats.should == []
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "is?," do
|
35
|
+
|
36
|
+
it "recognizes a valid format" do
|
37
|
+
Query::Format::Icao.is?(@valid).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "recognizes non-valid format" do
|
41
|
+
Query::Format::Icao.is?(@invalid).should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
it "stubs to" do
|
47
|
+
Query::Format::Icao.to.should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "stubs convertable_formats" do
|
51
|
+
Query::Format::Icao.convertable_formats.should == []
|
52
|
+
end
|
53
|
+
|
54
|
+
it "doesn't convert" do
|
55
|
+
query = Barometer::Query.new(@valid)
|
56
|
+
Query::Format::Icao.converts?(query).should be_false
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query::Postalcode" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@valid = "T5B 4M9"
|
7
|
+
@invalid = "90210"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "and class methods" do
|
11
|
+
|
12
|
+
it "returns a format" do
|
13
|
+
Query::Format::Postalcode.format.should == :postalcode
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a country" do
|
17
|
+
Query::Format::Postalcode.country_code.should == "CA"
|
18
|
+
Query::Format::Postalcode.country_code("ignored").should == "CA"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns a regex" do
|
22
|
+
Query::Format::Postalcode.regex.should_not be_nil
|
23
|
+
Query::Format::Postalcode.regex.is_a?(Regexp).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the convertable_formats" do
|
27
|
+
Query::Format::Postalcode.convertable_formats.should_not be_nil
|
28
|
+
Query::Format::Postalcode.convertable_formats.is_a?(Array).should be_true
|
29
|
+
Query::Format::Postalcode.convertable_formats.should == []
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "is?," do
|
33
|
+
|
34
|
+
it "recognizes a valid format" do
|
35
|
+
Query::Format::Postalcode.is?(@valid).should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "recognizes non-valid format" do
|
39
|
+
Query::Format::Postalcode.is?(@invalid).should be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
it "stubs to" do
|
45
|
+
Query::Format::Postalcode.to.should be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "stubs convertable_formats" do
|
49
|
+
Query::Format::Postalcode.convertable_formats.should == []
|
50
|
+
end
|
51
|
+
|
52
|
+
it "doesn't convert" do
|
53
|
+
query = Barometer::Query.new(@valid)
|
54
|
+
Query::Format::Postalcode.converts?(query).should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query::ShortZipcode" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@valid = "90210"
|
7
|
+
@invalid = "90210-5555"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "and class methods" do
|
11
|
+
|
12
|
+
it "returns a format" do
|
13
|
+
Query::Format::ShortZipcode.format.should == :short_zipcode
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a country" do
|
17
|
+
Query::Format::ShortZipcode.country_code.should == "US"
|
18
|
+
Query::Format::ShortZipcode.country_code("ignored").should == "US"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns a regex" do
|
22
|
+
Query::Format::ShortZipcode.regex.should_not be_nil
|
23
|
+
Query::Format::ShortZipcode.regex.is_a?(Regexp).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "is?," do
|
27
|
+
|
28
|
+
it "recognizes a valid format" do
|
29
|
+
Query::Format::ShortZipcode.is?(@valid).should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "recognizes non-valid format" do
|
33
|
+
Query::Format::ShortZipcode.is?(@invalid).should be_false
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
it "stubs to" do
|
39
|
+
Query::Format::ShortZipcode.to.should be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "stubs convertable_formats" do
|
43
|
+
Query::Format::ShortZipcode.convertable_formats.should == []
|
44
|
+
end
|
45
|
+
|
46
|
+
it "doesn't convert" do
|
47
|
+
query = Barometer::Query.new(@valid)
|
48
|
+
Query::Format::ShortZipcode.converts?(query).should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query::WeatherID" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@short_zipcode = "90210"
|
7
|
+
@zipcode = @short_zipcode
|
8
|
+
@long_zipcode = "90210-5555"
|
9
|
+
@weather_id = "USGA0028"
|
10
|
+
@postal_code = "T5B 4M9"
|
11
|
+
@coordinates = "40.756054,-73.986951"
|
12
|
+
@geocode = "New York, NY"
|
13
|
+
@icao = "KSFO"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "and class methods" do
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@us_query = "USGA0000"
|
20
|
+
@ca_query = "CAAB0000"
|
21
|
+
@es_query = "SPXX0000"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a format" do
|
25
|
+
Query::Format::WeatherID.format.should == :weather_id
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a country" do
|
29
|
+
Query::Format::WeatherID.country_code.should be_nil
|
30
|
+
Query::Format::WeatherID.country_code("i").should be_nil
|
31
|
+
Query::Format::WeatherID.country_code(@us_query).should == "US"
|
32
|
+
Query::Format::WeatherID.country_code(@ca_query).should == "CA"
|
33
|
+
Query::Format::WeatherID.country_code(@es_query).should == "ES"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a regex" do
|
37
|
+
Query::Format::WeatherID.regex.should_not be_nil
|
38
|
+
Query::Format::WeatherID.regex.is_a?(Regexp).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the convertable_formats" do
|
42
|
+
Query::Format::WeatherID.convertable_formats.should_not be_nil
|
43
|
+
Query::Format::WeatherID.convertable_formats.is_a?(Array).should be_true
|
44
|
+
Query::Format::WeatherID.convertable_formats.include?(:short_zipcode).should be_true
|
45
|
+
Query::Format::WeatherID.convertable_formats.include?(:zipcode).should be_true
|
46
|
+
Query::Format::WeatherID.convertable_formats.include?(:coordinates).should be_true
|
47
|
+
Query::Format::WeatherID.convertable_formats.include?(:geocode).should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "is?," do
|
51
|
+
|
52
|
+
before(:each) do
|
53
|
+
@valid = "USGA0028"
|
54
|
+
@invalid = "invalid"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "recognizes a valid format" do
|
58
|
+
Query::Format::WeatherID.is?(@valid).should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "recognizes non-valid format" do
|
62
|
+
Query::Format::WeatherID.is?(@invalid).should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "fixing country codes" do
|
68
|
+
|
69
|
+
it "doesn't fix a correct code" do
|
70
|
+
Query::Format::WeatherID.send("_fix_country", "CA").should == "CA"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "fixes an incorrect code" do
|
74
|
+
Query::Format::WeatherID.send("_fix_country", "SP").should == "ES"
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "when reversing lookup" do
|
80
|
+
|
81
|
+
it "requires a Barometer::Query object" do
|
82
|
+
lambda { Query::Format::WeatherID.reverse }.should raise_error(ArgumentError)
|
83
|
+
lambda { Query::Format::WeatherID.reverse("invalid") }.should raise_error(ArgumentError)
|
84
|
+
query = Barometer::Query.new(@weather_id)
|
85
|
+
query.is_a?(Barometer::Query).should be_true
|
86
|
+
lambda { Query::Format::WeatherID.reverse(original_query) }.should_not raise_error(ArgumentError)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns a Barometer::Query" do
|
90
|
+
query = Barometer::Query.new(@weather_id)
|
91
|
+
Query::Format::WeatherID.reverse(query).is_a?(Barometer::Query).should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "reverses a valid weather_id (US)" do
|
95
|
+
query = Barometer::Query.new(@weather_id)
|
96
|
+
new_query = Query::Format::WeatherID.reverse(query)
|
97
|
+
new_query.q.should == "Atlanta, GA, US"
|
98
|
+
new_query.country_code.should be_nil
|
99
|
+
new_query.format.should == :geocode
|
100
|
+
new_query.geo.should be_nil
|
101
|
+
end
|
102
|
+
|
103
|
+
it "doesn't reverse an invalid weather_id" do
|
104
|
+
query = Barometer::Query.new(@zipcode)
|
105
|
+
Query::Format::WeatherID.reverse(query).should be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "when converting using 'to'," do
|
111
|
+
|
112
|
+
before(:each) do
|
113
|
+
Barometer.google_geocode_key = KEY
|
114
|
+
end
|
115
|
+
|
116
|
+
it "requires a Barometer::Query object" do
|
117
|
+
lambda { Query::Format::WeatherID.to }.should raise_error(ArgumentError)
|
118
|
+
lambda { Query::Format::WeatherID.to("invalid") }.should raise_error(ArgumentError)
|
119
|
+
query = Barometer::Query.new(@zipcode)
|
120
|
+
query.is_a?(Barometer::Query).should be_true
|
121
|
+
lambda { Query::Format::WeatherID.to(original_query) }.should_not raise_error(ArgumentError)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "returns a Barometer::Query" do
|
125
|
+
query = Barometer::Query.new(@short_zipcode)
|
126
|
+
Query::Format::WeatherID.to(query).is_a?(Barometer::Query).should be_true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "converts from short_zipcode" do
|
130
|
+
query = Barometer::Query.new(@short_zipcode)
|
131
|
+
query.format.should == :short_zipcode
|
132
|
+
new_query = Query::Format::WeatherID.to(query)
|
133
|
+
new_query.q.should == "USCA0090"
|
134
|
+
new_query.country_code.should == "US"
|
135
|
+
new_query.format.should == :weather_id
|
136
|
+
new_query.geo.should_not be_nil
|
137
|
+
end
|
138
|
+
|
139
|
+
it "converts from zipcode" do
|
140
|
+
query = Barometer::Query.new(@zipcode)
|
141
|
+
query.format = :zipcode
|
142
|
+
query.format.should == :zipcode
|
143
|
+
new_query = Query::Format::WeatherID.to(query)
|
144
|
+
new_query.q.should == "USCA0090"
|
145
|
+
new_query.country_code.should == "US"
|
146
|
+
new_query.format.should == :weather_id
|
147
|
+
new_query.geo.should_not be_nil
|
148
|
+
end
|
149
|
+
|
150
|
+
it "converts from coordinates" do
|
151
|
+
query = Barometer::Query.new(@coordinates)
|
152
|
+
query.format.should == :coordinates
|
153
|
+
new_query = Query::Format::WeatherID.to(query)
|
154
|
+
new_query.q.should == "USNY0996"
|
155
|
+
new_query.country_code.should == "US"
|
156
|
+
new_query.format.should == :weather_id
|
157
|
+
new_query.geo.should_not be_nil
|
158
|
+
end
|
159
|
+
|
160
|
+
it "converts from geocode" do
|
161
|
+
query = Barometer::Query.new(@geocode)
|
162
|
+
query.format.should == :geocode
|
163
|
+
new_query = Query::Format::WeatherID.to(query)
|
164
|
+
new_query.q.should == "USNY0996"
|
165
|
+
new_query.country_code.should == "US"
|
166
|
+
new_query.format.should == :weather_id
|
167
|
+
new_query.geo.should be_nil
|
168
|
+
end
|
169
|
+
|
170
|
+
it "returns nil for other formats" do
|
171
|
+
query = Barometer::Query.new(@weather_id)
|
172
|
+
query.format.should == :weather_id
|
173
|
+
new_query = Query::Format::WeatherID.to(query)
|
174
|
+
new_query.should be_nil
|
175
|
+
|
176
|
+
query = Barometer::Query.new(@postal_code)
|
177
|
+
query.format.should == :postalcode
|
178
|
+
new_query = Query::Format::WeatherID.to(query)
|
179
|
+
new_query.should be_nil
|
180
|
+
|
181
|
+
query = Barometer::Query.new(@icao)
|
182
|
+
query.format.should == :icao
|
183
|
+
new_query = Query::Format::WeatherID.to(query)
|
184
|
+
new_query.should be_nil
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Query::Zipcode" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@short_zipcode = "90210"
|
7
|
+
@zipcode = @short_zipcode
|
8
|
+
@long_zipcode = "90210-5555"
|
9
|
+
@weather_id = "USGA0028"
|
10
|
+
@postal_code = "T5B 4M9"
|
11
|
+
@coordinates = "40.756054,-73.986951"
|
12
|
+
@geocode = "New York, NY"
|
13
|
+
@icao = "KSFO"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "and class methods" do
|
17
|
+
|
18
|
+
it "returns a format" do
|
19
|
+
Query::Format::Zipcode.format.should == :zipcode
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns a country" do
|
23
|
+
Query::Format::Zipcode.country_code.should == "US"
|
24
|
+
Query::Format::Zipcode.country_code("ignored").should == "US"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns a regex" do
|
28
|
+
Query::Format::Zipcode.regex.should_not be_nil
|
29
|
+
Query::Format::Zipcode.regex.is_a?(Regexp).should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the convertable_formats" do
|
33
|
+
Query::Format::Zipcode.convertable_formats.should_not be_nil
|
34
|
+
Query::Format::Zipcode.convertable_formats.is_a?(Array).should be_true
|
35
|
+
Query::Format::Zipcode.convertable_formats.include?(:short_zipcode).should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "is?," do
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
@valid = "90210-5555"
|
42
|
+
@invalid = "invalid"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "recognizes a valid format" do
|
46
|
+
Query::Format::Zipcode.is?(@valid).should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "recognizes non-valid format" do
|
50
|
+
Query::Format::Zipcode.is?(@invalid).should be_false
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "when converting using 'to'," do
|
56
|
+
|
57
|
+
it "requires a Barometer::Query object" do
|
58
|
+
lambda { Query::Format::Zipcode.to }.should raise_error(ArgumentError)
|
59
|
+
lambda { Query::Format::Zipcode.to("invalid") }.should raise_error(ArgumentError)
|
60
|
+
query = Barometer::Query.new(@zipcode)
|
61
|
+
query.is_a?(Barometer::Query).should be_true
|
62
|
+
lambda { Query::Format::Zipcode.to(original_query) }.should_not raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns a Barometer::Query" do
|
66
|
+
query = Barometer::Query.new(@short_zipcode)
|
67
|
+
Query::Format::Zipcode.to(query).is_a?(Barometer::Query).should be_true
|
68
|
+
end
|
69
|
+
|
70
|
+
it "converts from short_zipcode" do
|
71
|
+
query = Barometer::Query.new(@short_zipcode)
|
72
|
+
query.format.should == :short_zipcode
|
73
|
+
new_query = Query::Format::Zipcode.to(query)
|
74
|
+
new_query.q.should == @short_zipcode
|
75
|
+
new_query.format.should == :zipcode
|
76
|
+
new_query.country_code.should == "US"
|
77
|
+
new_query.geo.should be_nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns nil for other formats" do
|
81
|
+
query = Barometer::Query.new(@zipcode)
|
82
|
+
query.format = :zipcode
|
83
|
+
query.format.should == :zipcode
|
84
|
+
Query::Format::Zipcode.to(query).should be_nil
|
85
|
+
|
86
|
+
query = Barometer::Query.new(@weather_id)
|
87
|
+
query.format.should == :weather_id
|
88
|
+
Query::Format::Zipcode.to(query).should be_nil
|
89
|
+
|
90
|
+
query = Barometer::Query.new(@postal_code)
|
91
|
+
query.format.should == :postalcode
|
92
|
+
Query::Format::Zipcode.to(query).should be_nil
|
93
|
+
|
94
|
+
query = Barometer::Query.new(@coordinates)
|
95
|
+
query.format.should == :coordinates
|
96
|
+
Query::Format::Zipcode.to(query).should be_nil
|
97
|
+
|
98
|
+
query = Barometer::Query.new(@geocode)
|
99
|
+
query.format.should == :geocode
|
100
|
+
Query::Format::Zipcode.to(query).should be_nil
|
101
|
+
|
102
|
+
query = Barometer::Query.new(@icao)
|
103
|
+
query.format.should == :icao
|
104
|
+
Query::Format::Zipcode.to(query).should be_nil
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|