barometer 0.6.1 → 0.6.2

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 (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
@@ -1,76 +0,0 @@
1
- module Barometer
2
- #
3
- # Current Measurement
4
- # a data class for current weather conditions
5
- #
6
- # This is basically a data holding class for the current weather
7
- # conditions.
8
- #
9
- class Measurement::Current < Measurement::Common
10
-
11
- attr_reader :current_at, :updated_at
12
- attr_reader :temperature, :dew_point, :heat_index, :wind_chill
13
- attr_reader :pressure, :visibility
14
-
15
- # accessors (with input checking)
16
- #
17
- def temperature=(temperature)
18
- raise ArgumentError unless temperature.is_a?(Data::Temperature)
19
- @temperature = temperature
20
- end
21
-
22
- def dew_point=(dew_point)
23
- raise ArgumentError unless dew_point.is_a?(Data::Temperature)
24
- @dew_point = dew_point
25
- end
26
-
27
- def heat_index=(heat_index)
28
- raise ArgumentError unless heat_index.is_a?(Data::Temperature)
29
- @heat_index = heat_index
30
- end
31
-
32
- def wind_chill=(wind_chill)
33
- raise ArgumentError unless wind_chill.is_a?(Data::Temperature)
34
- @wind_chill = wind_chill
35
- end
36
-
37
- def pressure=(pressure)
38
- raise ArgumentError unless pressure.is_a?(Data::Pressure)
39
- @pressure = pressure
40
- end
41
-
42
- def visibility=(visibility)
43
- raise ArgumentError unless visibility.is_a?(Data::Distance)
44
- @visibility = visibility
45
- end
46
-
47
- def current_at=(current_at)
48
- raise ArgumentError unless (current_at.is_a?(Data::LocalTime) || current_at.is_a?(Data::LocalDateTime))
49
- @current_at = current_at
50
- end
51
-
52
- def updated_at=(updated_at)
53
- raise ArgumentError unless (updated_at.is_a?(Data::LocalTime) || updated_at.is_a?(Data::LocalDateTime))
54
- @updated_at = updated_at
55
- end
56
-
57
- #
58
- # answer simple questions
59
- #
60
-
61
- def wet?(wet_icons=nil, humidity_threshold=99)
62
- result = nil
63
- result ||= super(wet_icons, humidity_threshold) if (icon? || humidity?)
64
- result ||= _wet_by_dewpoint? if (dew_point? && temperature?)
65
- result
66
- end
67
-
68
- private
69
-
70
- def _wet_by_dewpoint?
71
- return nil unless dew_point? && temperature?
72
- temperature.to_f(metric?) <= dew_point.to_f(metric?)
73
- end
74
-
75
- end
76
- end
@@ -1,62 +0,0 @@
1
- require 'date'
2
- module Barometer
3
- #
4
- # Forecast Measurement
5
- # a data class for forecasted weather conditions
6
- #
7
- # This is basically a data holding class for the forecasted weather
8
- # conditions.
9
- #
10
- class Measurement::Forecast < Measurement::Common
11
-
12
- attr_reader :date
13
- attr_reader :low, :high, :pop, :night
14
-
15
- # accessors (with input checking)
16
- #
17
- def date=(date)
18
- raise ArgumentError unless date.is_a?(Date)
19
- @date = date
20
- end
21
-
22
- def high=(high)
23
- raise ArgumentError unless high.is_a?(Data::Temperature)
24
- @high = high
25
- end
26
-
27
- def low=(low)
28
- raise ArgumentError unless low.is_a?(Data::Temperature)
29
- @low = low
30
- end
31
-
32
- def pop=(pop)
33
- raise ArgumentError unless pop.is_a?(Fixnum)
34
- @pop = pop
35
- end
36
-
37
- def night=(night)
38
- raise ArgumentError unless night.is_a?(Measurement::ForecastNight)
39
- @night = night
40
- end
41
-
42
- #
43
- # answer simple questions
44
- #
45
-
46
- def wet?(wet_icons=nil, pop_threshold=50, humidity_threshold=99)
47
- result = nil
48
- result ||= _wet_by_pop?(pop_threshold) if pop?
49
- result ||= super(wet_icons, humidity_threshold) if (icon? || humidity?)
50
- result
51
- end
52
-
53
- private
54
-
55
- def _wet_by_pop?(threshold=50)
56
- raise ArgumentError unless (threshold.is_a?(Fixnum) || threshold.is_a?(Float))
57
- return nil unless pop?
58
- pop.to_f >= threshold.to_f
59
- end
60
-
61
- end
62
- end
@@ -1,27 +0,0 @@
1
- require 'date'
2
- module Barometer
3
- #
4
- # Night Measurement
5
- # a data class for forecasted night weather conditions
6
- #
7
- # This is basically a data holding class for the forecasted night
8
- # weather conditions.
9
- #
10
- class Measurement::ForecastNight < Measurement::Common
11
-
12
- attr_reader :date, :pop
13
-
14
- # accessors (with input checking)
15
- #
16
- def date=(date)
17
- raise ArgumentError unless date.is_a?(Date)
18
- @date = date
19
- end
20
-
21
- def pop=(pop)
22
- raise ArgumentError unless pop.is_a?(Fixnum)
23
- @pop = pop
24
- end
25
-
26
- end
27
- end
@@ -1,352 +0,0 @@
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