attack-barometer 0.5.0 → 0.6.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.
Files changed (64) hide show
  1. data/README.rdoc +51 -9
  2. data/VERSION.yml +1 -1
  3. data/bin/barometer +57 -7
  4. data/lib/barometer/base.rb +3 -0
  5. data/lib/barometer/data/sun.rb +10 -0
  6. data/lib/barometer/data/zone.rb +79 -188
  7. data/lib/barometer/data.rb +11 -6
  8. data/lib/barometer/formats/coordinates.rb +4 -1
  9. data/lib/barometer/formats/geocode.rb +9 -7
  10. data/lib/barometer/formats/icao.rb +2 -2
  11. data/lib/barometer/formats/weather_id.rb +2 -2
  12. data/lib/barometer/measurements/common.rb +113 -0
  13. data/lib/barometer/{data → measurements}/current.rb +17 -42
  14. data/lib/barometer/measurements/forecast.rb +62 -0
  15. data/lib/barometer/measurements/forecast_array.rb +72 -0
  16. data/lib/barometer/{data → measurements}/measurement.rb +57 -45
  17. data/lib/barometer/measurements/night.rb +27 -0
  18. data/lib/barometer/query.rb +55 -5
  19. data/lib/barometer/services.rb +3 -1
  20. data/lib/barometer/translations/zone_codes.yml +360 -0
  21. data/lib/barometer/weather.rb +5 -4
  22. data/lib/barometer/weather_services/google.rb +19 -35
  23. data/lib/barometer/weather_services/service.rb +113 -255
  24. data/lib/barometer/weather_services/weather_bug.rb +291 -2
  25. data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
  26. data/lib/barometer/weather_services/wunderground.rb +83 -89
  27. data/lib/barometer/weather_services/yahoo.rb +44 -91
  28. data/lib/barometer/web_services/geocode.rb +1 -0
  29. data/lib/barometer/web_services/timezone.rb +40 -0
  30. data/lib/barometer/web_services/weather_id.rb +17 -2
  31. data/lib/barometer.rb +11 -0
  32. data/lib/demometer/demometer.rb +28 -0
  33. data/lib/demometer/public/css/master.css +259 -1
  34. data/lib/demometer/views/index.erb +2 -0
  35. data/lib/demometer/views/layout.erb +3 -2
  36. data/lib/demometer/views/measurement.erb +4 -1
  37. data/lib/demometer/views/readme.erb +116 -88
  38. data/spec/data/sun_spec.rb +53 -0
  39. data/spec/data/zone_spec.rb +330 -100
  40. data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
  41. data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
  42. data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
  43. data/spec/formats/weather_id_spec.rb +10 -5
  44. data/spec/measurements/common_spec.rb +352 -0
  45. data/spec/{data → measurements}/current_spec.rb +40 -103
  46. data/spec/measurements/forecast_array_spec.rb +165 -0
  47. data/spec/measurements/forecast_spec.rb +135 -0
  48. data/spec/{data → measurements}/measurement_spec.rb +86 -107
  49. data/spec/measurements/night_measurement_spec.rb +49 -0
  50. data/spec/query_spec.rb +12 -2
  51. data/spec/spec_helper.rb +28 -1
  52. data/spec/weather_services/google_spec.rb +27 -117
  53. data/spec/weather_services/services_spec.rb +49 -1024
  54. data/spec/weather_services/weather_bug_spec.rb +274 -0
  55. data/spec/weather_services/weather_dot_com_spec.rb +45 -125
  56. data/spec/weather_services/wunderground_spec.rb +42 -136
  57. data/spec/weather_services/yahoo_spec.rb +26 -116
  58. data/spec/weather_spec.rb +45 -45
  59. metadata +23 -11
  60. data/lib/barometer/data/forecast.rb +0 -84
  61. data/lib/barometer/data/night.rb +0 -69
  62. data/lib/barometer/extensions/graticule.rb +0 -51
  63. data/spec/data/forecast_spec.rb +0 -192
  64. data/spec/data/night_measurement_spec.rb +0 -136
