barometer 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.rdoc +1 -1
  2. data/VERSION.yml +1 -1
  3. data/bin/barometer +4 -12
  4. data/lib/barometer/data.rb +2 -5
  5. data/lib/barometer/data/local_datetime.rb +2 -2
  6. data/lib/barometer/measurements/measurement.rb +6 -6
  7. data/lib/barometer/measurements/result.rb +207 -0
  8. data/lib/barometer/measurements/{forecast_array.rb → result_array.rb} +16 -13
  9. data/lib/barometer/translations/weather_country_codes.yml +3 -3
  10. data/lib/barometer/weather_services/google.rb +3 -3
  11. data/lib/barometer/weather_services/weather_bug.rb +3 -3
  12. data/lib/barometer/weather_services/weather_dot_com.rb +65 -38
  13. data/lib/barometer/weather_services/wunderground.rb +3 -3
  14. data/lib/barometer/weather_services/yahoo.rb +3 -3
  15. data/lib/demometer/demometer.rb +2 -2
  16. data/lib/demometer/public/css/master.css +4 -75
  17. data/lib/demometer/public/css/print.css +1 -2
  18. data/lib/demometer/public/css/syntax.css +1 -2
  19. data/lib/demometer/views/about.erb +1 -1
  20. data/lib/demometer/views/contributing.erb +4 -4
  21. data/lib/demometer/views/index.erb +8 -9
  22. data/lib/demometer/views/layout.erb +1 -2
  23. data/spec/measurements/measurement_spec.rb +29 -53
  24. data/spec/measurements/{forecast_array_spec.rb → result_array_spec.rb} +8 -8
  25. data/spec/measurements/result_spec.rb +660 -0
  26. data/spec/spec_helper.rb +1 -0
  27. data/spec/weather_services/google_spec.rb +4 -4
  28. data/spec/weather_services/services_spec.rb +1 -1
  29. data/spec/weather_services/weather_bug_spec.rb +3 -3
  30. data/spec/weather_services/weather_dot_com_spec.rb +19 -22
  31. data/spec/weather_services/wunderground_spec.rb +2 -2
  32. data/spec/weather_services/yahoo_spec.rb +2 -2
  33. data/spec/weather_spec.rb +14 -39
  34. metadata +6 -12
  35. data/lib/barometer/measurements/common.rb +0 -113
  36. data/lib/barometer/measurements/current.rb +0 -76
  37. data/lib/barometer/measurements/forecast.rb +0 -62
  38. data/lib/barometer/measurements/night.rb +0 -27
  39. data/spec/measurements/common_spec.rb +0 -352
  40. data/spec/measurements/current_spec.rb +0 -186
  41. data/spec/measurements/forecast_spec.rb +0 -135
  42. data/spec/measurements/night_measurement_spec.rb +0 -49
@@ -6,8 +6,7 @@
6
6
  <link rel='stylesheet' href='/css/master.css' type='text/css' media="screen, projection">
7
7
  <link rel='stylesheet' href='/css/syntax.css' type='text/css' media="screen, projection">
8
8
  <link rel='stylesheet' href='/css/print.css' type='text/css' media="print">
9
- <!--><link rel='shortcut icon' href='/images/favicon.ico'>-->
10
- <link rel='alternate' href='http://attack.github.com/feed.xml' type='application/atom+xml' title='Barometers Blog'>
9
+ <link rel='alternate' href='http://attack.github.com/feed.xml' type='application/atom+xml' title='Barometer Feed'>
11
10
 
12
11
  </head>
13
12
  <body id=''>
@@ -99,23 +99,23 @@ describe "Measurement" do
99
99
  lambda { @measurement.utc_time_stamp = valid_data }.should_not raise_error(ArgumentError)
100
100
  end
101
101
 
102
- it "only accepts Data::CurrentMeasurement for current" do
102
+ it "only accepts Measurement::Result for current" do
103
103
  invalid_data = "invalid"
104
- invalid_data.class.should_not == Measurement::Current
104
+ invalid_data.class.should_not == Measurement::Result
105
105
  lambda { @measurement.current = invalid_data }.should raise_error(ArgumentError)
106
106
 
107
- valid_data = Measurement::Current.new
108
- valid_data.class.should == Measurement::Current
107
+ valid_data = Measurement::Result.new
108
+ valid_data.class.should == Measurement::Result
109
109
  lambda { @measurement.current = valid_data }.should_not raise_error(ArgumentError)
110
110
  end
111
111
 
112
- it "only accepts Data::ForecastArray for forecast" do
112
+ it "only accepts Data::ResultArray for forecast" do
113
113
  invalid_data = 1
114
- invalid_data.class.should_not == Measurement::ForecastArray
114
+ invalid_data.class.should_not == Measurement::ResultArray
115
115
  lambda { @measurement.forecast = invalid_data }.should raise_error(ArgumentError)
116
116
 
117
- valid_data = Measurement::ForecastArray.new
118
- valid_data.class.should == Measurement::ForecastArray
117
+ valid_data = Measurement::ResultArray.new
118
+ valid_data.class.should == Measurement::ResultArray
119
119
  lambda { @measurement.forecast = valid_data }.should_not raise_error(ArgumentError)
