barometer 0.5.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 @@
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- This document is intended only for use by authorized licensees of The --> <!-- Weather Channel. Unauthorized use is prohibited. Copyright 1995-2009, --> <!-- The Weather Channel Interactive, Inc. All Rights Reserved. --> <search ver="3.0"> <loc id="USCA0987" type="1">San Francisco, CA</loc> <loc id="USCA1085" type="1">South San Francisco, CA</loc> </search>
|
@@ -0,0 +1 @@
|
|
1
|
+
<aws:weather xmlns:aws="http://www.aws.com/aws"><aws:api version="2.0" /><aws:WebURL>http://weather.weatherbug.com/CA/Los Angeles-weather.html?ZCode=Z5546&Units=1&stat=LSNGH</aws:WebURL><aws:InputLocationURL>http://weather.weatherbug.com/CA/Beverly Hills-weather.html?ZCode=Z5546&Units=1</aws:InputLocationURL><aws:ob><aws:ob-date><aws:year number="2009" /><aws:month number="5" text="May" abbrv="May" /><aws:day number="15" text="Friday" abbrv="Fri" /><aws:hour number="11" hour-24="11" /><aws:minute number="00" /><aws:second number="02" /><aws:am-pm abbrv="AM" /><aws:time-zone offset="-7" text="Pacific Daylight Time" abbrv="PDT" /></aws:ob-date><aws:requested-station-id /><aws:station-id>LSNGH</aws:station-id><aws:station>Milken Community HS</aws:station><aws:city-state zipcode="90049">Los Angeles, CA</aws:city-state><aws:country>USA</aws:country><aws:latitude>34.1258316040039</aws:latitude><aws:longitude>-118.478332519531</aws:longitude><aws:site-url>http://www.milkenschool.org/</aws:site-url><aws:aux-temp units="&deg;C">23.5</aws:aux-temp><aws:aux-temp-rate units="&deg;C">-17.8</aws:aux-temp-rate><aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond023.gif">Hazy</aws:current-condition><aws:dew-point units="&deg;C">14.4444444444444</aws:dew-point><aws:elevation units="m">383</aws:elevation><aws:feels-like units="&deg;C">22</aws:feels-like><aws:gust-time><aws:year number="2009" /><aws:month number="5" text="May" abbrv="May" /><aws:day number="15" text="Friday" abbrv="Fri" /><aws:hour number="10" hour-24="10" /><aws:minute number="53" /><aws:second number="00" /><aws:am-pm abbrv="AM" /><aws:time-zone offset="-7" text="Pacific Daylight Time" abbrv="PDT" /></aws:gust-time><aws:gust-direction>SSE</aws:gust-direction><aws:gust-speed units="km/h">16</aws:gust-speed><aws:humidity units="%">62</aws:humidity><aws:humidity-high units="%">100</aws:humidity-high><aws:humidity-low units="%">62</aws:humidity-low><aws:humidity-rate>-9</aws:humidity-rate><aws:indoor-temp units="&deg;C">46</aws:indoor-temp><aws:indoor-temp-rate units="&deg;C">1</aws:indoor-temp-rate><aws:light>34.2</aws:light><aws:light-rate>0.4</aws:light-rate><aws:moon-phase moon-phase-img="http://api.wxbug.net/images/moonphase/mphase18.gif">71</aws:moon-phase><aws:pressure units="mb">1011.31</aws:pressure><aws:pressure-high units="mb">1,011.36</aws:pressure-high><aws:pressure-low units="mb">1,010.39</aws:pressure-low><aws:pressure-rate units="mb/h">0.23</aws:pressure-rate><aws:rain-month units="mm">0.00</aws:rain-month><aws:rain-rate units="mm/h">0.00</aws:rain-rate><aws:rain-rate-max units="mm/h">0.00</aws:rain-rate-max><aws:rain-today units="mm">0.00</aws:rain-today><aws:rain-year units="mm">38.35</aws:rain-year><aws:temp units="&deg;C">22.2</aws:temp><aws:temp-high units="&deg;C">22</aws:temp-high><aws:temp-low units="&deg;C">13</aws:temp-low><aws:temp-rate units="&deg;C/h">2.2</aws:temp-rate><aws:sunrise><aws:year number="2009" /><aws:month number="5" text="May" abbrv="May" /><aws:day number="15" text="Friday" abbrv="Fri" /><aws:hour number="5" hour-24="05" /><aws:minute number="52" /><aws:second number="17" /><aws:am-pm abbrv="AM" /><aws:time-zone offset="-7" text="Pacific Daylight Time" abbrv="PDT" /></aws:sunrise><aws:sunset><aws:year number="2009" /><aws:month number="5" text="May" abbrv="May" /><aws:day number="15" text="Friday" abbrv="Fri" /><aws:hour number="7" hour-24="19" /><aws:minute number="48" /><aws:second number="37" /><aws:am-pm abbrv="PM" /><aws:time-zone offset="-7" text="Pacific Daylight Time" abbrv="PDT" /></aws:sunset><aws:wet-bulb units="&deg;C">17.39</aws:wet-bulb><aws:wind-speed units="km/h">11</aws:wind-speed><aws:wind-speed-avg units="km/h">8</aws:wind-speed-avg><aws:wind-direction>SE</aws:wind-direction><aws:wind-direction-avg>SE</aws:wind-direction-avg></aws:ob></aws:weather>
|
@@ -0,0 +1 @@
|
|
1
|
+
<aws:weather xmlns:aws="http://www.aws.com/aws"><aws:api version="2.0" /><aws:WebURL>http://weather.weatherbug.com/CA/Beverly Hills-weather/local-forecast/7-day-forecast.html?ZCode=Z5546&Units=1</aws:WebURL><aws:forecasts type="Detailed" date="5/15/2009 8:26:00 AM"><aws:location><aws:city>Beverly Hills</aws:city><aws:state>CA</aws:state><aws:zip>90210</aws:zip><aws:zone>CA041</aws:zone></aws:location><aws:forecast><aws:title alttitle="FRI">Friday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Friday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the upper 60s to mid 70s at the beaches to the lower 80s inland.</aws:prediction><aws:high units="&deg;C">27</aws:high><aws:low units="&deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="SAT">Saturday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Saturday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the lower to mid 70s at the beaches to the lower to mid 80s inland.</aws:prediction><aws:high units="&deg;C">28</aws:high><aws:low units="&deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="SUN">Sunday</aws:title><aws:short-prediction>Partly Cloudy</aws:short-prediction><aws:image isNight="0" icon="cond003.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond003.gif</aws:image><aws:description>Sunday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then sunny. Highs in the lower to mid 70s at the beaches to the lower to mid 80s inland.</aws:prediction><aws:high units="&deg;C">28</aws:high><aws:low units="&deg;C">17</aws:low></aws:forecast><aws:forecast><aws:title alttitle="MON">Monday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Monday</aws:description><aws:prediction>Areas of low clouds and fog in the morning then mostly sunny. Highs around 70 at the beaches to around 80 inland.</aws:prediction><aws:high units="&deg;C">26</aws:high><aws:low units="&deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="TUE">Tuesday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Tuesday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&deg;C">25</aws:high><aws:low units="&deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="WED">Wednesday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Wednesday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&deg;C">24</aws:high><aws:low units="&deg;C">16</aws:low></aws:forecast><aws:forecast><aws:title alttitle="THU">Thursday</aws:title><aws:short-prediction>Mostly Sunny</aws:short-prediction><aws:image isNight="0" icon="cond026.gif">http://deskwx.weatherbug.com/images/Forecast/icons/cond026.gif</aws:image><aws:description>Thursday</aws:description><aws:prediction>Night through morning low clouds and fog...otherwise mostly clear. Lows around 60. Highs in the mid to upper 60s at the beaches to the 70s inland.</aws:prediction><aws:high units="&deg;C">24</aws:high><aws:low units="&deg;C">--</aws:low></aws:forecast></aws:forecasts></aws:weather>
|
@@ -167,6 +167,16 @@ describe "Query::WeatherID" do
|
|
167
167
|
new_query.geo.should be_nil
|
168
168
|
end
|
169
169
|
|
170
|
+
it "converts from icao" do
|
171
|
+
query = Barometer::Query.new(@icao)
|
172
|
+
query.format.should == :icao
|
173
|
+
new_query = Query::Format::WeatherID.to(query)
|
174
|
+
new_query.q.should == "USCA0987"
|
175
|
+
new_query.country_code.should == "US"
|
176
|
+
new_query.format.should == :weather_id
|
177
|
+
new_query.geo.should_not be_nil
|
178
|
+
end
|
179
|
+
|
170
180
|
it "returns nil for other formats" do
|
171
181
|
query = Barometer::Query.new(@weather_id)
|
172
182
|
query.format.should == :weather_id
|
@@ -177,11 +187,6 @@ describe "Query::WeatherID" do
|
|
177
187
|
query.format.should == :postalcode
|
178
188
|
new_query = Query::Format::WeatherID.to(query)
|
179
189
|
new_query.should be_nil
|
180
|
-
|
181
|
-
query = Barometer::Query.new(@icao)
|
182
|
-
query.format.should == :icao
|
183
|
-
new_query = Query::Format::WeatherID.to(query)
|
184
|
-
new_query.should be_nil
|
185
190
|
end
|
186
191
|
|
187
192
|
end
|
@@ -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 =
|
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 =
|
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 "
|
143
|
+
describe "answer simple questions, like" do
|
219
144
|
|
220
145
|
before(:each) do
|
221
|
-
@current =
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
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
|