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
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
+ require 'mocha'
3
4
  require 'fakeweb'
4
5
  require 'cgi'
5
6
  require 'yaml'
@@ -41,7 +41,7 @@ describe "Google" do
41
41
 
42
42
  it "returns Measurement::Current object" do
43
43
  current = WeatherService::Google._build_current({})
44
- current.is_a?(Measurement::Current).should be_true
44
+ current.is_a?(Measurement::Result).should be_true
45
45
  end
46
46
 
47
47
  end
@@ -59,7 +59,7 @@ describe "Google" do
59
59
 
60
60
  it "returns Array object" do
61
61
  current = WeatherService::Google._build_forecast({})
62
- current.is_a?(Measurement::ForecastArray).should be_true
62
+ current.is_a?(Measurement::ResultArray).should be_true
63
63
  end
64
64
 
65
65
  end
@@ -135,8 +135,8 @@ describe "Google" do
135
135
  it "returns a Barometer::Measurement object" do
136
136
  result = Barometer::WeatherService::Google._measure(@measurement, @query)
137
137
  result.is_a?(Barometer::Measurement).should be_true
138
- result.current.is_a?(Measurement::Current).should be_true
139
- result.forecast.is_a?(Measurement::ForecastArray).should be_true
138
+ result.current.is_a?(Measurement::Result).should be_true
139
+ result.forecast.is_a?(Measurement::ResultArray).should be_true
140
140
  end
141
141
 
142
142
  end
@@ -134,7 +134,7 @@ describe "WeatherServices" do
134
134
 
135
135
  it "returns current and future" do
136
136
  measurement = @service.measure(@query)
137
- measurement.current.is_a?(Measurement::Current).should be_true
137
+ measurement.current.is_a?(Measurement::Result).should be_true
138
138
  measurement.forecast.is_a?(Array).should be_true
139
139
  end
140
140
 
@@ -52,7 +52,7 @@ describe "WeatherBug" do
52
52
 
53
53
  it "returns Measurement::Current object" do
54
54
  current = WeatherService::WeatherBug._build_current({})
55
- current.is_a?(Measurement::Current).should be_true
55
+ current.is_a?(Measurement::Result).should be_true
56
56
  end
57
57
 
58
58
  end
@@ -181,8 +181,8 @@ describe "WeatherBug" do
181
181
  it "returns a Barometer::Measurement object" do
182
182
  result = WeatherService::WeatherBug._measure(@measurement, @query)
183
183
  result.is_a?(Barometer::Measurement).should be_true
184
- result.current.is_a?(Measurement::Current).should be_true
185
- result.forecast.is_a?(Measurement::ForecastArray).should be_true
184
+ result.current.is_a?(Measurement::Result).should be_true
185
+ result.forecast.is_a?(Measurement::ResultArray).should be_true
186
186
  end
187
187
 
188
188
  end
@@ -48,7 +48,7 @@ describe "WeatherDotCom" do
48
48
 
49
49
  it "returns Measurement::Current object" do
50
50
  current = WeatherService::WeatherDotCom._build_current({})
51
- current.is_a?(Measurement::Current).should be_true
51
+ current.is_a?(Measurement::Result).should be_true
52
52
  end
53
53
 
54
54
  end
@@ -153,8 +153,8 @@ describe "WeatherDotCom" do
153
153
  it "returns a Barometer::Measurement object" do
154
154
  result = WeatherService::WeatherDotCom._measure(@measurement, @query)
155
155
  result.is_a?(Barometer::Measurement).should be_true
156
- result.current.is_a?(Measurement::Current).should be_true
157
- result.forecast.is_a?(Measurement::ForecastArray).should be_true
156
+ result.current.is_a?(Measurement::Result).should be_true
157
+ result.forecast.is_a?(Measurement::ResultArray).should be_true
158
158
  end
159
159
 
160
160
  end
@@ -195,10 +195,6 @@ describe "WeatherDotCom" do
195
195
  @measurement.current.visibility.to_f.should == 16.1
196
196
 
197
197
  # build sun