120
120
  end
121
121
 
@@ -194,7 +194,7 @@ describe "Measurement" do
194
194
  @measurement.current.should be_nil
195
195
  @measurement.success.should be_false
196
196
 
197
- @measurement.current = Measurement::Current.new
197
+ @measurement.current = Measurement::Result.new
198
198
  @measurement.current.temperature = Data::Temperature.new
199
199
  @measurement.current.temperature.c = 10
200
200
  @measurement.utc_time_stamp.should_not be_nil
@@ -203,7 +203,7 @@ describe "Measurement" do
203
203
  end
204
204
 
205
205
  it "returns successful state" do
206
- @measurement.current = Measurement::Current.new
206
+ @measurement.current = Measurement::Result.new
207
207
  @measurement.current.temperature = Data::Temperature.new
208
208
  @measurement.current.temperature.c = 10
209
209
  @measurement.success!
@@ -226,7 +226,7 @@ describe "Measurement" do
226
226
  @measurement.current.should be_nil
227
227
  @measurement.current?.should be_true
228
228
 
229
- @measurement.current = Measurement::Current.new
229
+ @measurement.current = Measurement::Result.new
230
230
  @measurement.current.current_at.should be_nil
231
231
  @measurement.current?.should be_true
232
232
 
@@ -288,11 +288,11 @@ describe "Measurement" do
288
288
  before(:each) do
289
289
  @measurement = Barometer::Measurement.new
290
290
 
291
- # create a measurement object with a forecast array that includes
291
+ # create a measurement object with a result array that includes
292
292
  # dates for 4 consecutive days starting with tommorrow
293
- @measurement.forecast = Measurement::ForecastArray.new
293
+ @measurement.forecast = Measurement::ResultArray.new
294
294
  1.upto(4) do |i|
295
- forecast_measurement = Measurement::Forecast.new
295
+ forecast_measurement = Measurement::Result.new
296
296
  forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
297
297
  @measurement.forecast << forecast_measurement
298
298
  end
@@ -302,7 +302,7 @@ describe "Measurement" do
302
302
  end
303
303
 
304
304
  it "returns nil when there are no forecasts" do
305
- @measurement.forecast = Measurement::ForecastArray.new
305
+ @measurement.forecast = Measurement::ResultArray.new
306
306
  @measurement.forecast.size.should == 0
307
307
  @measurement.for.should be_nil
308
308
  end
@@ -348,7 +348,7 @@ describe "Measurement" do
348
348
 
349
349
  before(:each) do
350
350
  @measurement = Barometer::Measurement.new(:wunderground)
351
- @measurement.current = Measurement::Current.new
351
+ @measurement.current = Measurement::Result.new
352
352
  @now = Data::LocalDateTime.parse("2009-05-01 2:05 pm")
353
353
  end
354
354
 
@@ -366,16 +366,12 @@ describe "Measurement" do
366
366
  describe "windy?" do
367
367
 
368
368
  it "returns true if a current_measurement returns true" do
369
- module Barometer; class Measurement::Current < Measurement::Common
370
- def windy?(a=nil); true; end
371
- end; end
369
+ @measurement.current.stubs(:windy?).returns(true)
372
370
  @measurement.windy?.should be_true
373
371
  end
374
-
372
+
375
373
  it "returns false if a current_measurement returns false" do
376
- module Barometer; class Measurement::Current < Measurement::Common
377
- def windy?(a=nil); false; end
378
- end; end
374
+ @measurement.current.stubs(:windy?).returns(false)
379
375
  @measurement.windy?.should be_false
380
376
  end
381
377
 
@@ -384,16 +380,12 @@ describe "Measurement" do
384
380
  describe "wet?" do
385
381
 
386
382
  it "returns true if the current_measurement returns true" do
387
- module Barometer; class Measurement::Current < Measurement::Common
388
- def wet?(a=nil,b=nil,c=nil); true; end
389
- end; end
383
+ @measurement.current.stubs(:wet?).returns(true)
390
384
  @measurement.wet?.should be_true
391
385
  end
392
386
 
393
387
  it "returns false if the current_measurement returns false" do
394
- module Barometer; class Measurement::Current < Measurement::Common
395
- def wet?(a=nil,b=nil,c=nil); false; end
396
- end; end
388
+ @measurement.current.stubs(:wet?).returns(false)
397
389
  @measurement.wet?.should be_false
398
390
  end
399
391
 
@@ -402,16 +394,12 @@ describe "Measurement" do
402
394
  describe "day?" do
403
395
 
404
396
  it "returns true if the current_measurement returns true" do
405
- module Barometer; class Measurement::Current < Measurement::Common
406
- def day?(a=nil); true; end
407
- end; end
397
+ @measurement.current.stubs(:day?).returns(true)
408
398
  @measurement.day?.should be_true
409
399
  end
410
400
 
411
401
  it "returns false if the current_measurement returns false" do
412
- module Barometer; class Measurement::Current < Measurement::Common
413
- def day?(a=nil); false; end
414
- end; end
402
+ @measurement.current.stubs(:day?).returns(false)
415
403
  @measurement.day?.should be_false
