barometer 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +51 -9
- data/VERSION.yml +2 -2
- data/bin/barometer +57 -7
- data/lib/barometer.rb +11 -0
- data/lib/barometer/base.rb +3 -0
- data/lib/barometer/data.rb +11 -6
- data/lib/barometer/data/sun.rb +10 -0
- data/lib/barometer/data/zone.rb +79 -188
- data/lib/barometer/formats/coordinates.rb +4 -1
- data/lib/barometer/formats/geocode.rb +9 -7
- data/lib/barometer/formats/icao.rb +2 -2
- data/lib/barometer/formats/weather_id.rb +2 -2
- data/lib/barometer/measurements/common.rb +113 -0
- data/lib/barometer/{data → measurements}/current.rb +17 -42
- data/lib/barometer/measurements/forecast.rb +62 -0
- data/lib/barometer/measurements/forecast_array.rb +72 -0
- data/lib/barometer/{data → measurements}/measurement.rb +57 -45
- data/lib/barometer/measurements/night.rb +27 -0
- data/lib/barometer/query.rb +55 -5
- data/lib/barometer/services.rb +3 -1
- data/lib/barometer/translations/icao_country_codes.yml +274 -1
- data/lib/barometer/translations/weather_country_codes.yml +189 -6
- data/lib/barometer/translations/zone_codes.yml +360 -0
- data/lib/barometer/weather.rb +5 -4
- data/lib/barometer/weather_services/google.rb +19 -35
- data/lib/barometer/weather_services/service.rb +113 -255
- data/lib/barometer/weather_services/weather_bug.rb +291 -2
- data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
- data/lib/barometer/weather_services/wunderground.rb +83 -89
- data/lib/barometer/weather_services/yahoo.rb +44 -91
- data/lib/barometer/web_services/geocode.rb +1 -0
- data/lib/barometer/web_services/timezone.rb +40 -0
- data/lib/barometer/web_services/weather_id.rb +17 -2
- data/lib/demometer/demometer.rb +28 -0
- data/lib/demometer/public/css/master.css +259 -1
- data/lib/demometer/public/css/print.css +94 -0
- data/lib/demometer/public/css/syntax.css +64 -0
- data/lib/demometer/public/images/link-out.gif +0 -0
- data/lib/demometer/views/about.erb +10 -0
- data/lib/demometer/views/index.erb +2 -0
- data/lib/demometer/views/layout.erb +3 -2
- data/lib/demometer/views/measurement.erb +4 -1
- data/lib/demometer/views/readme.erb +116 -88
- data/spec/data/sun_spec.rb +53 -0
- data/spec/data/zone_spec.rb +330 -100
- data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
- data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
- data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
- data/spec/formats/weather_id_spec.rb +10 -5
- data/spec/measurements/common_spec.rb +352 -0
- data/spec/{data → measurements}/current_spec.rb +40 -103
- data/spec/measurements/forecast_array_spec.rb +165 -0
- data/spec/measurements/forecast_spec.rb +135 -0
- data/spec/{data → measurements}/measurement_spec.rb +86 -107
- data/spec/measurements/night_measurement_spec.rb +49 -0
- data/spec/query_spec.rb +12 -2
- data/spec/spec_helper.rb +28 -1
- data/spec/weather_services/google_spec.rb +27 -117
- data/spec/weather_services/services_spec.rb +49 -1024
- data/spec/weather_services/weather_bug_spec.rb +274 -0
- data/spec/weather_services/weather_dot_com_spec.rb +45 -125
- data/spec/weather_services/wunderground_spec.rb +42 -136
- data/spec/weather_services/yahoo_spec.rb +26 -116
- data/spec/weather_spec.rb +45 -45
- metadata +27 -11
- data/lib/barometer/data/forecast.rb +0 -84
- data/lib/barometer/data/night.rb +0 -69
- data/lib/barometer/extensions/graticule.rb +0 -51
- data/spec/data/forecast_spec.rb +0 -192
- data/spec/data/night_measurement_spec.rb +0 -136
@@ -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
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Forecast Measurement" do
|
4
|
+
|
5
|
+
describe "when initialized" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@forecast = Measurement::Forecast.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "responds to date" do
|
12
|
+
@forecast.date.should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "responds to low" do
|
16
|
+
@forecast.low.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "responds to high" do
|
20
|
+
@forecast.high.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "responds to pop" do
|
24
|
+
@forecast.pop.should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "responds to night" do
|
28
|
+
@forecast.night.should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when writing data" do
|
34
|
+
|
35
|
+
before(:each) do
|
36
|
+
@forecast = Measurement::Forecast.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "only accepts Date for date" do
|
40
|
+
invalid_data = 1
|
41
|
+
invalid_data.class.should_not == Date
|
42
|
+
lambda { @forecast.date = invalid_data }.should raise_error(ArgumentError)
|
43
|
+
|
44
|
+
valid_data = Date.new
|
45
|
+
valid_data.class.should == Date
|
46
|
+
lambda { @forecast.date = valid_data }.should_not raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "only accepts Data::Temperature for high" do
|
50
|
+
invalid_data = 1
|
51
|
+
invalid_data.class.should_not == Data::Temperature
|
52
|
+
lambda { @forecast.high = invalid_data }.should raise_error(ArgumentError)
|
53
|
+
|
54
|
+
valid_data = Data::Temperature.new
|
55
|
+
valid_data.class.should == Data::Temperature
|
56
|
+
lambda { @forecast.high = valid_data }.should_not raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "only accepts Data::Temperature for low" do
|
60
|
+
invalid_data = 1
|
61
|
+
invalid_data.class.should_not == Data::Temperature
|
62
|
+
lambda { @forecast.low = invalid_data }.should raise_error(ArgumentError)
|
63
|
+
|
64
|
+
valid_data = Data::Temperature.new
|
65
|
+
valid_data.class.should == Data::Temperature
|
66
|
+
lambda { @forecast.low = valid_data }.should_not raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "only accepts Fixnum for pop" do
|
70
|
+
invalid_data = "test"
|
71
|
+
invalid_data.class.should_not == Fixnum
|
72
|
+
lambda { @forecast.pop = invalid_data }.should raise_error(ArgumentError)
|
73
|
+
|
74
|
+
valid_data = 50
|
75
|
+
valid_data.class.should == Fixnum
|
76
|
+
lambda { @forecast.pop = valid_data }.should_not raise_error(ArgumentError)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "only accepts Measurement::ForecastNight for night" do
|
80
|
+
invalid_data = 1
|
81
|
+
invalid_data.class.should_not == Measurement::ForecastNight
|
82
|
+
lambda { @forecast.night = invalid_data }.should raise_error(ArgumentError)
|
83
|
+
|
84
|
+
valid_data = Measurement::ForecastNight.new
|
85
|
+
valid_data.class.should == Measurement::ForecastNight
|
86
|
+
lambda { @forecast.night = valid_data }.should_not raise_error(ArgumentError)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "answer simple questions, like" do
|
92
|
+
|
93
|
+
before(:each) do
|
94
|
+
@forecast = Measurement::Forecast.new
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "wet?" do
|
98
|
+
|
99
|
+
describe "wet_by_pop?" do
|
100
|
+
|
101
|
+
it "requires real threshold number (or nil)" do
|
102
|
+
lambda { @forecast.send("_wet_by_pop?","invalid") }.should raise_error(ArgumentError)
|
103
|
+
lambda { @forecast.send("_wet_by_pop?") }.should_not raise_error(ArgumentError)
|
104
|
+
lambda { @forecast.send("_wet_by_pop?",50) }.should_not raise_error(ArgumentError)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "returns nil when no pop" do
|
108
|
+
@forecast.pop?.should be_false
|
109
|
+
@forecast.send("_wet_by_pop?",50).should be_nil
|
110
|
+
@forecast.wet?.should be_nil
|
111
|
+
@forecast.pop = 60
|
112
|
+
@forecast.pop?.should be_true
|
113
|
+
@forecast.send("_wet_by_pop?",50).should_not be_nil
|
114
|
+
@forecast.wet?.should_not be_nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it "return true when current pop over threshold" do
|
118
|
+
@forecast.pop = 60
|
119
|
+
@forecast.send("_wet_by_pop?",50).should be_true
|
120
|
+
@forecast.wet?.should be_true
|
121
|
+
end
|
122
|
+
|
123
|
+
it "return false when current pop under threshold" do
|
124
|
+
@forecast.pop = 40
|
125
|
+
@forecast.send("_wet_by_pop?",50).should be_false
|
126
|
+
@forecast.wet?.should be_false
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -5,7 +5,7 @@ describe "Measurement" do
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@measurement =
|
8
|
+
@measurement = Barometer::Measurement.new
|
9
9
|
end
|
10
10
|
|
11
11
|
it "responds to source" do
|
@@ -14,7 +14,7 @@ describe "Measurement" do
|
|
14
14
|
|
15
15
|
it "stores the source" do
|
16
16
|
source = :wunderground
|
17
|
-
measurement =
|
17
|
+
measurement = Barometer::Measurement.new(source)
|
18
18
|
measurement.source.should_not be_nil
|
19
19
|
measurement.source.should == source
|
20
20
|
end
|
@@ -48,7 +48,7 @@ describe "Measurement" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "responds to current?" do
|
51
|
-
@measurement.current?.should
|
51
|
+
@measurement.current?.should be_true
|
52
52
|
end
|
53
53
|
|
54
54
|
it "responds to metric" do
|
@@ -76,7 +76,7 @@ describe "Measurement" do
|
|
76
76
|
describe "when writing data" do
|
77
77
|
|
78
78
|
before(:each) do
|
79
|
-
@measurement =
|
79
|
+
@measurement = Barometer::Measurement.new
|
80
80
|
end
|
81
81
|
|
82
82
|
it "only accepts Symbol for source" do
|
@@ -101,21 +101,21 @@ describe "Measurement" do
|
|
101
101
|
|
102
102
|
it "only accepts Data::CurrentMeasurement for current" do
|
103
103
|
invalid_data = "invalid"
|
104
|
-
invalid_data.class.should_not ==
|
104
|
+
invalid_data.class.should_not == Measurement::Current
|
105
105
|
lambda { @measurement.current = invalid_data }.should raise_error(ArgumentError)
|
106
106
|
|
107
|
-
valid_data =
|
108
|
-
valid_data.class.should ==
|
107
|
+
valid_data = Measurement::Current.new
|
108
|
+
valid_data.class.should == Measurement::Current
|
109
109
|
lambda { @measurement.current = valid_data }.should_not raise_error(ArgumentError)
|
110
110
|
end
|
111
111
|
|
112
|
-
it "only accepts
|
112
|
+
it "only accepts Data::ForecastArray for forecast" do
|
113
113
|
invalid_data = 1
|
114
|
-
invalid_data.class.should_not ==
|
114
|
+
invalid_data.class.should_not == Measurement::ForecastArray
|
115
115
|
lambda { @measurement.forecast = invalid_data }.should raise_error(ArgumentError)
|
116
116
|
|
117
|
-
valid_data =
|
118
|
-
valid_data.class.should ==
|
117
|
+
valid_data = Measurement::ForecastArray.new
|
118
|
+
valid_data.class.should == Measurement::ForecastArray
|
119
119
|
lambda { @measurement.forecast = valid_data }.should_not raise_error(ArgumentError)
|
120
120
|
end
|
121
121
|
|
@@ -184,7 +184,7 @@ describe "Measurement" do
|
|
184
184
|
describe "and the helpers" do
|
185
185
|
|
186
186
|
before(:each) do
|
187
|
-
@measurement =
|
187
|
+
@measurement = Barometer::Measurement.new
|
188
188
|
end
|
189
189
|
|
190
190
|
it "changes state to successful (if successful)" do
|
@@ -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 =
|
197
|
+
@measurement.current = Measurement::Current.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 =
|
206
|
+
@measurement.current = Measurement::Current.new
|
207
207
|
@measurement.current.temperature = Data::Temperature.new
|
208
208
|
@measurement.current.temperature.c = 10
|
209
209
|
@measurement.success!
|
@@ -224,11 +224,11 @@ describe "Measurement" do
|
|
224
224
|
|
225
225
|
it "indicates if current" do
|
226
226
|
@measurement.current.should be_nil
|
227
|
-
@measurement.current?.should
|
227
|
+
@measurement.current?.should be_true
|
228
228
|
|
229
|
-
@measurement.current =
|
229
|
+
@measurement.current = Measurement::Current.new
|
230
230
|
@measurement.current.current_at.should be_nil
|
231
|
-
@measurement.current?.should
|
231
|
+
@measurement.current?.should be_true
|
232
232
|
|
233
233
|
@measurement.current.current_at = Data::LocalTime.new(9,0,0)
|
234
234
|
@measurement.current?.should be_true
|
@@ -255,7 +255,7 @@ describe "Measurement" do
|
|
255
255
|
describe "changing units" do
|
256
256
|
|
257
257
|
before(:each) do
|
258
|
-
@measurement =
|
258
|
+
@measurement = Barometer::Measurement.new
|
259
259
|
end
|
260
260
|
|
261
261
|
it "indicates if metric?" do
|
@@ -286,13 +286,13 @@ describe "Measurement" do
|
|
286
286
|
describe "when searching forecasts using 'for'" do
|
287
287
|
|
288
288
|
before(:each) do
|
289
|
-
@measurement =
|
289
|
+
@measurement = Barometer::Measurement.new
|
290
290
|
|
291
291
|
# create a measurement object with a forecast array that includes
|
292
292
|
# dates for 4 consecutive days starting with tommorrow
|
293
|
-
@measurement.forecast =
|
293
|
+
@measurement.forecast = Measurement::ForecastArray.new
|
294
294
|
1.upto(4) do |i|
|
295
|
-
forecast_measurement =
|
295
|
+
forecast_measurement = Measurement::Forecast.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 =
|
305
|
+
@measurement.forecast = Measurement::ForecastArray.new
|
306
306
|
@measurement.forecast.size.should == 0
|
307
307
|
@measurement.for.should be_nil
|
308
308
|
end
|
@@ -347,85 +347,70 @@ describe "Measurement" do
|
|
347
347
|
describe "when answering the simple questions," do
|
348
348
|
|
349
349
|
before(:each) do
|
350
|
-
@measurement =
|
350
|
+
@measurement = Barometer::Measurement.new(:wunderground)
|
351
|
+
@measurement.current = Measurement::Current.new
|
351
352
|
@now = Data::LocalDateTime.parse("2009-05-01 2:05 pm")
|
352
353
|
end
|
353
354
|
|
355
|
+
# def windy?(time_string=nil, threshold=10)
|
356
|
+
# local_time = Data::LocalTime.parse(time_string)
|
357
|
+
# if current?(local_time)
|
358
|
+
# return nil unless current
|
359
|
+
# current.windy?(threshold)
|
360
|
+
# else
|
361
|
+
# return nil unless forecast && (future = forecast[local_time])
|
362
|
+
# future.windy?(threshold)
|
363
|
+
# end
|
364
|
+
# end
|
365
|
+
|
354
366
|
describe "windy?" do
|
355
367
|
|
356
|
-
it "
|
357
|
-
|
358
|
-
|
359
|
-
lambda { @measurement.windy?(1.1) }.should_not raise_error(ArgumentError)
|
360
|
-
end
|
361
|
-
|
362
|
-
it "requires time as a Time object" do
|
363
|
-
#lambda { @measurement.windy?(1,false) }.should raise_error(ArgumentError)
|
364
|
-
lambda { @measurement.windy?(1,@now) }.should_not raise_error(ArgumentError)
|
365
|
-
end
|
366
|
-
|
367
|
-
it "returns true if a source returns true" do
|
368
|
-
module Barometer; class WeatherService
|
369
|
-
def self.windy?(a=nil,b=nil,c=nil); true; end
|
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
|
370
371
|
end; end
|
371
372
|
@measurement.windy?.should be_true
|
372
373
|
end
|
373
374
|
|
374
|
-
it "returns false if a
|
375
|
-
module Barometer; class
|
376
|
-
def
|
375
|
+
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
|
377
378
|
end; end
|
378
379
|
@measurement.windy?.should be_false
|
379
380
|
end
|
380
381
|
|
381
382
|
end
|
382
383
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
end
|
402
|
-
|
403
|
-
it "returns false if a measurement returns false" do
|
404
|
-
module Barometer; class WeatherService
|
405
|
-
def self.wet?(a=nil,b=nil,c=nil); false; end
|
406
|
-
end; end
|
407
|
-
@measurement.wet?.should be_false
|
408
|
-
end
|
409
|
-
|
410
|
-
end
|
411
|
-
|
384
|
+
describe "wet?" do
|
385
|
+
|
386
|
+
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
|
390
|
+
@measurement.wet?.should be_true
|
391
|
+
end
|
392
|
+
|
393
|
+
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
|
397
|
+
@measurement.wet?.should be_false
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
|
412
402
|
describe "day?" do
|
413
|
-
|
414
|
-
it "
|
415
|
-
|
416
|
-
|
417
|
-
end
|
418
|
-
|
419
|
-
it "returns true if a source returns true" do
|
420
|
-
module Barometer; class WeatherService
|
421
|
-
def self.day?(a=nil,b=nil); true; end
|
403
|
+
|
404
|
+
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
|
422
407
|
end; end
|
423
408
|
@measurement.day?.should be_true
|
424
409
|
end
|
425
|
-
|
426
|
-
it "returns false if
|
427
|
-
module Barometer; class
|
428
|
-
def
|
410
|
+
|
411
|
+
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
|
429
414
|
end; end
|
430
415
|
@measurement.day?.should be_false
|
431
416
|
end
|
@@ -434,45 +419,39 @@ describe "Measurement" do
|
|
434
419
|
|
435
420
|
describe "sunny?" do
|
436
421
|
|
437
|
-
it "
|
438
|
-
|
439
|
-
|
440
|
-
end
|
441
|
-
|
442
|
-
it "returns true if a source returns true" do
|
443
|
-
module Barometer; class WeatherService
|
444
|
-
def self.day?(a=nil,b=nil); true; end
|
422
|
+
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
|
445
425
|
end; end
|
446
|
-
module Barometer; class
|
447
|
-
def
|
426
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
427
|
+
def sunny?(a=nil,b=nil); true; end
|
448
428
|
end; end
|
429
|
+
@measurement.day?.should be_true
|
449
430
|
@measurement.sunny?.should be_true
|
450
431
|
end
|
451
|
-
|
452
|
-
it "returns false if
|
453
|
-
module Barometer; class
|
454
|
-
def
|
432
|
+
|
433
|
+
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
|
455
436
|
end; end
|
456
|
-
module Barometer; class
|
457
|
-
def
|
437
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
438
|
+
def sunny?(a=nil,b=nil); false; end
|
458
439
|
end; end
|
440
|
+
@measurement.day?.should be_true
|
459
441
|
@measurement.sunny?.should be_false
|
460
442
|
end
|
461
443
|
|
462
444
|
it "returns false if night time" do
|
463
|
-
module Barometer; class
|
464
|
-
def
|
445
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
446
|
+
def day?(a=nil); false; end
|
465
447
|
end; end
|
466
|
-
module Barometer; class
|
467
|
-
def
|
468
|
-
end; end
|
469
|
-
@measurement.sunny?.should be_true
|
470
|
-
module Barometer; class WeatherService
|
471
|
-
def self.day?(a=nil,b=nil); false; end
|
448
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
449
|
+
def sunny?(a=nil,b=nil); true; end
|
472
450
|
end; end
|
451
|
+
@measurement.day?.should be_false
|
473
452
|
@measurement.sunny?.should be_false
|
474
453
|
end
|
475
|
-
|
454
|
+
|
476
455
|
end
|
477
456
|
|
478
457
|
end
|