198
- # sun_rise = Barometer::Zone.merge("6:01 am", "5/4/09 12:51 AM PDT", -7)
199
- # sun_set = Barometer::Zone.merge("7:40 pm", "5/4/09 12:51 AM PDT", -7)
200
- # @measurement.current.sun.rise.should == sun_rise
201
- # @measurement.current.sun.set.should == sun_set
202
198
  @measurement.current.sun.rise.to_s.should == "06:01 am"
203
199
  @measurement.current.sun.set.to_s.should == "07:40 pm"
204
200
 
@@ -208,9 +204,11 @@ describe "WeatherDotCom" do
208
204
  @measurement.location.longitude.to_f.should == -118.41
209
205
 
210
206
  # builds forecasts
211
- @measurement.forecast.size.should == 5
207
+ @measurement.forecast.size.should == 10
212
208
 
213
- @measurement.forecast[0].date.should == Date.parse("May 3")
209
+ # day
210
+ @measurement.forecast[0].valid_start_date.should == Date.parse("May 3 7:00 am")
211
+ @measurement.forecast[0].valid_end_date.should == Date.parse("May 3 6:59:59 pm")
214
212
  @measurement.forecast[0].condition.should == "Partly Cloudy"
215
213
  @measurement.forecast[0].icon.should == "30"
216
214
  @measurement.forecast[0].high.should be_nil
@@ -223,23 +221,22 @@ describe "WeatherDotCom" do
223
221
  @measurement.forecast[0].wind.degrees.to_i.should == 288
224
222
  @measurement.forecast[0].wind.direction.should == "WNW"
225
223
 
226
- # sun_rise = Barometer::Zone.merge("6:02 am", "5/4/09 12:25 AM PDT", -7)
227
- # sun_set = Barometer::Zone.merge("7:40 pm", "5/4/09 12:25 AM PDT", -7)
228
- # @measurement.forecast[0].sun.rise.should == sun_rise
229
- # @measurement.forecast[0].sun.set.should == sun_set
230
224
  @measurement.forecast[0].sun.rise.to_s.should == "06:02 am"
231
225
  @measurement.forecast[0].sun.set.to_s.should == "07:40 pm"
232
226
 
233
- @measurement.forecast[0].night.should_not be_nil
234
- @measurement.forecast[0].night.condition.should == "Partly Cloudy"
235
- @measurement.forecast[0].night.icon.should == "29"
236
- @measurement.forecast[0].night.pop.to_i.should == 10
237
- @measurement.forecast[0].night.humidity.to_i.should == 71
227
+ # night
228
+ @measurement.forecast[1].should_not be_nil
229
+ @measurement.forecast[1].valid_start_date.should == Date.parse("May 3 7:00 pm")
230
+ @measurement.forecast[1].valid_end_date.should == Date.parse("May 4 6:59:59 am")
231
+ @measurement.forecast[1].condition.should == "Partly Cloudy"
232
+ @measurement.forecast[1].icon.should == "29"
233
+ @measurement.forecast[1].pop.to_i.should == 10
234
+ @measurement.forecast[1].humidity.to_i.should == 71
238
235
 
239
- @measurement.forecast[0].night.wind.should_not be_nil
240
- @measurement.forecast[0].night.wind.to_i.should == 14
241
- @measurement.forecast[0].night.wind.degrees.to_i.should == 335
242
- @measurement.forecast[0].night.wind.direction.should == "NNW"
236
+ @measurement.forecast[1].wind.should_not be_nil
237
+ @measurement.forecast[1].wind.to_i.should == 14
238
+ @measurement.forecast[1].wind.degrees.to_i.should == 335
239
+ @measurement.forecast[1].wind.direction.should == "NNW"
243
240
  end
244
241
 
245
242
  end
@@ -42,7 +42,7 @@ describe "Wunderground" do
42
42
 
43
43
  it "returns Barometer::CurrentMeasurement object" do
44
44
  current = WeatherService::Wunderground._build_current({})
45
- current.is_a?(Measurement::Current).should be_true
45
+ current.is_a?(Measurement::Result).should be_true
46
46
  end
47
47
 
48
48
  end
@@ -182,7 +182,7 @@ describe "Wunderground" do
182
182
  it "returns a Barometer::Measurement object" do
183
183
  result = WeatherService::Wunderground._measure(@measurement, @query)