@@ -0,0 +1,352 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Common Measurement" do
4
+
5
+ describe "when initialized" do
6
+
7
+ before(:each) do
8
+ @common = Measurement::Common.new
9
+ end
10
+
11
+ it "responds to humidity" do
12
+ @common.humidity.should be_nil
13
+ end
14
+
15
+ it "responds to icon" do
16
+ @common.icon.should be_nil
17
+ end
18
+
19
+ it "responds to condition" do
20
+ @common.condition.should be_nil
21
+ end
22
+
23
+ it "responds to wind" do
24
+ @common.wind.should be_nil
25
+ end
26
+
27
+ it "responds to sun" do
28
+ @common.sun.should be_nil
29
+ end
30
+
31
+ it "responds to metric" do
32
+ @common.metric.should be_true
33
+ end
34
+
35
+ it "responds to metric?" do
36
+ @common.metric?.should be_true
37
+ @common.metric = false
38
+ @common.metric?.should be_false
39
+ end
40
+
41
+ end
42
+
43
+ describe "when writing data" do
44
+
45
+ before(:each) do
46
+ @common = Measurement::Common.new
47
+ end
48
+
49
+ it "only accepts Fixnum or Float for humidity" do
50
+ invalid_data = "invalid"
51
+ invalid_data.class.should_not == Fixnum
52
+ invalid_data.class.should_not == Float
53
+ lambda { @common.humidity = invalid_data }.should raise_error(ArgumentError)
54
+
55
+ valid_data = 1.to_i
56
+ valid_data.class.should == Fixnum
57
+ lambda { @common.humidity = valid_data }.should_not raise_error(ArgumentError)
58
+
59
+ valid_data = 1.0.to_f
60
+ valid_data.class.should == Float
61
+ lambda { @common.humidity = valid_data }.should_not raise_error(ArgumentError)
62
+ end
63
+
64
+ it "only accepts String for icon" do
65
+ invalid_data = 1
66
+ invalid_data.class.should_not == String
67
+ lambda { @common.icon = invalid_data }.should raise_error(ArgumentError)
68
+
69
+ valid_data = "valid"
70
+ valid_data.class.should == String
71
+ lambda { @common.icon = valid_data }.should_not raise_error(ArgumentError)
72
+ end
73
+
74
+ it "only accepts String for condition" do
75
+ invalid_data = 1
76
+ invalid_data.class.should_not == String
77
+ lambda { @common.condition = invalid_data }.should raise_error(ArgumentError)
78
+
79
+ valid_data = "valid"
80
+ valid_data.class.should == String
81
+ lambda { @common.condition = valid_data }.should_not raise_error(ArgumentError)
82
+ end
83
+
84
+ it "only accepts Data::Speed for wind" do
85
+ invalid_data = 1
86
+ invalid_data.class.should_not == Data::Speed
87
+ lambda { @common.wind = invalid_data }.should raise_error(ArgumentError)
88
+
89
+ valid_data = Data::Speed.new
90
+ valid_data.class.should == Data::Speed
91
+ lambda { @common.wind = valid_data }.should_not raise_error(ArgumentError)
92
+ end
93
+
94
+ it "only accepts Data::Sun for sun" do
95
+ invalid_data = 1
96
+ invalid_data.class.should_not == Data::Sun
97
+ lambda { @common.sun = invalid_data }.should raise_error(ArgumentError)
98
+
99
+ valid_data = Data::Sun.new
100
+ valid_data.class.should == Data::Sun
101
+ lambda { @common.sun = valid_data }.should_not raise_error(ArgumentError)
102
+ end
103
+
104
+ end
105
+
106
+ describe "method missing" do
107
+
108
+ before(:each) do
109
+ @common = Measurement::Common.new
110
+ end
111
+
112
+ it "responds to method + ?" do
113
+ valid_method = "humidity"
114
+ @common.respond_to?(valid_method).should be_true
115
+ lambda { @common.send(valid_method + "?") }.should_not raise_error(NoMethodError)
116
+ end
117
+
118
+ it "ignores non_method + ?" do
119
+ invalid_method = "humid"
120
+ @common.respond_to?(invalid_method).should be_false
121
+ lambda { @common.send(invalid_method + "?") }.should raise_error(NoMethodError)
122
+ end
123
+
124
+ it "returns true if set" do
125
+ @common.humidity = 10
126
+ @common.humidity.should_not be_nil
127
+ @common.humidity?.should be_true
128
+ end
129
+
130
+ it "returns false if not set" do
131
+ @common.humidity.should be_nil
132
+ @common.humidity?.should be_false
133
+ end
134
+
135
+ end
136
+
137
+ describe "answer simple questions, like" do
138
+
139
+ before(:each) do
140
+ @common = Measurement::Common.new
141
+ end
142
+
143
+ describe "windy?" do
144
+
145
+ before(:each) do
146
+ @wind = Data::Speed.new
147
+ @wind << 11
148
+ end
149
+
150
+ it "requires real threshold number (or nil)" do
151
+ lambda { @common.windy?("invalid") }.should raise_error(ArgumentError)
152
+ lambda { @common.windy? }.should_not raise_error(ArgumentError)
153
+ lambda { @common.windy?(10) }.should_not raise_error(ArgumentError)
154
+ end
155
+
156
+ it "returns nil when no wind" do
157
+ @common.wind?.should be_false
158
+ @common.windy?.should be_nil
159
+ @common.wind = @wind
160
+ @common.wind?.should be_true
161
+ @common.windy?.should_not be_nil
162
+ end
163
+
164
+ it "return true when current wind over threshold" do
165
+ @common.wind = @wind
166
+ @common.windy?.should be_true
167
+ @common.windy?(10).should be_true
168
+ end
169
+
170
+ it "return false when current wind under threshold" do
171
+ @common.wind = @wind
172
+ @common.windy?(15).should be_false
173
+ end
174
+
175
+ end
176
+
177
+ describe "day?" do
178
+
179
+ before(:each) do
180
+ @early_time = Data::LocalTime.parse("6:00 am")
181
+ @mid_time = Data::LocalTime.parse("11:00 am")
182
+ @late_time = Data::LocalTime.parse("8:00 pm")
183
+ @sun = Data::Sun.new(@early_time, @late_time)
184
+
185
+ end
186
+
187
+ it "requires Data::LocalTime object" do
188
+ @common.sun = @sun
189
+ lambda { @common.day?("invalid") }.should raise_error(ArgumentError)
190
+ lambda { @common.day? }.should raise_error(ArgumentError)
191
+ lambda { @common.day?(@mid_time) }.should_not raise_error(ArgumentError)
192
+ end
193
+
194
+ it "returns nil when no sun" do
195
+ @common.sun?.should be_false
196
+ @common.day?(@mid_time).should be_nil
197
+ @common.sun = @sun
198
+ @common.sun?.should be_true
199
+ @common.day?(@mid_time).should_not be_nil
200
+ end
201
+
202
+ it "return true when time between rise and set" do
203
+ @common.sun = @sun
204
+ @common.day?(@mid_time).should be_true
205
+ end
206
+
207
+ it "return false when time before rise or after set" do
208
+ sun = Data::Sun.new(@mid_time, @late_time)
209
+ @common.sun = sun
210
+ @common.day?(@early_time).should be_false
211
+
212
+ sun = Data::Sun.new(@early_time, @mid_time)
213
+ @common.sun = sun
214
+ @common.day?(@late_time).should be_false
215
+ end
216
+
217
+ end
218
+
219
+ describe "wet?" do
220
+
221
+ describe "wet_by_humidity?" do
222
+
223
+ it "requires real threshold number (or nil)" do
224
+ lambda { @common.send("_wet_by_humidity?","invalid") }.should raise_error(ArgumentError)
225
+ lambda { @common.send("_wet_by_humidity?") }.should_not raise_error(ArgumentError)
226
+ lambda { @common.send("_wet_by_humidity?",99) }.should_not raise_error(ArgumentError)
227
+ end
228
+
229
+ it "returns nil when no humidity" do
230
+ @common.humidity?.should be_false
231
+ @common.send("_wet_by_humidity?").should be_nil
232
+ @common.wet?(nil,99).should be_nil
233
+ @common.humidity = 100
234
+ @common.humidity?.should be_true
235
+ @common.send("_wet_by_humidity?").should_not be_nil
236
+ @common.wet?(nil,99).should_not be_nil
237
+ end
238
+
239
+ it "return true when current humidity over threshold" do
240
+ @common.humidity = 100
241
+ @common.send("_wet_by_humidity?").should be_true
242
+ @common.send("_wet_by_humidity?",99).should be_true
243
+ @common.wet?(nil,99).should be_true
244
+ end
245
+
246
+ it "return false when current humidity under threshold" do
247
+ @common.humidity = 98
248
+ @common.send("_wet_by_humidity?",99).should be_false
249
+ @common.wet?(nil,99).should be_false
250
+ end
251
+
252
+ end
253
+
254
+ describe "wet_by_icon?" do
255
+
256
+ before(:each) do
257
+ @wet_icons = %w(rain thunderstorm)
258
+ end
259
+
260
+ it "requires Array (or nil)" do
261
+ lambda { @common.send("_wet_by_icon?","invalid") }.should raise_error(ArgumentError)
262
+ lambda { @common.send("_wet_by_icon?") }.should_not raise_error(ArgumentError)
263
+ lambda { @common.send("_wet_by_icon?",@wet_icons) }.should_not raise_error(ArgumentError)
264
+ end
265
+
266
+ it "returns nil when no icon or Array" do
267
+ @common.icon?.should be_false
268
+ @common.send("_wet_by_icon?",@wet_icons).should be_nil
269
+ @common.wet?(@wet_icons).should be_nil
270
+ @common.icon = "rain"
271
+ @common.icon?.should be_true
272
+ @common.send("_wet_by_icon?").should be_nil
273
+ @common.send("_wet_by_icon?",@wet_icons).should_not be_nil
274
+ @common.wet?(@wet_icons).should_not be_nil
275
+ end
276
+
277
+ it "return true when current icon indicates wet" do
278
+ @common.icon = "rain"
279
+ @common.send("_wet_by_icon?",@wet_icons).should be_true
280
+ @common.wet?(@wet_icons).should be_true
281
+ end
282
+
283
+ it "return false when current icon does NOT indicate wet" do
284
+ @common.icon = "sun"
285
+ @common.send("_wet_by_icon?",@wet_icons).should be_false
286
+ @common.wet?(@wet_icons).should be_false
287
+ end
288
+
289
+ end
290
+
291
+ end
292
+
293
+ describe "sunny?" do
294
+
295
+ describe "sunny_by_icon?" do
296
+
297
+ before(:each) do
298
+ @sunny_icons = %w(sunny clear)
299
+ @early_time = Data::LocalTime.parse("6:00 am")
300
+ @mid_time = Data::LocalTime.parse("11:00 am")
301
+ @late_time = Data::LocalTime.parse("8:00 pm")
302
+ @sun = Data::Sun.new(@early_time, @late_time)
303
+
304
+ @common.sun = @sun
305
+ end
306
+
307
+ it "requires Array (or nil)" do
308
+ lambda { @common.send("_sunny_by_icon?","invalid") }.should raise_error(ArgumentError)
309
+ lambda { @common.send("_sunny_by_icon?") }.should_not raise_error(ArgumentError)
310
+ lambda { @common.send("_sunny_by_icon?",@sunny_icons) }.should_not raise_error(ArgumentError)
311
+ end
312
+
313
+ it "returns nil when no icon or Array" do
314
+ @common.icon?.should be_false
315
+ @common.send("_sunny_by_icon?",@sunny_icons).should be_nil
316
+ @common.sunny?(@mid_time,@sunny_icons).should be_nil
317
+ @common.icon = "sunny"
318
+ @common.icon?.should be_true
319
+ @common.send("_sunny_by_icon?").should be_nil
320
+ @common.send("_sunny_by_icon?",@sunny_icons).should_not be_nil
321
+ @common.sun?(@mid_time,@sunny_icons).should_not be_nil
322
+ end
323
+
324
+ it "returns true when current icon indicates sunny" do
325
+ @common.icon = "sunny"
326
+ @common.send("_sunny_by_icon?",@sunny_icons).should be_true
327
+ @common.sunny?(@mid_time,@sunny_icons).should be_true
328
+ end
329
+
330
+ it "returns false when current icon does NOT indicate sunny" do
331
+ @common.icon = "rain"
332
+ @common.send("_sunny_by_icon?",@sunny_icons).should be_false
333
+ @common.sunny?(@mid_time,@sunny_icons).should be_false
334
+ end
335
+
336
+ it "returns false when night" do
337
+ @common.icon = "sunny"
338
+ @common.send("_sunny_by_icon?",@sunny_icons).should be_true
339
+ @common.sunny?(@mid_time,@sunny_icons).should be_true
340
+
341
+ @sun = Data::Sun.new(@mid_time, @late_time)
342
+ @common.sun = @sun
343
+ @common.sunny?(@early_time,@sunny_icons).should be_false
344
+ end
345
+
346
+ end
347
+
348
+ end
349
+
350
+ end
351
+
352
+ end
@@ -5,19 +5,7 @@ describe "Current Measurement" do
5
5
  describe "when initialized" do