416
404
  end
417
405
 
@@ -420,34 +408,22 @@ describe "Measurement" do
420
408
  describe "sunny?" do
421
409
 
422
410
  it "returns true if the current_measurement returns true and day" do
423
- module Barometer; class Measurement::Current < Measurement::Common
424
- def day?(a=nil); true; end
425
- end; end
426
- module Barometer; class Measurement::Current < Measurement::Common
427
- def sunny?(a=nil,b=nil); true; end
428
- end; end
411
+ @measurement.current.stubs(:day?).returns(true)
412
+ @measurement.current.stubs(:sunny?).returns(true)
429
413
  @measurement.day?.should be_true
430
414
  @measurement.sunny?.should be_true
431
415
  end
432
416
 
433
417
  it "returns false if the current_measurement returns false and day" do
434
- module Barometer; class Measurement::Current < Measurement::Common
435
- def day?(a=nil); true; end
436
- end; end
437
- module Barometer; class Measurement::Current < Measurement::Common
438
- def sunny?(a=nil,b=nil); false; end
439
- end; end
418
+ @measurement.current.stubs(:day?).returns(true)
419
+ @measurement.current.stubs(:sunny?).returns(false)
440
420
  @measurement.day?.should be_true
441
421
  @measurement.sunny?.should be_false
442
422
  end
443
423
 
444
424
  it "returns false if night time" do
445
- module Barometer; class Measurement::Current < Measurement::Common
446
- def day?(a=nil); false; end
447
- end; end
448
- module Barometer; class Measurement::Current < Measurement::Common
449
- def sunny?(a=nil,b=nil); true; end
450
- end; end
425
+ @measurement.current.stubs(:day?).returns(false)
426
+ @measurement.current.stubs(:sunny?).returns(true)
451
427
  @measurement.day?.should be_false
452
428
  @measurement.sunny?.should be_false
453
429
  end
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Forecast Array" do
3
+ describe "Result Array" do
4
4
 
5
5
  describe "instance methods" do
6
6
 
7
7
  before(:each) do
8
- @array = Measurement::ForecastArray.new
8
+ @array = Measurement::ResultArray.new
9
9
  end
10
10
 
11
11
  describe "'<<'" do
12
12
 
13
- it "requires ForecastMeasurement" do
13
+ it "requires Measurement::Result" do
14
14
  lambda { @array << "invalid" }.should raise_error(ArgumentError)
15
15
  end
16
16
 
17
17
  it "adds ForecastMeasurement" do
18
18
  @array.size.should == 0
19
- forecast = Measurement::Forecast.new
19
+ forecast = Measurement::Result.new
20
20
  @array << forecast
21
21
  @array.size.should == 1
22
22
  end
@@ -27,7 +27,7 @@ describe "Forecast Array" do
27
27
 
28
28
  before(:each) do
29
29
  1.upto(4) do |i|
30
- forecast_measurement = Measurement::Forecast.new
30
+ forecast_measurement = Measurement::Result.new
31
31
  forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
32
32
  @array << forecast_measurement
33
33
  end
@@ -37,7 +37,7 @@ describe "Forecast Array" do
37
37
  end
38
38
 
39
39
  it "returns nil when there are no forecasts" do
40
- @array = Measurement::ForecastArray.new
40
+ @array = Measurement::ResultArray.new
41
41
  @array.size.should == 0
42
42
  @array.for(@tommorrow).should be_nil
43
43
  end
@@ -90,7 +90,7 @@ describe "Forecast Array" do
90
90
  describe "simple questions" do
91
91
 
92
92
  before(:each) do
93
- @array = Measurement::ForecastArray.new
93
+ @array = Measurement::ResultArray.new
94
94
  #@early = Data::LocalTime("6:00 am")
95
95
  #@noon = Data::LocalTime("12:00 pm")
96
96
  #@late = Data::LocalTime("8:00 pm")
@@ -99,7 +99,7 @@ describe "Forecast Array" do
99
99
  @sun_icons = %w(sunny)
100
100
 
101
101
  0.upto(1) do |i|
102
- forecast_measurement = Measurement::Forecast.new
102
+ forecast_measurement = Measurement::Result.new
103
103
  forecast_measurement.date = Date.parse((@now + (i * 60 * 60 * 24)).to_s)
104
104
  wind = Data::Speed.new
105
105
  wind << (i * 5)