184
184
  result.is_a?(Barometer::Measurement).should be_true
185
- result.current.is_a?(Measurement::Current).should be_true
185
+ result.current.is_a?(Measurement::Result).should be_true
186
186
  result.forecast.is_a?(Array).should be_true
187
187
  end
188
188
 
@@ -37,7 +37,7 @@ describe "Yahoo" do
37
37
 
38
38
  it "returns Barometer::CurrentMeasurement object" do
39
39
  current = WeatherService::Yahoo._build_current({})
40
- current.is_a?(Measurement::Current).should be_true
40
+ current.is_a?(Measurement::Result).should be_true
41
41
  end
42
42
 
43
43
  end
@@ -122,7 +122,7 @@ describe "Yahoo" do
122
122
  it "returns a Barometer::Measurement object" do
123
123
  result = WeatherService::Yahoo._measure(@measurement, @query)
124
124
  result.is_a?(Barometer::Measurement).should be_true
125
- result.current.is_a?(Measurement::Current).should be_true
125
+ result.current.is_a?(Measurement::Result).should be_true
126
126
  result.forecast.is_a?(Array).should be_true
127
127
  end
128
128
 
data/spec/weather_spec.rb CHANGED
@@ -83,10 +83,10 @@ describe "Weather" do
83
83
  before(:each) do
84
84
  @weather = Barometer::Weather.new
85
85
  @wunderground = Barometer::Measurement.new(:wunderground)
86
- @wunderground.current = Measurement::Current.new
86
+ @wunderground.current = Measurement::Result.new
87
87
  @wunderground.success = true
88
88
  @yahoo = Barometer::Measurement.new(:yahoo)
89
- @yahoo.current = Measurement::Current.new
89
+ @yahoo.current = Measurement::Result.new
90
90
  @yahoo.success = true
91
91
  @google = Barometer::Measurement.new(:google)
92
92
  @weather.measurements << @wunderground
@@ -298,9 +298,7 @@ describe "Weather" do
298
298
  wunderground = Barometer::Measurement.new(:wunderground)
299
299
  wunderground.success = true
300
300
  @weather.measurements << wunderground
301
- module Barometer; class Barometer::Measurement
302
- def windy?(a=nil,b=nil); true; end
303
- end; end
301
+ Barometer::Measurement.any_instance.stubs(:windy?).returns(true)
304
302
  @weather.windy?.should be_true
305
303
  end
306
304
 
@@ -308,9 +306,7 @@ describe "Weather" do
308
306
  wunderground = Barometer::Measurement.new(:wunderground)
309
307
  wunderground.success = true
310
308
  @weather.measurements << wunderground
311
- module Barometer; class Barometer::Measurement
312
- def windy?(a=nil,b=nil); false; end
313
- end; end
309
+ Barometer::Measurement.any_instance.stubs(:windy?).returns(false)
314
310
  @weather.windy?.should be_false
315
311
  end
316
312
 
@@ -338,9 +334,7 @@ describe "Weather" do
338
334
  wunderground = Barometer::Measurement.new(:wunderground)
339
335
  wunderground.success = true
340
336
  @weather.measurements << wunderground
341
- module Barometer; class Barometer::Measurement
342
- def wet?(a=nil,b=nil); true; end
343
- end; end
337
+ Barometer::Measurement.any_instance.stubs(:wet?).returns(true)
344
338
  @weather.wet?.should be_true
345
339
  end
346
340
 
@@ -348,9 +342,7 @@ describe "Weather" do
348
342
  wunderground = Barometer::Measurement.new(:wunderground)
349
343
  wunderground.success = true
350
344
  @weather.measurements << wunderground
351
- module Barometer; class Barometer::Measurement
352
- def wet?(a=nil,b=nil); false; end
353
- end; end
345
+ Barometer::Measurement.any_instance.stubs(:wet?).returns(false)
354
346
  @weather.wet?.should be_false
355
347
  end
356
348
 
@@ -378,9 +370,7 @@ describe "Weather" do
378
370
  wunderground = Barometer::Measurement.new(:wunderground)
379
371
  wunderground.success = true
380
372
  @weather.measurements << wunderground