6
6
 
7
7
  before(:each) do
8
- @current = Data::CurrentMeasurement.new
9
- end
10
-
11
- it "responds to humidity" do
12
- @current.humidity.should be_nil
13
- end
14
-
15
- it "responds to icon" do
16
- @current.icon.should be_nil
17
- end
18
-
19
- it "responds to condition" do
20
- @current.condition.should be_nil
8
+ @current = Measurement::Current.new
21
9
  end
22
10
 
23
11
  it "responds to temperature" do
@@ -36,10 +24,6 @@ describe "Current Measurement" do
36
24
  @current.wind_chill.should be_nil
37
25
  end
38
26
 
39
- it "responds to wind" do
40
- @current.wind.should be_nil
41
- end
42
-
43
27
  it "responds to pressure" do
44
28
  @current.pressure.should be_nil
45
29
  end
@@ -48,10 +32,6 @@ describe "Current Measurement" do
48
32
  @current.pressure.should be_nil
49
33
  end
50
34
 
51
- it "responds to sun" do
52
- @current.sun.should be_nil
53
- end
54
-
55
35
  it "responds to current_at" do
56
36
  @current.current_at.should be_nil
57
37
  end
@@ -65,42 +45,7 @@ describe "Current Measurement" do
65
45
  describe "when writing data" do