@@ -0,0 +1,660 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Result Measurement" do
4
+
5
+ describe "when initialized" do
6
+
7
+ before(:each) do
8
+ @result = Measurement::Result.new
9
+ end
10
+
11
+ it "responds to temperature" do
12
+ @result.temperature.should be_nil
13
+ end
14
+
15
+ it "responds to dew_point" do
16
+ @result.dew_point.should be_nil
17
+ end
18
+
19
+ it "responds to heat_index" do
20
+ @result.heat_index.should be_nil
21
+ end
22
+
23
+ it "responds to wind_chill" do
24
+ @result.wind_chill.should be_nil
25
+ end
26
+
27
+ it "responds to pressure" do
28
+ @result.pressure.should be_nil
29
+ end
30
+
31
+ it "responds to visibility" do
32
+ @result.pressure.should be_nil
33
+ end
34
+
35
+ it "responds to current_at" do
36
+ @result.current_at.should be_nil
37
+ end
38
+
39
+ it "responds to updated_at" do
40
+ @result.updated_at.should be_nil
41
+ end
42
+
43
+ it "responds to date" do
44
+ @result.date.should be_nil
45
+ end
46
+
47
+ it "responds to low" do
48
+ @result.low.should be_nil
49
+ end
50
+
51
+ it "responds to high" do
52
+ @result.high.should be_nil
53
+ end
54
+
55
+ it "responds to pop" do
56
+ @result.pop.should be_nil
57
+ end
58
+
59
+ it "responds to valid_start_date" do
60
+ @result.valid_start_date.should be_nil
61
+ end
62
+
63
+ it "responds to valid_end_date" do
64
+ @result.valid_end_date.should be_nil
65
+ end
66
+
67
+ it "responds to description" do
68
+ @result.description.should be_nil
69
+ end
70
+
71
+ it "responds to humidity" do
72
+ @result.humidity.should be_nil
73
+ end
74
+
75
+ it "responds to icon" do
76
+ @result.icon.should be_nil
77
+ end
78
+
79
+ it "responds to condition" do
80
+ @result.condition.should be_nil
81
+ end
82
+
83
+ it "responds to wind" do
84
+ @result.wind.should be_nil
85
+ end
86
+
87
+ it "responds to sun" do
88
+ @result.sun.should be_nil
89
+ end
90
+
91
+ it "responds to metric" do
92
+ @result.metric.should be_true
93
+ end
94
+
95
+ it "responds to metric?" do
96
+ @result.metric?.should be_true
97
+ @result.metric = false
98
+ @result.metric?.should be_false
99
+ end
100
+
101
+ end
102
+
103
+ describe "when writing data" do
104
+
105
+ before(:each) do
106
+ @result = Measurement::Result.new
107
+ end
108
+
109
+ it "only accepts Data::Temperature for temperature" do
110
+ invalid_data = 1
111
+ invalid_data.class.should_not == Data::Temperature
112
+ lambda { @result.temperature = invalid_data }.should raise_error(ArgumentError)
113
+
114
+ valid_data = Data::Temperature.new
115
+ valid_data.class.should == Data::Temperature
116
+ lambda { @result.temperature = valid_data }.should_not raise_error(ArgumentError)
117
+ end
118
+
119
+ it "only accepts Data::Temperature for dew_point" do
120
+ invalid_data = 1
121
+ invalid_data.class.should_not == Data::Temperature
122
+ lambda { @result.dew_point = invalid_data }.should raise_error(ArgumentError)
123
+
124
+ valid_data = Data::Temperature.new
125
+ valid_data.class.should == Data::Temperature
126
+ lambda { @result.dew_point = valid_data }.should_not raise_error(ArgumentError)
127
+ end
128
+
129
+ it "only accepts Data::Temperature for heat_index" do
130
+ invalid_data = 1
131
+ invalid_data.class.should_not == Data::Temperature
132
+ lambda { @result.heat_index = invalid_data }.should raise_error(ArgumentError)
133
+
134
+ valid_data = Data::Temperature.new
135
+ valid_data.class.should == Data::Temperature
136
+ lambda { @result.heat_index = valid_data }.should_not raise_error(ArgumentError)
137
+ end
138
+
139
+ it "only accepts Data::Temperature for wind_chill" do
140
+ invalid_data = 1
141
+ invalid_data.class.should_not == Data::Temperature
142
+ lambda { @result.wind_chill = invalid_data }.should raise_error(ArgumentError)
143
+
144
+ valid_data = Data::Temperature.new
145
+ valid_data.class.should == Data::Temperature
146
+ lambda { @result.wind_chill = valid_data }.should_not raise_error(ArgumentError)
147
+ end
148
+
149
+ it "only accepts Data::Pressure for pressure" do
150
+ invalid_data = 1
151
+ invalid_data.class.should_not == Data::Pressure
152
+ lambda { @result.pressure = invalid_data }.should raise_error(ArgumentError)
153
+
154
+ valid_data = Data::Pressure.new
155
+ valid_data.class.should == Data::Pressure
156
+ lambda { @result.pressure = valid_data }.should_not raise_error(ArgumentError)
157
+ end
158
+
159
+ it "only accepts Data::Distance for visibility" do
160
+ invalid_data = 1
161
+ invalid_data.class.should_not == Data::Distance
162
+ lambda { @result.visibility = invalid_data }.should raise_error(ArgumentError)
163
+
164
+ valid_data = Data::Distance.new
165
+ valid_data.class.should == Data::Distance
166
+ lambda { @result.visibility = valid_data }.should_not raise_error(ArgumentError)
167
+ end
168
+
169
+ it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
170
+ invalid_data = 1
171
+ invalid_data.class.should_not == Data::LocalTime
172
+ invalid_data.class.should_not == Data::LocalDateTime
173
+ lambda { @result.current_at = invalid_data }.should raise_error(ArgumentError)
174
+
175
+ valid_data = Data::LocalTime.new
176
+ valid_data.class.should == Data::LocalTime
177
+ lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
178
+
179
+ valid_data = Data::LocalDateTime.new(2009,1,1)
180
+ valid_data.class.should == Data::LocalDateTime
181
+ lambda { @result.current_at = valid_data }.should_not raise_error(ArgumentError)
182
+ end
183
+
184
+ it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
185
+ invalid_data = 1
186
+ invalid_data.class.should_not == Data::LocalTime
187
+ invalid_data.class.should_not == Data::LocalDateTime
188
+ lambda { @result.updated_at = invalid_data }.should raise_error(ArgumentError)
189
+
190
+ valid_data = Data::LocalTime.new
191
+ valid_data.class.should == Data::LocalTime
192
+ lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
193
+
194
+ valid_data = Data::LocalDateTime.new(2009,1,1)
195
+ valid_data.class.should == Data::LocalDateTime
196
+ lambda { @result.updated_at = valid_data }.should_not raise_error(ArgumentError)
197
+ end
198
+
199
+ it "only accepts Date for date" do
200
+ invalid_data = 1
201
+ invalid_data.class.should_not == Date
202
+ lambda { @result.date = invalid_data }.should raise_error(ArgumentError)
203
+
204
+ valid_data = Date.new
205
+ valid_data.class.should == Date
206
+ lambda { @result.date = valid_data }.should_not raise_error(ArgumentError)
207
+ end
208
+
209
+ it "only accepts Data::Temperature for high" do
210
+ invalid_data = 1
211
+ invalid_data.class.should_not == Data::Temperature
212
+ lambda { @result.high = invalid_data }.should raise_error(ArgumentError)
213
+
214
+ valid_data = Data::Temperature.new
215
+ valid_data.class.should == Data::Temperature
216
+ lambda { @result.high = valid_data }.should_not raise_error(ArgumentError)
217
+ end
218
+
219
+ it "only accepts Data::Temperature for low" do
220
+ invalid_data = 1
221
+ invalid_data.class.should_not == Data::Temperature
222
+ lambda { @result.low = invalid_data }.should raise_error(ArgumentError)
223
+
224
+ valid_data = Data::Temperature.new
225
+ valid_data.class.should == Data::Temperature
226
+ lambda { @result.low = valid_data }.should_not raise_error(ArgumentError)
227
+ end
228
+
229
+ it "only accepts Fixnum for pop" do
230
+ invalid_data = "test"
231
+ invalid_data.class.should_not == Fixnum
232
+ lambda { @result.pop = invalid_data }.should raise_error(ArgumentError)
233
+
234
+ valid_data = 50
235
+ valid_data.class.should == Fixnum
236
+ lambda { @result.pop = valid_data }.should_not raise_error(ArgumentError)
237
+ end
238
+
239
+ it "only accepts Data::LocalDateTime for valid_start_date" do
240
+ invalid_data = 1
241
+ invalid_data.class.should_not == Data::LocalDateTime
242
+ lambda { @result.valid_start_date = invalid_data }.should raise_error(ArgumentError)
243
+
244
+ valid_data = Data::LocalDateTime.new(2009,1,1)
245
+ valid_data.class.should == Data::LocalDateTime
246
+ lambda { @result.valid_start_date = valid_data }.should_not raise_error(ArgumentError)
247
+ end
248
+
249
+ it "only accepts Data::LocalDateTime for valid_end_date" do
250
+ invalid_data = 1
251
+ invalid_data.class.should_not == Data::LocalDateTime
252
+ lambda { @result.valid_end_date = invalid_data }.should raise_error(ArgumentError)
253
+
254
+ valid_data = Data::LocalDateTime.new(2009,1,1)
255
+ valid_data.class.should == Data::LocalDateTime
256
+ lambda { @result.valid_end_date = valid_data }.should_not raise_error(ArgumentError)
257
+ end
258
+
259
+ it "sets valid_start_date and valid_end_date if given date" do
260
+ forecast = Measurement::Result.new
261
+ forecast.valid_start_date.should be_nil
262
+ forecast.valid_end_date.should be_nil
263
+ date = Date.new(2009,05,05)
264
+ forecast.date = date
265
+ forecast.valid_start_date.should_not be_nil
266
+ forecast.valid_start_date.year.should == date.year
267
+ forecast.valid_start_date.month.should == date.month
268
+ forecast.valid_start_date.day.should == date.day
269
+ forecast.valid_start_date.hour.should == 0
270
+ forecast.valid_start_date.min.should == 0
271
+ forecast.valid_start_date.sec.should == 0
272
+
273
+ forecast.valid_end_date.should_not be_nil
274
+ forecast.valid_end_date.year.should == date.year
275
+ forecast.valid_end_date.month.should == date.month
276
+ forecast.valid_end_date.day.should == date.day
277
+ forecast.valid_end_date.hour.should == 23
278
+ forecast.valid_end_date.min.should == 59
279
+ forecast.valid_end_date.sec.should == 59
280
+ end
281
+
282
+ it "returns true if the valid_date range includes the given date" do
283
+ forecast = Measurement::Result.new
284
+ forecast.date = Date.new(2009,05,05)
285
+ forecast.for_datetime?(Data::LocalDateTime.new(2009,5,5,12,0,0)).should be_true
286
+ end
287
+
288
+ it "returns false if the valid_date range excludes the given date" do
289
+ forecast = Measurement::Result.new
290
+ forecast.date = Date.new(2009,05,05)
291
+ forecast.for_datetime?(Data::LocalDateTime.new(2009,5,4,12,0,0)).should be_false
292
+ end
293
+
294
+ it "only accepts Fixnum or Float for humidity" do
295
+ invalid_data = "invalid"
296
+ invalid_data.class.should_not == Fixnum
297
+ invalid_data.class.should_not == Float
298
+ lambda { @result.humidity = invalid_data }.should raise_error(ArgumentError)
299
+
300
+ valid_data = 1.to_i
301
+ valid_data.class.should == Fixnum
302
+ lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
303
+
304
+ valid_data = 1.0.to_f
305
+ valid_data.class.should == Float
306
+ lambda { @result.humidity = valid_data }.should_not raise_error(ArgumentError)
307
+ end
308
+
309
+ it "only accepts String for icon" do
310
+ invalid_data = 1
311
+ invalid_data.class.should_not == String
312
+ lambda { @result.icon = invalid_data }.should raise_error(ArgumentError)
313
+
314
+ valid_data = "valid"
315
+ valid_data.class.should == String
316
+ lambda { @result.icon = valid_data }.should_not raise_error(ArgumentError)
317
+ end
318
+
319
+ it "only accepts String for condition" do
320
+ invalid_data = 1
321
+ invalid_data.class.should_not == String
322
+ lambda { @result.condition = invalid_data }.should raise_error(ArgumentError)
323
+
324
+ valid_data = "valid"
325
+ valid_data.class.should == String
326
+ lambda { @result.condition = valid_data }.should_not raise_error(ArgumentError)
327
+ end
328
+
329
+ it "only accepts Data::Speed for wind" do
330
+ invalid_data = 1
331
+ invalid_data.class.should_not == Data::Speed
332
+ lambda { @result.wind = invalid_data }.should raise_error(ArgumentError)
333
+
334
+ valid_data = Data::Speed.new
335
+ valid_data.class.should == Data::Speed
336
+ lambda { @result.wind = valid_data }.should_not raise_error(ArgumentError)
337
+ end
338
+
339
+ it "only accepts Data::Sun for sun" do
340
+ invalid_data = 1
341
+ invalid_data.class.should_not == Data::Sun
342
+ lambda { @result.sun = invalid_data }.should raise_error(ArgumentError)
343
+
344
+ valid_data = Data::Sun.new
345
+ valid_data.class.should == Data::Sun
346
+ lambda { @result.sun = valid_data }.should_not raise_error(ArgumentError)
347
+ end
348
+
349
+ end
350
+
351
+ describe "method missing" do
352
+
353
+ before(:each) do
354
+ @result = Measurement::Result.new
355
+ end
356
+
357
+ it "responds to method + ?" do
358
+ valid_method = "humidity"
359
+ @result.respond_to?(valid_method).should be_true
360
+ lambda { @result.send(valid_method + "?") }.should_not raise_error(NoMethodError)
361
+ end
362
+
363
+ it "ignores non_method + ?" do
364
+ invalid_method = "humid"
365
+ @result.respond_to?(invalid_method).should be_false
366
+ lambda { @result.send(invalid_method + "?") }.should raise_error(NoMethodError)
367
+ end
368
+
369
+ it "returns true if set" do
370
+ @result.humidity = 10
371
+ @result.humidity.should_not be_nil
372
+ @result.humidity?.should be_true
373
+ end
374
+
375
+ it "returns false if not set" do
376
+ @result.humidity.should be_nil
377
+ @result.humidity?.should be_false
378
+ end
379
+
380
+ end
381
+
382
+ describe "answer simple questions, like" do
383
+
384
+ before(:each) do
385
+ @result = Measurement::Result.new
386
+ @result.temperature = Data::Temperature.new
387
+ @result.temperature << 5
388
+ @dew_point = Data::Temperature.new
389
+ @dew_point << 10
390
+ end
391
+
392
+ describe "windy?" do
393
+
394
+ before(:each) do
395
+ @wind = Data::Speed.new
396
+ @wind << 11
397
+ end
398
+
399
+ it "requires real threshold number (or nil)" do
400
+ lambda { @result.windy?("invalid") }.should raise_error(ArgumentError)
401
+ lambda { @result.windy? }.should_not raise_error(ArgumentError)
402
+ lambda { @result.windy?(10) }.should_not raise_error(ArgumentError)
403
+ end
404
+
405
+ it "returns nil when no wind" do
406
+ @result.wind?.should be_false
407
+ @result.windy?.should be_nil
408
+ @result.wind = @wind
409
+ @result.wind?.should be_true
410
+ @result.windy?.should_not be_nil
411
+ end
412
+
413
+ it "return true when current wind over threshold" do
414
+ @result.wind = @wind
415
+ @result.windy?.should be_true
416
+ @result.windy?(10).should be_true
417
+ end
418
+
419
+ it "return false when current wind under threshold" do
420
+ @result.wind = @wind
421
+ @result.windy?(15).should be_false
422
+ end
423
+
424
+ end
425
+
426
+ describe "day?" do
427
+
428
+ before(:each) do
429
+ @early_time = Data::LocalTime.parse("6:00 am")
430
+ @mid_time = Data::LocalTime.parse("11:00 am")
431
+ @late_time = Data::LocalTime.parse("8:00 pm")
432
+ @sun = Data::Sun.new(@early_time, @late_time)
433
+
434
+ end
435
+
436
+ it "requires Data::LocalTime object" do
437
+ @result.sun = @sun
438
+ lambda { @result.day?("invalid") }.should raise_error(ArgumentError)
439
+ lambda { @result.day? }.should raise_error(ArgumentError)
440
+ lambda { @result.day?(@mid_time) }.should_not raise_error(ArgumentError)
441
+ end
442
+
443
+ it "returns nil when no sun" do
444
+ @result.sun?.should be_false
445
+ @result.day?(@mid_time).should be_nil
446
+ @result.sun = @sun
447
+ @result.sun?.should be_true
448
+ @result.day?(@mid_time).should_not be_nil
449
+ end
450
+
451
+ it "return true when time between rise and set" do
452
+ @result.sun = @sun
453
+ @result.day?(@mid_time).should be_true
454
+ end
455
+
456
+ it "return false when time before rise or after set" do
457
+ sun = Data::Sun.new(@mid_time, @late_time)
458
+ @result.sun = sun
459
+ @result.day?(@early_time).should be_false
460
+
461
+ sun = Data::Sun.new(@early_time, @mid_time)
462
+ @result.sun = sun
463
+ @result.day?(@late_time).should be_false
464
+ end
465
+
466
+ end
467
+
468
+ describe "wet?" do
469
+
470
+ describe "wet_by_humidity?" do
471
+
472
+ it "requires real threshold number (or nil)" do
473
+ lambda { @result.send("_wet_by_humidity?","invalid") }.should raise_error(ArgumentError)
474
+ lambda { @result.send("_wet_by_humidity?") }.should_not raise_error(ArgumentError)
475
+ lambda { @result.send("_wet_by_humidity?",99) }.should_not raise_error(ArgumentError)
476
+ end
477
+
478
+ it "returns nil when no humidity" do
479
+ @result.humidity?.should be_false
480
+ @result.send("_wet_by_humidity?").should be_nil
481
+ @result.wet?(nil,99).should be_nil
482
+ @result.humidity = 100
483
+ @result.humidity?.should be_true
484
+ @result.send("_wet_by_humidity?").should_not be_nil
485
+ @result.wet?(nil,99).should_not be_nil
486
+ end
487
+
488
+ it "return true when current humidity over threshold" do
489
+ @result.humidity = 100
490
+ @result.send("_wet_by_humidity?").should be_true
491
+ @result.send("_wet_by_humidity?",99).should be_true
492
+ @result.wet?(nil,99).should be_true
493
+ end
494
+
495
+ it "return false when current humidity under threshold" do
496
+ @result.humidity = 98
497
+ @result.send("_wet_by_humidity?",99).should be_false
498
+ @result.wet?(nil,99).should be_false
499
+ end
500
+
501
+ end
502
+
503
+ describe "wet_by_icon?" do
504
+
505
+ before(:each) do
506
+ @wet_icons = %w(rain thunderstorm)
507
+ end
508
+
509
+ it "requires Array (or nil)" do
510
+ lambda { @result.send("_wet_by_icon?","invalid") }.should raise_error(ArgumentError)
511
+ lambda { @result.send("_wet_by_icon?") }.should_not raise_error(ArgumentError)
512
+ lambda { @result.send("_wet_by_icon?",@wet_icons) }.should_not raise_error(ArgumentError)
513
+ end
514
+
515
+ it "returns nil when no icon or Array" do
516
+ @result.icon?.should be_false
517
+ @result.send("_wet_by_icon?",@wet_icons).should be_nil
518
+ @result.wet?(@wet_icons).should be_nil
519
+ @result.icon = "rain"
520
+ @result.icon?.should be_true
521
+ @result.send("_wet_by_icon?").should be_nil
522
+ @result.send("_wet_by_icon?",@wet_icons).should_not be_nil
523
+ @result.wet?(@wet_icons).should_not be_nil
524
+ end
525
+
526
+ it "return true when current icon indicates wet" do
527
+ @result.icon = "rain"
528
+ @result.send("_wet_by_icon?",@wet_icons).should be_true
529
+ @result.wet?(@wet_icons).should be_true
530
+ end
531
+
532
+ it "return false when current icon does NOT indicate wet" do
533
+ @result.icon = "sun"
534
+ @result.send("_wet_by_icon?",@wet_icons).should be_false
535
+ @result.wet?(@wet_icons).should be_false
536
+ end
537
+
538
+ end
539
+
540
+ describe "wet_by_dewpoint?" do
541
+
542
+ it "returns nil when no dewpoint" do
543
+ @result.dew_point?.should be_false
544
+ @result.send("_wet_by_dewpoint?").should be_nil
545
+ @result.wet?.should be_nil
546
+ @result.dew_point = @dew_point
547
+ @result.dew_point?.should be_true
548
+ @result.send("_wet_by_dewpoint?").should_not be_nil
549
+ @result.wet?.should_not be_nil
550
+ end
551
+
552
+ it "return true when current dewpoint over temperature" do
553
+ @result.dew_point = @dew_point
554
+ @result.send("_wet_by_dewpoint?").should be_true
555
+ @result.wet?.should be_true
556
+ end
557
+
558
+ it "return false when current dewpoint under temperature" do
559
+ @result.temperature << 15
560
+ @result.dew_point = @dew_point
561
+ @result.send("_wet_by_dewpoint?").should be_false
562
+ @result.wet?.should be_false
563
+ end
564
+
565
+ end
566
+
567
+ describe "wet_by_pop?" do
568
+
569
+ it "requires real threshold number (or nil)" do
570
+ lambda { @result.send("_wet_by_pop?","invalid") }.should raise_error(ArgumentError)
571
+ lambda { @result.send("_wet_by_pop?") }.should_not raise_error(ArgumentError)
572
+ lambda { @result.send("_wet_by_pop?",50) }.should_not raise_error(ArgumentError)
573
+ end
574
+
575
+ it "returns nil when no pop" do
576
+ @result.pop?.should be_false
577
+ @result.send("_wet_by_pop?",50).should be_nil
578
+ @result.wet?.should be_nil
579
+ @result.pop = 60
580
+ @result.pop?.should be_true
581
+ @result.send("_wet_by_pop?",50).should_not be_nil
582
+ @result.wet?.should_not be_nil
583
+ end
584
+
585
+ it "return true when current pop over threshold" do
586
+ @result.pop = 60
587
+ @result.send("_wet_by_pop?",50).should be_true
588
+ @result.wet?.should be_true
589
+ end
590
+
591
+ it "return false when current pop under threshold" do
592
+ @result.pop = 40
593
+ @result.send("_wet_by_pop?",50).should be_false
594
+ @result.wet?.should be_false
595
+ end
596
+
597
+ end
598
+
599
+ end
600
+
601
+ describe "sunny?" do
602
+
603
+ describe "sunny_by_icon?" do
604
+
605
+ before(:each) do
606
+ @sunny_icons = %w(sunny clear)
607
+ @early_time = Data::LocalTime.parse("6:00 am")
608
+ @mid_time = Data::LocalTime.parse("11:00 am")
609
+ @late_time = Data::LocalTime.parse("8:00 pm")
610
+ @sun = Data::Sun.new(@early_time, @late_time)
611
+
612
+ @result.sun = @sun
613
+ end
614
+
615
+ it "requires Array (or nil)" do
616
+ lambda { @result.send("_sunny_by_icon?","invalid") }.should raise_error(ArgumentError)
617
+ lambda { @result.send("_sunny_by_icon?") }.should_not raise_error(ArgumentError)
618
+ lambda { @result.send("_sunny_by_icon?",@sunny_icons) }.should_not raise_error(ArgumentError)
619
+ end
620
+
621
+ it "returns nil when no icon or Array" do
622
+ @result.icon?.should be_false
623
+ @result.send("_sunny_by_icon?",@sunny_icons).should be_nil
624
+ @result.sunny?(@mid_time,@sunny_icons).should be_nil
625
+ @result.icon = "sunny"
626
+ @result.icon?.should be_true
627
+ @result.send("_sunny_by_icon?").should be_nil
628
+ @result.send("_sunny_by_icon?",@sunny_icons).should_not be_nil
629
+ @result.sun?(@mid_time,@sunny_icons).should_not be_nil
630
+ end
631
+
632
+ it "returns true when current icon indicates sunny" do
633
+ @result.icon = "sunny"
634
+ @result.send("_sunny_by_icon?",@sunny_icons).should be_true
635
+ @result.sunny?(@mid_time,@sunny_icons).should be_true
636
+ end
637
+
638
+ it "returns false when current icon does NOT indicate sunny" do
639
+ @result.icon = "rain"
640
+ @result.send("_sunny_by_icon?",@sunny_icons).should be_false
641
+ @result.sunny?(@mid_time,@sunny_icons).should be_false
642
+ end
643
+
644
+ it "returns false when night" do
645
+ @result.icon = "sunny"
646
+ @result.send("_sunny_by_icon?",@sunny_icons).should be_true
647
+ @result.sunny?(@mid_time,@sunny_icons).should be_true
648
+
649
+ @sun = Data::Sun.new(@mid_time, @late_time)
650
+ @result.sun = @sun
651
+ @result.sunny?(@early_time,@sunny_icons).should be_false
652
+ end
653
+
654
+ end
655
+
656
+ end
657
+
658
+ end
659
+
660
+ end