381
- module Barometer; class Barometer::Measurement
382
- def day?(a=nil); true; end
383
- end; end
373
+ Barometer::Measurement.any_instance.stubs(:day?).returns(true)
384
374
  @weather.day?.should be_true
385
375
  @weather.night?.should be_false
386
376
  end
@@ -389,9 +379,7 @@ describe "Weather" do
389
379
  wunderground = Barometer::Measurement.new(:wunderground)
390
380
  wunderground.success = true
391
381
  @weather.measurements << wunderground
392
- module Barometer; class Barometer::Measurement
393
- def day?(a=nil); false; end
394
- end; end
382
+ Barometer::Measurement.any_instance.stubs(:day?).returns(false)
395
383
  @weather.day?.should be_false
396
384
  @weather.night?.should be_true
397
385
  end
@@ -414,12 +402,8 @@ describe "Weather" do
414
402
  wunderground = Barometer::Measurement.new(:wunderground)
415
403
  wunderground.success = true
416
404
  @weather.measurements << wunderground
417
- module Barometer; class Barometer::Measurement
418
- def day?(a=nil); true; end
419
- end; end
420
- module Barometer; class Barometer::Measurement
421
- def sunny?(a=nil,b=nil); true; end
422
- end; end
405
+ Barometer::Measurement.any_instance.stubs(:day?).returns(true)
406
+ Barometer::Measurement.any_instance.stubs(:sunny?).returns(true)
423
407
  @weather.sunny?.should be_true
424
408
  end
425
409
 
@@ -427,12 +411,8 @@ describe "Weather" do
427
411
  wunderground = Barometer::Measurement.new(:wunderground)
428
412
  wunderground.success = true
429
413
  @weather.measurements << wunderground
430
- module Barometer; class Barometer::Measurement
431
- def day?(a=nil); true; end
432
- end; end
433
- module Barometer; class Barometer::Measurement
434
- def sunny?(a=nil,b=nil); false; end
435
- end; end
414
+ Barometer::Measurement.any_instance.stubs(:day?).returns(true)
415
+ Barometer::Measurement.any_instance.stubs(:sunny?).returns(false)
436
416
  @weather.sunny?.should be_false
437
417
  end
438
418
 
@@ -440,13 +420,8 @@ describe "Weather" do
440
420
  wunderground = Barometer::Measurement.new(:wunderground)
441
421
  wunderground.success = true
442
422
  @weather.measurements << wunderground
443
- module Barometer; class Barometer::Measurement
444
- def sunny?(a=nil,b=nil); true; end
445
- end; end
446
- @weather.sunny?.should be_true
447
- module Barometer; class Barometer::Measurement
448
- def day?(a=nil); false; end
449
- end; end
423
+ Barometer::Measurement.any_instance.stubs(:sunny?).returns(true)
424
+ Barometer::Measurement.any_instance.stubs(:day?).returns(false)
450
425
  @weather.sunny?.should be_false
451
426
  end
452
427
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barometer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark G
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-15 00:00:00 -06:00
12
+ date: 2009-05-20 00:00:00 -06:00
13
13
  default_executable: barometer
14
14
  dependencies: []
15
15
 
@@ -54,12 +54,9 @@ files:
54
54
  - lib/barometer/formats/zipcode.rb
55
55
  - lib/barometer/formats.rb
56
56
  - lib/barometer/measurements
57
- - lib/barometer/measurements/common.rb
58
- - lib/barometer/measurements/current.rb
59
- - lib/barometer/measurements/forecast.rb
60
- - lib/barometer/measurements/forecast_array.rb
61
57
  - lib/barometer/measurements/measurement.rb
62
- - lib/barometer/measurements/night.rb
58
+ - lib/barometer/measurements/result.rb
59
+ - lib/barometer/measurements/result_array.rb
63
60
  - lib/barometer/query.rb
64
61
  - lib/barometer/services.rb
65
62
  - lib/barometer/translations
@@ -151,12 +148,9 @@ files:
151
148
  - spec/formats/weather_id_spec.rb
152
149
  - spec/formats/zipcode_spec.rb
153
150
  - spec/measurements