66
46
 
67
47
  before(:each) do
68
- @current = Data::CurrentMeasurement.new
69
- end
70
-
71
- it "only accepts Fixnum or Float for humidity" do
72
- invalid_data = "invalid"
73
- invalid_data.class.should_not == Fixnum
74
- invalid_data.class.should_not == Float
75
- lambda { @current.humidity = invalid_data }.should raise_error(ArgumentError)
76
-
77
- valid_data = 1.to_i
78
- valid_data.class.should == Fixnum
79
- lambda { @current.humidity = valid_data }.should_not raise_error(ArgumentError)
80
-
81
- valid_data = 1.0.to_f
82
- valid_data.class.should == Float
83
- lambda { @current.humidity = valid_data }.should_not raise_error(ArgumentError)
84
- end
85
-
86
- it "only accepts String for icon" do
87
- invalid_data = 1
88
- invalid_data.class.should_not == String
89
- lambda { @current.icon = invalid_data }.should raise_error(ArgumentError)
90
-
91
- valid_data = "valid"
92
- valid_data.class.should == String
93
- lambda { @current.icon = valid_data }.should_not raise_error(ArgumentError)
94
- end
95
-
96
- it "only accepts String for condition" do
97
- invalid_data = 1
98
- invalid_data.class.should_not == String
99
- lambda { @current.condition = invalid_data }.should raise_error(ArgumentError)
100
-
101
- valid_data = "valid"
102
- valid_data.class.should == String
103
- lambda { @current.condition = valid_data }.should_not raise_error(ArgumentError)
48
+ @current = Measurement::Current.new
104
49
  end
