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
@@ -1,24 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
include Barometer
|
2
3
|
|
3
4
|
describe "Yahoo" do
|
4
5
|
|
5
6
|
before(:each) do
|
6
|
-
@accepted_formats = [:zipcode]
|
7
|
+
@accepted_formats = [:zipcode, :weather_id]
|
7
8
|
#@base_uri = "http://google.com"
|
8
9
|
end
|
9
10
|
|
10
11
|
describe "the class methods" do
|
11
12
|
|
12
13
|
it "defines accepted_formats" do
|
13
|
-
|
14
|
+
WeatherService::Yahoo.accepted_formats.should == @accepted_formats
|
14
15
|
end
|
15
16
|
|
16
|
-
# it "defines base_uri" do
|
17
|
-
# Barometer::Google.base_uri.should == @base_uri
|
18
|
-
# end
|
19
|
-
|
20
17
|
it "defines get_all" do
|
21
|
-
|
18
|
+
WeatherService::Yahoo.respond_to?("fetch").should be_true
|
22
19
|
end
|
23
20
|
|
24
21
|
end
|
@@ -26,17 +23,17 @@ describe "Yahoo" do
|
|
26
23
|
describe "building the current data" do
|
27
24
|
|
28
25
|
it "defines the build method" do
|
29
|
-
|
26
|
+
WeatherService::Yahoo.respond_to?("build_current").should be_true
|
30
27
|
end
|
31
28
|
|
32
29
|
it "requires Hash input" do
|
33
|
-
lambda {
|
34
|
-
lambda {
|
30
|
+
lambda { WeatherService::Yahoo.build_current }.should raise_error(ArgumentError)
|
31
|
+
lambda { WeatherService::Yahoo.build_current({}) }.should_not raise_error(ArgumentError)
|
35
32
|
end
|
36
33
|
|
37
34
|
it "returns Barometer::CurrentMeasurement object" do
|
38
|
-
current =
|
39
|
-
current.is_a?(
|
35
|
+
current = WeatherService::Yahoo.build_current({})
|
36
|
+
current.is_a?(Data::CurrentMeasurement).should be_true
|
40
37
|
end
|
41
38
|
|
42
39
|
end
|
@@ -44,16 +41,16 @@ describe "Yahoo" do
|
|
44
41
|
describe "building the forecast data" do
|
45
42
|
|
46
43
|
it "defines the build method" do
|
47
|
-
|
44
|
+
WeatherService::Yahoo.respond_to?("build_forecast").should be_true
|
48
45
|
end
|
49
46
|
|
50
47
|
it "requires Hash input" do
|
51
|
-
lambda {
|
52
|
-
lambda {
|
48
|
+
lambda { WeatherService::Yahoo.build_forecast }.should raise_error(ArgumentError)
|
49
|
+
lambda { WeatherService::Yahoo.build_forecast({}) }.should_not raise_error(ArgumentError)
|
53
50
|
end
|
54
51
|
|
55
52
|
it "returns Array object" do
|
56
|
-
current =
|
53
|
+
current = WeatherService::Yahoo.build_forecast({})
|
57
54
|
current.is_a?(Array).should be_true
|
58
55
|
end
|
59
56
|
|
@@ -62,52 +59,38 @@ describe "Yahoo" do
|
|
62
59
|
describe "building the location data" do
|
63
60
|
|
64
61
|
it "defines the build method" do
|
65
|
-
|
62
|
+
WeatherService::Yahoo.respond_to?("build_location").should be_true
|
66
63
|
end
|
67
64
|
|
68
65
|
it "requires Hash input" do
|
69
|
-
lambda {
|
70
|
-
lambda {
|
66
|
+
lambda { WeatherService::Yahoo.build_location }.should raise_error(ArgumentError)
|
67
|
+
lambda { WeatherService::Yahoo.build_location({}) }.should_not raise_error(ArgumentError)
|
71
68
|
end
|
72
69
|
|
73
70
|
it "requires Barometer::Geo input" do
|
74
|
-
geo =
|
75
|
-
lambda {
|
76
|
-
lambda {
|
71
|
+
geo = Data::Geo.new({})
|
72
|
+
lambda { WeatherService::Yahoo.build_location({}, {}) }.should raise_error(ArgumentError)
|
73
|
+
lambda { WeatherService::Yahoo.build_location({}, geo) }.should_not raise_error(ArgumentError)
|
77
74
|
end
|
78
75
|
|
79
76
|
it "returns Barometer::Location object" do
|
80
|
-
location =
|
81
|
-
location.is_a?(
|
77
|
+
location = WeatherService::Yahoo.build_location({})
|
78
|
+
location.is_a?(Data::Location).should be_true
|
82
79
|
end
|
83
80
|
|
84
81
|
end
|
85
82
|
|
86
|
-
# describe "building the timezone" do
|
87
|
-
#
|
88
|
-
# it "defines the build method" do
|
89
|
-
# Barometer::Yahoo.respond_to?("build_timezone").should be_true
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# it "requires Hash input" do
|
93
|
-
# lambda { Barometer::Yahoo.build_timezone }.should raise_error(ArgumentError)
|
94
|
-
# lambda { Barometer::Yahoo.build_timezone({}) }.should_not raise_error(ArgumentError)
|
95
|
-
# end
|
96
|
-
#
|
97
|
-
# end
|
98
|
-
|
99
83
|
describe "when measuring" do
|
100
84
|
|
101
85
|
before(:each) do
|
102
86
|
@query = Barometer::Query.new("90210")
|
103
|
-
@
|
104
|
-
@measurement = Barometer::Measurement.new
|
87
|
+
@measurement = Data::Measurement.new
|
105
88
|
|
106
89
|
FakeWeb.register_uri(:get,
|
107
|
-
"http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.
|
108
|
-
:string => File.read(File.join(File.dirname(__FILE__),
|
109
|
-
'fixtures',
|
110
|
-
'
|
90
|
+
"http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.q)}",
|
91
|
+
:string => File.read(File.join(File.dirname(__FILE__),
|
92
|
+
'../fixtures/services/yahoo',
|
93
|
+
'90210.xml')
|
111
94
|
)
|
112
95
|
)
|
113
96
|
end
|
@@ -115,27 +98,27 @@ describe "Yahoo" do
|
|
115
98
|
describe "all" do
|
116
99
|
|
117
100
|
it "responds to _measure" do
|
118
|
-
|
101
|
+
WeatherService::Yahoo.respond_to?("_measure").should be_true
|
119
102
|
end
|
120
103
|
|
121
104
|
it "requires a Barometer::Measurement object" do
|
122
|
-
lambda {
|
123
|
-
lambda {
|
124
|
-
|
125
|
-
lambda {
|
105
|
+
lambda { WeatherService::Yahoo._measure(nil, @query) }.should raise_error(ArgumentError)
|
106
|
+
lambda { WeatherService::Yahoo._measure("invlaid", @query) }.should raise_error(ArgumentError)
|
107
|
+
|
108
|
+
lambda { WeatherService::Yahoo._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
|
126
109
|
end
|
127
110
|
|
128
111
|
it "requires a Barometer::Query query" do
|
129
|
-
lambda {
|
130
|
-
lambda {
|
112
|
+
lambda { WeatherService::Yahoo._measure }.should raise_error(ArgumentError)
|
113
|
+
lambda { WeatherService::Yahoo._measure(@measurement, 1) }.should raise_error(ArgumentError)
|
131
114
|
|
132
|
-
lambda {
|
115
|
+
lambda { WeatherService::Yahoo._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
|
133
116
|
end
|
134
117
|
|
135
118
|
it "returns a Barometer::Measurement object" do
|
136
|
-
result =
|
137
|
-
result.is_a?(
|
138
|
-
result.current.is_a?(
|
119
|
+
result = WeatherService::Yahoo._measure(@measurement, @query)
|
120
|
+
result.is_a?(Data::Measurement).should be_true
|
121
|
+
result.current.is_a?(Data::CurrentMeasurement).should be_true
|
139
122
|
result.forecast.is_a?(Array).should be_true
|
140
123
|
|
141
124
|
result.source.should == :yahoo
|
@@ -148,25 +131,25 @@ describe "Yahoo" do
|
|
148
131
|
describe "when answering the simple questions," do
|
149
132
|
|
150
133
|
before(:each) do
|
151
|
-
@measurement =
|
134
|
+
@measurement = Data::Measurement.new
|
152
135
|
end
|
153
136
|
|
154
137
|
describe "currently_wet_by_icon?" do
|
155
138
|
|
156
139
|
before(:each) do
|
157
|
-
@measurement.current =
|
140
|
+
@measurement.current = Data::CurrentMeasurement.new
|
158
141
|
end
|
159
142
|
|
160
143
|
it "returns true if matching icon code" do
|
161
144
|
@measurement.current.icon = "4"
|
162
145
|
@measurement.current.icon?.should be_true
|
163
|
-
|
146
|
+
WeatherService::Yahoo.currently_wet_by_icon?(@measurement.current).should be_true
|
164
147
|
end
|
165
148
|
|
166
149
|
it "returns false if NO matching icon code" do
|
167
150
|
@measurement.current.icon = "32"
|
168
151
|
@measurement.current.icon?.should be_true
|
169
|
-
|
152
|
+
WeatherService::Yahoo.currently_wet_by_icon?(@measurement.current).should be_false
|
170
153
|
end
|
171
154
|
|
172
155
|
end
|
@@ -174,7 +157,7 @@ describe "Yahoo" do
|
|
174
157
|
describe "forecasted_wet_by_icon?" do
|
175
158
|
|
176
159
|
before(:each) do
|
177
|
-
@measurement.forecast = [
|
160
|
+
@measurement.forecast = [Data::ForecastMeasurement.new]
|
178
161
|
@measurement.forecast.first.date = Date.today
|
179
162
|
@measurement.forecast.size.should == 1
|
180
163
|
end
|
@@ -182,13 +165,13 @@ describe "Yahoo" do
|
|
182
165
|
it "returns true if matching icon code" do
|
183
166
|
@measurement.forecast.first.icon = "4"
|
184
167
|
@measurement.forecast.first.icon?.should be_true
|
185
|
-
|
168
|
+
WeatherService::Yahoo.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
|
186
169
|
end
|
187
170
|
|
188
171
|
it "returns false if NO matching icon code" do
|
189
172
|
@measurement.forecast.first.icon = "32"
|
190
173
|
@measurement.forecast.first.icon?.should be_true
|
191
|
-
|
174
|
+
WeatherService::Yahoo.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
|
192
175
|
end
|
193
176
|
|
194
177
|
end
|
@@ -196,19 +179,19 @@ describe "Yahoo" do
|
|
196
179
|
describe "currently_sunny_by_icon?" do
|
197
180
|
|
198
181
|
before(:each) do
|
199
|
-
@measurement.current =
|
182
|
+
@measurement.current = Data::CurrentMeasurement.new
|
200
183
|
end
|
201
184
|
|
202
185
|
it "returns true if matching icon code" do
|
203
186
|
@measurement.current.icon = "32"
|
204
187
|
@measurement.current.icon?.should be_true
|
205
|
-
|
188
|
+
WeatherService::Yahoo.currently_sunny_by_icon?(@measurement.current).should be_true
|
206
189
|
end
|
207
190
|
|
208
191
|
it "returns false if NO matching icon code" do
|
209
192
|
@measurement.current.icon = "4"
|
210
193
|
@measurement.current.icon?.should be_true
|
211
|
-
|
194
|
+
WeatherService::Yahoo.currently_sunny_by_icon?(@measurement.current).should be_false
|
212
195
|
end
|
213
196
|
|
214
197
|
end
|
@@ -216,7 +199,7 @@ describe "Yahoo" do
|
|
216
199
|
describe "forecasted_sunny_by_icon?" do
|
217
200
|
|
218
201
|
before(:each) do
|
219
|
-
@measurement.forecast = [
|
202
|
+
@measurement.forecast = [Data::ForecastMeasurement.new]
|
220
203
|
@measurement.forecast.first.date = Date.today
|
221
204
|
@measurement.forecast.size.should == 1
|
222
205
|
end
|
@@ -224,13 +207,13 @@ describe "Yahoo" do
|
|
224
207
|
it "returns true if matching icon code" do
|
225
208
|
@measurement.forecast.first.icon = "32"
|
226
209
|
@measurement.forecast.first.icon?.should be_true
|
227
|
-
|
210
|
+
WeatherService::Yahoo.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
|
228
211
|
end
|
229
212
|
|
230
213
|
it "returns false if NO matching icon code" do
|
231
214
|
@measurement.forecast.first.icon = "4"
|
232
215
|
@measurement.forecast.first.icon?.should be_true
|
233
|
-
|
216
|
+
WeatherService::Yahoo.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
|
234
217
|
end
|
235
218
|
|
236
219
|
end
|
@@ -241,28 +224,29 @@ describe "Yahoo" do
|
|
241
224
|
|
242
225
|
before(:each) do
|
243
226
|
@query = Barometer::Query.new("90210")
|
244
|
-
@
|
245
|
-
@measurement = Barometer::Measurement.new
|
227
|
+
@measurement = Data::Measurement.new
|
246
228
|
|
247
229
|
FakeWeb.register_uri(:get,
|
248
|
-
"http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.
|
230
|
+
"http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.q)}",
|
249
231
|
:string => File.read(File.join(File.dirname(__FILE__),
|
250
|
-
'fixtures',
|
251
|
-
'
|
232
|
+
'../fixtures/services/yahoo',
|
233
|
+
'90210.xml')
|
252
234
|
)
|
253
235
|
)
|
254
236
|
end
|
255
237
|
|
256
238
|
# TODO: complete this
|
257
239
|
it "should correctly build the data" do
|
258
|
-
result =
|
240
|
+
result = WeatherService::Yahoo._measure(@measurement, @query)
|
259
241
|
|
260
|
-
sun_rise = Barometer::Zone.merge("6:09 am", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
|
261
|
-
sun_set = Barometer::Zone.merge("7:34 pm", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
|
242
|
+
#sun_rise = Barometer::Zone.merge("6:09 am", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
|
243
|
+
#sun_set = Barometer::Zone.merge("7:34 pm", "Sun, 26 Apr 2009 10:51 am PDT", "PDT")
|
262
244
|
|
263
245
|
# build current
|
264
|
-
|
265
|
-
|
246
|
+
#@measurement.current.sun.rise.should == sun_rise
|
247
|
+
#@measurement.current.sun.set.should == sun_set
|
248
|
+
@measurement.current.sun.rise.to_s.should == "06:09 am"
|
249
|
+
@measurement.current.sun.set.to_s.should == "07:34 pm"
|
266
250
|
|
267
251
|
# builds location
|
268
252
|
@measurement.location.city.should == "Beverly Hills"
|
@@ -272,13 +256,13 @@ describe "Yahoo" do
|
|
272
256
|
|
273
257
|
@measurement.forecast[0].condition.should == "Mostly Sunny"
|
274
258
|
@measurement.forecast[0].icon.should == "34"
|
275
|
-
@measurement.forecast[0].sun.rise.should
|
276
|
-
@measurement.forecast[0].sun.set.should ==
|
259
|
+
@measurement.forecast[0].sun.rise.should == "06:09 am"
|
260
|
+
@measurement.forecast[0].sun.set.should == "07:34 pm"
|
277
261
|
|
278
262
|
@measurement.forecast[1].condition.should == "Cloudy"
|
279
263
|
@measurement.forecast[1].icon.should == "26"
|
280
|
-
@measurement.forecast[1].sun.rise.should ==
|
281
|
-
@measurement.forecast[1].sun.set.should ==
|
264
|
+
@measurement.forecast[1].sun.rise.should == "06:09 am"
|
265
|
+
@measurement.forecast[1].sun.set.should == "07:34 pm"
|
282
266
|
|
283
267
|
end
|
284
268
|
# <yweather:location city="Beverly Hills" region="CA" country="US"/>
|
data/spec/weather_spec.rb
CHANGED
@@ -38,16 +38,16 @@ describe "Weather" do
|
|
38
38
|
|
39
39
|
before(:each) do
|
40
40
|
module Barometer
|
41
|
-
class Measurement
|
41
|
+
class Data::Measurement
|
42
42
|
attr_accessor :success
|
43
43
|
end
|
44
44
|
end
|
45
45
|
@weather = Barometer::Weather.new
|
46
|
-
@wunderground =
|
46
|
+
@wunderground = Data::Measurement.new(:wunderground)
|
47
47
|
@wunderground.success = true
|
48
|
-
@yahoo =
|
48
|
+
@yahoo = Data::Measurement.new(:yahoo)
|
49
49
|
@yahoo.success = true
|
50
|
-
@google =
|
50
|
+
@google = Data::Measurement.new(:google)
|
51
51
|
@weather.measurements << @wunderground
|
52
52
|
@weather.measurements << @yahoo
|
53
53
|
@weather.measurements << @google
|
@@ -82,36 +82,47 @@ describe "Weather" do
|
|
82
82
|
|
83
83
|
before(:each) do
|
84
84
|
@weather = Barometer::Weather.new
|
85
|
-
@wunderground =
|
86
|
-
@wunderground.current =
|
85
|
+
@wunderground = Data::Measurement.new(:wunderground)
|
86
|
+
@wunderground.current = Data::CurrentMeasurement.new
|
87
87
|
@wunderground.success = true
|
88
|
-
@yahoo =
|
89
|
-
@yahoo.current =
|
88
|
+
@yahoo = Data::Measurement.new(:yahoo)
|
89
|
+
@yahoo.current = Data::CurrentMeasurement.new
|
90
90
|
@yahoo.success = true
|
91
|
-
@google =
|
91
|
+
@google = Data::Measurement.new(:google)
|
92
92
|
@weather.measurements << @wunderground
|
93
93
|
@weather.measurements << @yahoo
|
94
94
|
@weather.measurements << @google
|
95
95
|
end
|
96
96
|
|
97
97
|
it "doesn't include nil values" do
|
98
|
-
@weather.source(:wunderground).current.temperature =
|
98
|
+
@weather.source(:wunderground).current.temperature = Data::Temperature.new
|
99
99
|
@weather.source(:wunderground).current.temperature.c = 10
|
100
100
|
|
101
101
|
@weather.temperature.c.should == 10
|
102
102
|
|
103
|
-
@weather.source(:yahoo).current.temperature =
|
103
|
+
@weather.source(:yahoo).current.temperature = Data::Temperature.new
|
104
104
|
@weather.source(:yahoo).current.temperature.c = nil
|
105
105
|
|
106
106
|
@weather.temperature.c.should == 10
|
107
107
|
end
|
108
108
|
|
109
|
+
it "respects the measurement weight" do
|
110
|
+
@weather.source(:wunderground).current.temperature = Data::Temperature.new
|
111
|
+
@weather.source(:wunderground).current.temperature.c = 10
|
112
|
+
@weather.source(:yahoo).current.temperature = Data::Temperature.new
|
113
|
+
@weather.source(:yahoo).current.temperature.c = 4
|
114
|
+
|
115
|
+
@weather.measurements.first.weight = 2
|
116
|
+
|
117
|
+
@weather.temperature.c.should == 8
|
118
|
+
end
|
119
|
+
|
109
120
|
describe "for temperature" do
|
110
121
|
|
111
122
|
before(:each) do
|
112
|
-
@weather.source(:wunderground).current.temperature =
|
123
|
+
@weather.source(:wunderground).current.temperature = Data::Temperature.new
|
113
124
|
@weather.source(:wunderground).current.temperature.c = 10
|
114
|
-
@weather.source(:yahoo).current.temperature =
|
125
|
+
@weather.source(:yahoo).current.temperature = Data::Temperature.new
|
115
126
|
@weather.source(:yahoo).current.temperature.c = 6
|
116
127
|
end
|
117
128
|
|
@@ -128,9 +139,9 @@ describe "Weather" do
|
|
128
139
|
describe "for wind" do
|
129
140
|
|
130
141
|
before(:each) do
|
131
|
-
@weather.source(:wunderground).current.wind =
|
142
|
+
@weather.source(:wunderground).current.wind = Data::Speed.new
|
132
143
|
@weather.source(:wunderground).current.wind.kph = 10
|
133
|
-
@weather.source(:yahoo).current.wind =
|
144
|
+
@weather.source(:yahoo).current.wind = Data::Speed.new
|
134
145
|
@weather.source(:yahoo).current.wind.kph = 6
|
135
146
|
end
|
136
147
|
|
@@ -164,9 +175,9 @@ describe "Weather" do
|
|
164
175
|
describe "for pressure" do
|
165
176
|
|
166
177
|
before(:each) do
|
167
|
-
@weather.source(:wunderground).current.pressure =
|
178
|
+
@weather.source(:wunderground).current.pressure = Data::Pressure.new
|
168
179
|
@weather.source(:wunderground).current.pressure.mb = 10
|
169
|
-
@weather.source(:yahoo).current.pressure =
|
180
|
+
@weather.source(:yahoo).current.pressure = Data::Pressure.new
|
170
181
|
@weather.source(:yahoo).current.pressure.mb = 6
|
171
182
|
end
|
172
183
|
|
@@ -183,9 +194,9 @@ describe "Weather" do
|
|
183
194
|
describe "for dew_point" do
|
184
195
|
|
185
196
|
before(:each) do
|
186
|
-
@weather.source(:wunderground).current.dew_point =
|
197
|
+
@weather.source(:wunderground).current.dew_point = Data::Temperature.new
|
187
198
|
@weather.source(:wunderground).current.dew_point.c = 10
|
188
|
-
@weather.source(:yahoo).current.dew_point =
|
199
|
+
@weather.source(:yahoo).current.dew_point = Data::Temperature.new
|
189
200
|
@weather.source(:yahoo).current.dew_point.c = 6
|
190
201
|
end
|
191
202
|
|
@@ -202,9 +213,9 @@ describe "Weather" do
|
|
202
213
|
describe "for heat_index" do
|
203
214
|
|
204
215
|
before(:each) do
|
205
|
-
@weather.source(:wunderground).current.heat_index =
|
216
|
+
@weather.source(:wunderground).current.heat_index = Data::Temperature.new
|
206
217
|
@weather.source(:wunderground).current.heat_index.c = 10
|
207
|
-
@weather.source(:yahoo).current.heat_index =
|
218
|
+
@weather.source(:yahoo).current.heat_index = Data::Temperature.new
|
208
219
|
@weather.source(:yahoo).current.heat_index.c = 6
|
209
220
|
end
|
210
221
|
|
@@ -221,9 +232,9 @@ describe "Weather" do
|
|
221
232
|
describe "for wind_chill" do
|
222
233
|
|
223
234
|
before(:each) do
|
224
|
-
@weather.source(:wunderground).current.wind_chill =
|
235
|
+
@weather.source(:wunderground).current.wind_chill = Data::Temperature.new
|
225
236
|
@weather.source(:wunderground).current.wind_chill.c = 10
|
226
|
-
@weather.source(:yahoo).current.wind_chill =
|
237
|
+
@weather.source(:yahoo).current.wind_chill = Data::Temperature.new
|
227
238
|
@weather.source(:yahoo).current.wind_chill.c = 6
|
228
239
|
end
|
229
240
|
|
@@ -240,9 +251,9 @@ describe "Weather" do
|
|
240
251
|
describe "for visibility" do
|
241
252
|
|
242
253
|
before(:each) do
|
243
|
-
@weather.source(:wunderground).current.visibility =
|
254
|
+
@weather.source(:wunderground).current.visibility = Data::Distance.new
|
244
255
|
@weather.source(:wunderground).current.visibility.km = 10
|
245
|
-
@weather.source(:yahoo).current.visibility =
|
256
|
+
@weather.source(:yahoo).current.visibility = Data::Distance.new
|
246
257
|
@weather.source(:yahoo).current.visibility.km = 6
|
247
258
|
end
|
248
259
|
|
@@ -262,6 +273,7 @@ describe "Weather" do
|
|
262
273
|
|
263
274
|
before(:each) do
|
264
275
|
@weather = Barometer::Weather.new
|
276
|
+
@now = Data::LocalDateTime.parse("2:05 pm")
|
265
277
|
end
|
266
278
|
|
267
279
|
describe "windy?" do
|
@@ -272,9 +284,9 @@ describe "Weather" do
|
|
272
284
|
lambda { @weather.windy?(1.1) }.should_not raise_error(ArgumentError)
|
273
285
|
end
|
274
286
|
|
275
|
-
it "requires time as a
|
276
|
-
lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
|
277
|
-
lambda { @weather.windy?(1
|
287
|
+
it "requires time as a Data::LocalTime object" do
|
288
|
+
#lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
|
289
|
+
lambda { @weather.windy?(1,@now) }.should_not raise_error(ArgumentError)
|
278
290
|
end
|
279
291
|
|
280
292
|
it "returns nil when no measurements" do
|
@@ -283,20 +295,20 @@ describe "Weather" do
|
|
283
295
|
end
|
284
296
|
|
285
297
|
it "returns true if a measurement returns true" do
|
286
|
-
wunderground =
|
298
|
+
wunderground = Data::Measurement.new(:wunderground)
|
287
299
|
wunderground.success = true
|
288
300
|
@weather.measurements << wunderground
|
289
|
-
module Barometer; class Measurement
|
301
|
+
module Barometer; class Data::Measurement
|
290
302
|
def windy?(a=nil,b=nil); true; end
|
291
303
|
end; end
|
292
304
|
@weather.windy?.should be_true
|
293
305
|
end
|
294
306
|
|
295
307
|
it "returns false if a measurement returns false" do
|
296
|
-
wunderground =
|
308
|
+
wunderground = Data::Measurement.new(:wunderground)
|
297
309
|
wunderground.success = true
|
298
310
|
@weather.measurements << wunderground
|
299
|
-
module Barometer; class Measurement
|
311
|
+
module Barometer; class Data::Measurement
|
300
312
|
def windy?(a=nil,b=nil); false; end
|
301
313
|
end; end
|
302
314
|
@weather.windy?.should be_false
|
@@ -312,9 +324,9 @@ describe "Weather" do
|
|
312
324
|
lambda { @weather.wet?(1.1) }.should_not raise_error(ArgumentError)
|
313
325
|
end
|
314
326
|
|
315
|
-
it "requires time as a
|
316
|
-
lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
|
317
|
-
lambda { @weather.wet?(1
|
327
|
+
it "requires time as a Data::LocalTime object" do
|
328
|
+
#lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
|
329
|
+
lambda { @weather.wet?(1,@now) }.should_not raise_error(ArgumentError)
|
318
330
|
end
|
319
331
|
|
320
332
|
it "returns nil when no measurements" do
|
@@ -323,20 +335,20 @@ describe "Weather" do
|
|
323
335
|
end
|
324
336
|
|
325
337
|
it "returns true if a measurement returns true" do
|
326
|
-
wunderground =
|
338
|
+
wunderground = Data::Measurement.new(:wunderground)
|
327
339
|
wunderground.success = true
|
328
340
|
@weather.measurements << wunderground
|
329
|
-
module Barometer; class Measurement
|
341
|
+
module Barometer; class Data::Measurement
|
330
342
|
def wet?(a=nil,b=nil); true; end
|
331
343
|
end; end
|
332
344
|
@weather.wet?.should be_true
|
333
345
|
end
|
334
346
|
|
335
347
|
it "returns false if a measurement returns false" do
|
336
|
-
wunderground =
|
348
|
+
wunderground = Data::Measurement.new(:wunderground)
|
337
349
|
wunderground.success = true
|
338
350
|
@weather.measurements << wunderground
|
339
|
-
module Barometer; class Measurement
|
351
|
+
module Barometer; class Data::Measurement
|
340
352
|
def wet?(a=nil,b=nil); false; end
|
341
353
|
end; end
|
342
354
|
@weather.wet?.should be_false
|
@@ -346,14 +358,14 @@ describe "Weather" do
|
|
346
358
|
|
347
359
|
describe "day? and night?" do
|
348
360
|
|
349
|
-
it "requires time as a
|
350
|
-
lambda { @weather.day?("a") }.should raise_error(ArgumentError)
|
351
|
-
lambda { @weather.day?(
|
361
|
+
it "requires time as a Data::LocalTime object" do
|
362
|
+
#lambda { @weather.day?("a") }.should raise_error(ArgumentError)
|
363
|
+
lambda { @weather.day?(@now) }.should_not raise_error(ArgumentError)
|
352
364
|
end
|
353
365
|
|
354
|
-
it "requires time as a
|
355
|
-
lambda { @weather.night?("a") }.should raise_error(ArgumentError)
|
356
|
-
lambda { @weather.night?(
|
366
|
+
it "requires time as a Data::LocalTime object" do
|
367
|
+
#lambda { @weather.night?("a") }.should raise_error(ArgumentError)
|
368
|
+
lambda { @weather.night?(@now) }.should_not raise_error(ArgumentError)
|
357
369
|
end
|
358
370
|
|
359
371
|
it "returns nil when no measurements" do
|
@@ -363,10 +375,10 @@ describe "Weather" do
|
|
363
375
|
end
|
364
376
|
|
365
377
|
it "returns true if a measurement returns true (night is opposite)" do
|
366
|
-
wunderground =
|
378
|
+
wunderground = Data::Measurement.new(:wunderground)
|
367
379
|
wunderground.success = true
|
368
380
|
@weather.measurements << wunderground
|
369
|
-
module Barometer; class Measurement
|
381
|
+
module Barometer; class Data::Measurement
|
370
382
|
def day?(a=nil); true; end
|
371
383
|
end; end
|
372
384
|
@weather.day?.should be_true
|
@@ -374,10 +386,10 @@ describe "Weather" do
|
|
374
386
|
end
|
375
387
|
|
376
388
|
it "returns false if a measurement returns false (night is opposite)" do
|
377
|
-
wunderground =
|
389
|
+
wunderground = Data::Measurement.new(:wunderground)
|
378
390
|
wunderground.success = true
|
379
391
|
@weather.measurements << wunderground
|
380
|
-
module Barometer; class Measurement
|
392
|
+
module Barometer; class Data::Measurement
|
381
393
|
def day?(a=nil); false; end
|
382
394
|
end; end
|
383
395
|
@weather.day?.should be_false
|
@@ -388,9 +400,9 @@ describe "Weather" do
|
|
388
400
|
|
389
401
|
describe "sunny?" do
|
390
402
|
|
391
|
-
it "requires time as a
|
392
|
-
lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
|
393
|
-
lambda { @weather.sunny?(
|
403
|
+
it "requires time as a Data::LocalTime object" do
|
404
|
+
#lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
|
405
|
+
lambda { @weather.sunny?(@now) }.should_not raise_error(ArgumentError)
|
394
406
|
end
|
395
407
|
|
396
408
|
it "returns nil when no measurements" do
|
@@ -399,40 +411,40 @@ describe "Weather" do
|
|
399
411
|
end
|
400
412
|
|
401
413
|
it "returns true if a measurement returns true" do
|
402
|
-
wunderground =
|
414
|
+
wunderground = Data::Measurement.new(:wunderground)
|
403
415
|
wunderground.success = true
|
404
416
|
@weather.measurements << wunderground
|
405
|
-
module Barometer; class Measurement
|
417
|
+
module Barometer; class Data::Measurement
|
406
418
|
def day?(a=nil); true; end
|
407
419
|
end; end
|
408
|
-
module Barometer; class Measurement
|
420
|
+
module Barometer; class Data::Measurement
|
409
421
|
def sunny?(a=nil,b=nil); true; end
|
410
422
|
end; end
|
411
423
|
@weather.sunny?.should be_true
|
412
424
|
end
|
413
425
|
|
414
426
|
it "returns false if a measurement returns false" do
|
415
|
-
wunderground =
|
427
|
+
wunderground = Data::Measurement.new(:wunderground)
|
416
428
|
wunderground.success = true
|
417
429
|
@weather.measurements << wunderground
|
418
|
-
module Barometer; class Measurement
|
430
|
+
module Barometer; class Data::Measurement
|
419
431
|
def day?(a=nil); true; end
|
420
432
|
end; end
|
421
|
-
module Barometer; class Measurement
|
433
|
+
module Barometer; class Data::Measurement
|
422
434
|
def sunny?(a=nil,b=nil); false; end
|
423
435
|
end; end
|
424
436
|
@weather.sunny?.should be_false
|
425
437
|
end
|
426
438
|
|
427
439
|
it "returns false if night time" do
|
428
|
-
wunderground =
|
440
|
+
wunderground = Data::Measurement.new(:wunderground)
|
429
441
|
wunderground.success = true
|
430
442
|
@weather.measurements << wunderground
|
431
|
-
module Barometer; class Measurement
|
443
|
+
module Barometer; class Data::Measurement
|
432
444
|
def sunny?(a=nil,b=nil); true; end
|
433
445
|
end; end
|
434
446
|
@weather.sunny?.should be_true
|
435
|
-
module Barometer; class Measurement
|
447
|
+
module Barometer; class Data::Measurement
|
436
448
|
def day?(a=nil); false; end
|
437
449
|
end; end
|
438
450
|
@weather.sunny?.should be_false
|