154
- - spec/measurements/common_spec.rb
155
- - spec/measurements/current_spec.rb
156
- - spec/measurements/forecast_array_spec.rb
157
- - spec/measurements/forecast_spec.rb
158
151
  - spec/measurements/measurement_spec.rb
159
- - spec/measurements/night_measurement_spec.rb
152
+ - spec/measurements/result_array_spec.rb
153
+ - spec/measurements/result_spec.rb
160
154
  - spec/query_spec.rb
161
155
  - spec/spec_helper.rb
162
156
  - spec/weather_services
@@ -1,113 +0,0 @@
1
- module Barometer
2
- #
3
- # Common Measurement
4
- #
5
- # Code common to both Current and Forecast Measurements
6
- #
7
- class Measurement::Common
8
-
9
- attr_reader :humidity, :icon, :condition
10
- attr_reader :wind, :sun
11
- attr_accessor :metric
12
-
13
- def initialize(metric=true)
14
- @metric = metric
15
- end
16
-
17
- def metric?; metric; end
18
-
19
- # accessors (with input checking)
20
- #
21
- def humidity=(humidity)
22
- raise ArgumentError unless
23
- (humidity.is_a?(Fixnum) || humidity.is_a?(Float))
24
- @humidity = humidity
25
- end
26
-
27
- def icon=(icon)
28
- raise ArgumentError unless icon.is_a?(String)
29
- @icon = icon
30
- end
31
-
32
- def condition=(condition)
33
- raise ArgumentError unless condition.is_a?(String)
34
- @condition = condition
35
- end
36
-
37
- def wind=(wind)
38
- raise ArgumentError unless wind.is_a?(Data::Speed)
39
- @wind = wind
40
- end
41
-
42
- def sun=(sun)
43
- raise ArgumentError unless (sun.is_a?(Data::Sun) || sun.nil?)
44
- @sun = sun
45
- end
46
-
47
- #
48
- # helpers
49
- #
50
-
51
- # creates "?" helpers for all attributes (which maps to nil?)
52
- #
53
- def method_missing(method,*args)
54
- # if the method ends in ?, then strip it off and see if we
55
- # respond to the method without the ?
56
- if (call_method = method.to_s.chomp!("?")) && respond_to?(call_method)
57
- return send(call_method).nil? ? false : true
58
- else
59
- super(method,*args)
60
- end
61
- end
62
-
63
- #
64
- # answer simple questions
65
- #
66
-
67
- def windy?(threshold=10)
68
- raise ArgumentError unless (threshold.is_a?(Fixnum) || threshold.is_a?(Float))
69
- return nil unless wind?
70
- wind.to_f(metric?) >= threshold.to_f
71
- end
72
-
73
- def day?(time)
74
- return nil unless time && sun?
75
- sun.after_rise?(time) && sun.before_set?(time)
76
- end
77
-
78
- def wet?(wet_icons=nil, humidity_threshold=99)
79
- result = nil
80
- result ||= _wet_by_icon?(wet_icons) if icon?
81
- result ||= _wet_by_humidity?(humidity_threshold) if humidity?
82
- result
83
- end
84
-
85
- def sunny?(time, sunny_icons=nil)
86
- return nil unless time
87
- is_day = day?(time)
88
- return nil if is_day.nil?
89
- is_day && _sunny_by_icon?(sunny_icons)
90
- end
91
-
92
- private
93
-
94
- def _wet_by_humidity?(threshold=99)
95
- raise ArgumentError unless (threshold.is_a?(Fixnum) || threshold.is_a?(Float))
96
- return nil unless humidity?
97
- humidity.to_f >= threshold.to_f
98
- end
99
-
100
- def _wet_by_icon?(wet_icons=nil)
101
- raise ArgumentError unless (wet_icons.nil? || wet_icons.is_a?(Array))
102
- return nil unless (icon? && wet_icons)
103
- wet_icons.include?(icon.to_s.downcase)
104
- end
105
-
106
- def _sunny_by_icon?(sunny_icons=nil)
107
- raise ArgumentError unless (sunny_icons.nil? || sunny_icons.is_a?(Array))
108
- return nil unless (icon? && sunny_icons)
109
- sunny_icons.include?(icon.to_s.downcase)
110
- end
111
-
112
- end
113
- end