105
50
 
106
51
  it "only accepts Data::Temperature for temperature" do
@@ -143,16 +88,6 @@ describe "Current Measurement" do
143
88
  lambda { @current.wind_chill = valid_data }.should_not raise_error(ArgumentError)
144
89
  end
145
90
 
146
- it "only accepts Data::Speed for wind" do
147
- invalid_data = 1
148
- invalid_data.class.should_not == Data::Speed
149
- lambda { @current.wind = invalid_data }.should raise_error(ArgumentError)
150
-
151
- valid_data = Data::Speed.new
152
- valid_data.class.should == Data::Speed
153
- lambda { @current.wind = valid_data }.should_not raise_error(ArgumentError)
154
- end
155
-
156
91
  it "only accepts Data::Pressure for pressure" do
157
92
  invalid_data = 1
158
93
  invalid_data.class.should_not == Data::Pressure
@@ -173,16 +108,6 @@ describe "Current Measurement" do
173
108
  lambda { @current.visibility = valid_data }.should_not raise_error(ArgumentError)
174
109
  end
175
110
 
176
- it "only accepts Data::Sun for sun" do
177
- invalid_data = 1
178
- invalid_data.class.should_not == Data::Sun
179
- lambda { @current.sun = invalid_data }.should raise_error(ArgumentError)
180
-
181
- valid_data = Data::Sun.new
182
- valid_data.class.should == Data::Sun
183
- lambda { @current.sun = valid_data }.should_not raise_error(ArgumentError)
184
- end
185
-
186
111
  it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
187
112
  invalid_data = 1
188
113
  invalid_data.class.should_not == Data::LocalTime
@@ -215,35 +140,47 @@ describe "Current Measurement" do
215
140
 
216
141
  end
217
142
 
218
- describe "method missing" do
143
+ describe "answer simple questions, like" do
219
144
 
220
145
  before(:each) do
221
- @current = Data::CurrentMeasurement.new
222
- end
223
-
224
- it "responds to method + ?" do
225
- valid_method = "humidity"
226
- @current.respond_to?(valid_method).should be_true
227
- lambda { @current.send(valid_method + "?") }.should_not raise_error(NoMethodError)
228
- end
229
-
230
- it "ignores non_method + ?" do
231
- invalid_method = "humid"
232
- @current.respond_to?(invalid_method).should be_false
233
- lambda { @current.send(invalid_method + "?") }.should raise_error(NoMethodError)
234
- end
235
-
236
- it "returns true if set" do
237
- @current.humidity = 10
238
- @current.humidity.should_not be_nil
239
- @current.humidity?.should be_true
240
- end
241
-
242
- it "returns false if not set" do
243
- @current.humidity.should be_nil
244
- @current.humidity?.should be_false
146
+ @current = Measurement::Current.new
147
+ @current.temperature = Data::Temperature.new
148
+ @current.temperature << 5
149
+ @dew_point = Data::Temperature.new
150
+ @dew_point << 10
151
+ end
152
+
153
+ describe "wet?" do
154
+
155
+ describe "wet_by_dewpoint?" do
156
+
157
+ it "returns nil when no dewpoint" do
158
+ @current.dew_point?.should be_false
159
+ @current.send("_wet_by_dewpoint?").should be_nil
160
+ @current.wet?.should be_nil
161
+ @current.dew_point = @dew_point
162
+ @current.dew_point?.should be_true
163
+ @current.send("_wet_by_dewpoint?").should_not be_nil
164
+ @current.wet?.should_not be_nil
165
+ end
166
+
167
+ it "return true when current dewpoint over temperature" do
168
+ @current.dew_point = @dew_point
169
+ @current.send("_wet_by_dewpoint?").should be_true
170
+ @current.wet?.should be_true
171
+ end
172
+
173
+ it "return false when current dewpoint under temperature" do
174
+ @current.temperature << 15
175
+ @current.dew_point = @dew_point
176
+ @current.send("_wet_by_dewpoint?").should be_false
177
+ @current.wet?.should be_false
178
+ end
179
+
180
+ end
181
+
245
182
  end
246
183
 
247
184
  end
248
-
185
+
249
186
  end
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Forecast Array" do
4
+
5
+ describe "instance methods" do
6
+
7
+ before(:each) do
8
+ @array = Measurement::ForecastArray.new
9
+ end
10
+
11
+ describe "'<<'" do
12
+
13
+ it "requires ForecastMeasurement" do
14
+ lambda { @array << "invalid" }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it "adds ForecastMeasurement" do
18
+ @array.size.should == 0
19
+ forecast = Measurement::Forecast.new
20
+ @array << forecast
21
+ @array.size.should == 1
22
+ end
23
+
24
+ end
25
+
26
+ describe "when searching forecasts using 'for'" do
27
+
28
+ before(:each) do
29
+ 1.upto(4) do |i|
30
+ forecast_measurement = Measurement::Forecast.new
31
+ forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
32
+ @array << forecast_measurement
33
+ end
34
+ @array.size.should == 4
35
+
36
+ @tommorrow = (Time.now + (60 * 60 * 24))
37
+ end
38
+
39
+ it "returns nil when there are no forecasts" do
40
+ @array = Measurement::ForecastArray.new
41
+ @array.size.should == 0
42
+ @array.for(@tommorrow).should be_nil
43
+ end
44
+
45
+ it "finds the date using a String" do
46
+ tommorrow = @tommorrow.to_s
47
+ tommorrow.class.should == String
48
+ @array.for(tommorrow).should == @array.first
49
+ end
50
+
51
+ it "finds the date using a Date" do
52
+ tommorrow = Date.parse(@tommorrow.to_s)
53
+ tommorrow.class.should == Date
54
+ @array.for(tommorrow).should == @array.first
55
+ end
56
+
57
+ it "finds the date using a DateTime" do
58
+ tommorrow = DateTime.parse(@tommorrow.to_s)
59
+ tommorrow.class.should == DateTime
60
+ @array.for(tommorrow).should == @array.first
61
+ end
62
+
63
+ it "finds the date using a Time" do
64
+ @tommorrow.class.should == Time
65
+ @array.for(@tommorrow).should == @array.first
66
+ end
67
+
68
+ it "finds the date using Data::LocalDateTime" do
69
+ tommorrow = Data::LocalDateTime.parse(@tommorrow.to_s)
70
+ tommorrow.class.should == Data::LocalDateTime
71
+ @array.for(tommorrow).should == @array.first
72
+ end
73
+
74
+ it "finds nothing when there is not a match" do
75
+ yesterday = (Time.now - (60 * 60 * 24))
76
+ yesterday.class.should == Time
77
+ @array.for(yesterday).should be_nil
78
+ end
79
+
80
+ it "finds using '[]'" do
81
+ tommorrow = @tommorrow.to_s
82
+ tommorrow.class.should == String
83
+ @array[tommorrow].should == @array.first
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+
90
+ describe "simple questions" do
91
+
92
+ before(:each) do
93
+ @array = Measurement::ForecastArray.new
94
+ #@early = Data::LocalTime("6:00 am")
95
+ #@noon = Data::LocalTime("12:00 pm")
96
+ #@late = Data::LocalTime("8:00 pm")
97
+ @now = Time.utc(2009,5,5,10,30,25)
98
+
99
+ @sun_icons = %w(sunny)
100
+
101
+ 0.upto(1) do |i|
102
+ forecast_measurement = Measurement::Forecast.new
103
+ forecast_measurement.date = Date.parse((@now + (i * 60 * 60 * 24)).to_s)
104
+ wind = Data::Speed.new
105
+ wind << (i * 5)
106
+ forecast_measurement.wind = wind
107
+ forecast_measurement.sun = Data::Sun.new(
108
+ Data::LocalTime.parse("9:00 am"), Data::LocalTime.parse("3:00 pm"))
109
+ forecast_measurement.icon = "sunny"
110
+ forecast_measurement.pop = 40
111
+ forecast_measurement.humidity = 95
112
+ @array << forecast_measurement
113
+ end
114
+ @array.size.should == 2
115
+ @tommorrow = (@now + (60 * 60 * 24))
116
+ @yesterday = (@now - (60 * 60 * 24))
117
+ @earlier = (@now - (60 * 60 * 3))
118
+ @later = (@now + (60 * 60 * 6))
119
+ end
120
+
121
+ it "answers windy?" do
122
+ @array.windy?(@tommorrow).should be_false
123
+ @array.windy?(@tommorrow,1).should be_true
124
+ @array.windy?(@yesterday).should be_nil
125
+ end
126
+
127
+ it "answers day?" do
128
+ @array.day?(@yesterday).should be_nil
129
+ @array.day?(@earlier).should be_false
130
+ @array.day?(@later).should be_false
131
+ @array.day?(@tommorrow).should be_true
132
+ @array.day?(@now).should be_true
133
+ end
134
+
135
+ it "answers sunny?" do
136
+ @array.sunny?(@tommorrow,%w(rain)).should be_false
137
+ @array.sunny?(@tommorrow,@sun_icons).should be_true
138
+ @array.sunny?(@yesterday).should be_nil
139
+ end
140
+
141
+ describe "wet?" do
142
+
143
+ it "answers via pop" do
144
+ @array.wet?(@tommorrow).should be_false
145
+ @array.wet?(@tommorrow,nil,50).should be_false
146
+ @array.wet?(@tommorrow,nil,30).should be_true
147
+ end
148
+
149
+ it "answers via humidity" do
150
+ @array.wet?(@tommorrow).should be_false
151
+ @array.wet?(@tommorrow,nil,50,99).should be_false
152
+ @array.wet?(@tommorrow,nil,50,90).should be_true
153
+ end
154
+
155
+ it "answers via icon" do
156
+ @array.wet?(@tommorrow,%w(rain)).should be_false
157
+ # pretend that "sun" means wet
158
+ @array.wet?(@tommorrow,@sun_icons).should be_true
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+
165
+ end