barometer 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +78 -70
- data/VERSION.yml +2 -2
- data/bin/barometer +100 -37
- data/lib/barometer.rb +12 -8
- data/lib/barometer/base.rb +48 -20
- data/lib/barometer/data.rb +5 -1
- data/lib/barometer/data/current.rb +23 -15
- data/lib/barometer/data/distance.rb +15 -5
- data/lib/barometer/data/forecast.rb +23 -5
- data/lib/barometer/data/geo.rb +16 -54
- data/lib/barometer/data/local_datetime.rb +137 -0
- data/lib/barometer/data/local_time.rb +134 -0
- data/lib/barometer/data/location.rb +6 -1
- data/lib/barometer/data/measurement.rb +71 -42
- data/lib/barometer/data/night.rb +69 -0
- data/lib/barometer/data/pressure.rb +15 -5
- data/lib/barometer/data/speed.rb +16 -5
- data/lib/barometer/data/sun.rb +8 -20
- data/lib/barometer/data/temperature.rb +22 -9
- data/lib/barometer/data/units.rb +10 -19
- data/lib/barometer/data/zone.rb +135 -9
- data/lib/barometer/formats.rb +12 -0
- data/lib/barometer/formats/coordinates.rb +42 -0
- data/lib/barometer/formats/format.rb +46 -0
- data/lib/barometer/formats/geocode.rb +51 -0
- data/lib/barometer/formats/icao.rb +37 -0
- data/lib/barometer/formats/postalcode.rb +22 -0
- data/lib/barometer/formats/short_zipcode.rb +17 -0
- data/lib/barometer/formats/weather_id.rb +107 -0
- data/lib/barometer/formats/zipcode.rb +31 -0
- data/lib/barometer/query.rb +61 -232
- data/lib/barometer/services.rb +14 -4
- data/lib/barometer/translations/icao_country_codes.yml +9 -0
- data/lib/barometer/translations/weather_country_codes.yml +17 -0
- data/lib/barometer/weather.rb +51 -30
- data/lib/barometer/{services → weather_services}/google.rb +23 -26
- data/lib/barometer/weather_services/noaa.rb +6 -0
- data/lib/barometer/{services → weather_services}/service.rb +101 -92
- data/lib/barometer/weather_services/weather_bug.rb +6 -0
- data/lib/barometer/weather_services/weather_dot_com.rb +261 -0
- data/lib/barometer/{services → weather_services}/wunderground.rb +58 -76
- data/lib/barometer/{services → weather_services}/yahoo.rb +91 -121
- data/lib/barometer/web_services/geocode.rb +33 -0
- data/lib/barometer/web_services/weather_id.rb +37 -0
- data/lib/barometer/web_services/web_service.rb +32 -0
- data/lib/demometer/demometer.rb +31 -4
- data/lib/demometer/views/forecast.erb +20 -0
- data/lib/demometer/views/index.erb +10 -3
- data/lib/demometer/views/measurement.erb +8 -3
- data/lib/demometer/views/readme.erb +63 -24
- data/spec/barometer_spec.rb +18 -36
- data/spec/{data_current_spec.rb → data/current_spec.rb} +73 -49
- data/spec/{data_distance_spec.rb → data/distance_spec.rb} +30 -30
- data/spec/{data_forecast_spec.rb → data/forecast_spec.rb} +57 -15
- data/spec/data/geo_spec.rb +91 -0
- data/spec/data/local_datetime_spec.rb +269 -0
- data/spec/data/local_time_spec.rb +239 -0
- data/spec/{data_location_spec.rb → data/location_spec.rb} +12 -1
- data/spec/{data_measurement_spec.rb → data/measurement_spec.rb} +135 -66
- data/spec/data/night_measurement_spec.rb +136 -0
- data/spec/{data_pressure_spec.rb → data/pressure_spec.rb} +29 -29
- data/spec/{data_speed_spec.rb → data/speed_spec.rb} +30 -30
- data/spec/data/sun_spec.rb +49 -0
- data/spec/{data_temperature_spec.rb → data/temperature_spec.rb} +44 -44
- data/spec/{units_spec.rb → data/units_spec.rb} +6 -6
- data/spec/{data_zone_spec.rb → data/zone_spec.rb} +15 -15
- data/spec/fixtures/formats/weather_id/90210.xml +1 -0
- data/spec/fixtures/formats/weather_id/atlanta.xml +1 -0
- data/spec/fixtures/formats/weather_id/from_USGA0028.xml +1 -0
- data/spec/fixtures/formats/weather_id/new_york.xml +1 -0
- data/spec/fixtures/{geocode_40_73.xml → geocode/40_73.xml} +0 -0
- data/spec/fixtures/{geocode_90210.xml → geocode/90210.xml} +0 -0
- data/spec/fixtures/{geocode_T5B4M9.xml → geocode/T5B4M9.xml} +0 -0
- data/spec/fixtures/geocode/atlanta.xml +1 -0
- data/spec/fixtures/{geocode_calgary_ab.xml → geocode/calgary_ab.xml} +0 -0
- data/spec/fixtures/{geocode_ksfo.xml → geocode/ksfo.xml} +0 -0
- data/spec/fixtures/{geocode_newyork_ny.xml → geocode/newyork_ny.xml} +0 -0
- data/spec/fixtures/{google_calgary_ab.xml → services/google/calgary_ab.xml} +0 -0
- data/spec/fixtures/services/weather_dot_com/90210.xml +1 -0
- data/spec/fixtures/{current_calgary_ab.xml → services/wunderground/current_calgary_ab.xml} +0 -0
- data/spec/fixtures/{forecast_calgary_ab.xml → services/wunderground/forecast_calgary_ab.xml} +0 -0
- data/spec/fixtures/{yahoo_90210.xml → services/yahoo/90210.xml} +0 -0
- data/spec/formats/coordinates_spec.rb +158 -0
- data/spec/formats/format_spec.rb +73 -0
- data/spec/formats/geocode_spec.rb +179 -0
- data/spec/formats/icao_spec.rb +61 -0
- data/spec/formats/postalcode_spec.rb +59 -0
- data/spec/formats/short_zipcode_spec.rb +53 -0
- data/spec/formats/weather_id_spec.rb +191 -0
- data/spec/formats/zipcode_spec.rb +111 -0
- data/spec/query_spec.rb +261 -288
- data/spec/spec_helper.rb +128 -4
- data/spec/{service_google_spec.rb → weather_services/google_spec.rb} +46 -46
- data/spec/weather_services/services_spec.rb +1118 -0
- data/spec/weather_services/weather_dot_com_spec.rb +327 -0
- data/spec/weather_services/wunderground_spec.rb +332 -0
- data/spec/{service_yahoo_spec.rb → weather_services/yahoo_spec.rb} +65 -81
- data/spec/weather_spec.rb +73 -61
- data/spec/web_services/geocode_spec.rb +45 -0
- data/spec/web_services/web_services_spec.rb +26 -0
- metadata +88 -36
- data/lib/barometer/services/noaa.rb +0 -6
- data/lib/barometer/services/weather_bug.rb +0 -6
- data/lib/barometer/services/weather_dot_com.rb +0 -6
- data/spec/data_geo_spec.rb +0 -94
- data/spec/data_sun_spec.rb +0 -76
- data/spec/service_wunderground_spec.rb +0 -330
- data/spec/services_spec.rb +0 -1106
@@ -5,17 +5,17 @@ describe "Pressure" do
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@pressure =
|
8
|
+
@pressure = Data::Pressure.new
|
9
9
|
end
|
10
10
|
|
11
11
|
it "defines METRIC_UNITS" do
|
12
|
-
|
13
|
-
|
12
|
+
Data::Pressure.const_defined?("METRIC_UNITS").should be_true
|
13
|
+
Data::Pressure::METRIC_UNITS.should == "mb"
|
14
14
|
end
|
15
15
|
|
16
16
|
it "defines IMPERIAL_UNITS" do
|
17
|
-
|
18
|
-
|
17
|
+
Data::Pressure.const_defined?("IMPERIAL_UNITS").should be_true
|
18
|
+
Data::Pressure::IMPERIAL_UNITS.should == "in"
|
19
19
|
end
|
20
20
|
|
21
21
|
it "responds to millibars" do
|
@@ -52,20 +52,20 @@ describe "Pressure" do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "requires a value, that is either Integer or Float" do
|
55
|
-
|
56
|
-
|
55
|
+
Data::Pressure.mb_to_in(nil).should be_nil
|
56
|
+
Data::Pressure.in_to_mb(nil).should be_nil
|
57
57
|
|
58
58
|
not_float_or_integer = "string"
|
59
|
-
|
60
|
-
|
59
|
+
Data::Pressure.mb_to_in(not_float_or_integer).should be_nil
|
60
|
+
Data::Pressure.in_to_mb(not_float_or_integer).should be_nil
|
61
61
|
end
|
62
62
|
|
63
63
|
it "converts MB to IN" do
|
64
|
-
((
|
64
|
+
((Data::Pressure.mb_to_in(@mb)*100).round/100.0).should == @in
|
65
65
|
end
|
66
66
|
|
67
67
|
it "converts IN to MB" do
|
68
|
-
((
|
68
|
+
((Data::Pressure.in_to_mb(@in)*100).round/100.0).should == @mb
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
@@ -73,7 +73,7 @@ describe "Pressure" do
|
|
73
73
|
describe "updating" do
|
74
74
|
|
75
75
|
before(:each) do
|
76
|
-
@pressure =
|
76
|
+
@pressure = Data::Pressure.new
|
77
77
|
@in = 21.31
|
78
78
|
@mb = 721.64
|
79
79
|
end
|
@@ -123,7 +123,7 @@ describe "Pressure" do
|
|
123
123
|
describe "storing" do
|
124
124
|
|
125
125
|
before(:each) do
|
126
|
-
@pressure =
|
126
|
+
@pressure = Data::Pressure.new
|
127
127
|
@in = 21.31
|
128
128
|
@mb = 721.64
|
129
129
|
end
|
@@ -165,7 +165,7 @@ describe "Pressure" do
|
|
165
165
|
describe "retrieving" do
|
166
166
|
|
167
167
|
before(:each) do
|
168
|
-
@pressure =
|
168
|
+
@pressure = Data::Pressure.new
|
169
169
|
@in = 21.31
|
170
170
|
@mb = 721.64
|
171
171
|
end
|
@@ -233,52 +233,52 @@ describe "Pressure" do
|
|
233
233
|
before(:each) do
|
234
234
|
@in = 21.31
|
235
235
|
@mb = 721.64
|
236
|
-
@pressure_low =
|
236
|
+
@pressure_low = Data::Pressure.new
|
237
237
|
@pressure_low.mb = (@mb - 1.0)
|
238
|
-
@pressure_high =
|
238
|
+
@pressure_high = Data::Pressure.new
|
239
239
|
@pressure_high.mb = (@mb + 1.0)
|
240
|
-
@pressure =
|
240
|
+
@pressure = Data::Pressure.new
|
241
241
|
@pressure.mb = @mb
|
242
|
-
@pressure_same =
|
242
|
+
@pressure_same = Data::Pressure.new
|
243
243
|
@pressure_same.mb = @mb
|
244
244
|
end
|
245
245
|
|
246
246
|
it "defines <=>" do
|
247
|
-
|
247
|
+
Data::Pressure.method_defined?("<=>").should be_true
|
248
248
|
(@pressure_low <=> @pressure_high).should == -1
|
249
249
|
(@pressure_high <=> @pressure_low).should == 1
|
250
250
|
(@pressure <=> @pressure_same).should == 0
|
251
251
|
end
|
252
252
|
|
253
253
|
it "defines <" do
|
254
|
-
|
254
|
+
Data::Pressure.method_defined?("<").should be_true
|
255
255
|
@pressure_low.should < @pressure_high
|
256
256
|
@pressure_high.should_not < @pressure_low
|
257
257
|
@pressure.should_not < @pressure_same
|
258
258
|
end
|
259
259
|
|
260
260
|
it "defines >" do
|
261
|
-
|
261
|
+
Data::Pressure.method_defined?(">").should be_true
|
262
262
|
@pressure_low.should_not > @pressure_high
|
263
263
|
@pressure_high.should > @pressure_low
|
264
264
|
@pressure.should_not > @pressure_same
|
265
265
|
end
|
266
266
|
|
267
267
|
it "defines ==" do
|
268
|
-
|
268
|
+
Data::Pressure.method_defined?("==").should be_true
|
269
269
|
@pressure_low.should_not == @pressure_high
|
270
270
|
@pressure.should == @pressure_same
|
271
271
|
end
|
272
272
|
|
273
273
|
it "defines <=" do
|
274
|
-
|
274
|
+
Data::Pressure.method_defined?("<=").should be_true
|
275
275
|
@pressure_low.should <= @pressure_high
|
276
276
|
@pressure_high.should_not <= @pressure_low
|
277
277
|
@pressure.should <= @pressure_same
|
278
278
|
end
|
279
279
|
|
280
280
|
it "defines >=" do
|
281
|
-
|
281
|
+
Data::Pressure.method_defined?(">=").should be_true
|
282
282
|
@pressure_low.should_not >= @pressure_high
|
283
283
|
@pressure_high.should >= @pressure_low
|
284
284
|
@pressure.should >= @pressure_same
|
@@ -291,7 +291,7 @@ describe "Pressure" do
|
|
291
291
|
before(:each) do
|
292
292
|
@in = 21.31
|
293
293
|
@mb = 721.64
|
294
|
-
@pressure =
|
294
|
+
@pressure = Data::Pressure.new
|
295
295
|
@pressure.mb = @mb
|
296
296
|
end
|
297
297
|
|
@@ -315,20 +315,20 @@ describe "Pressure" do
|
|
315
315
|
|
316
316
|
it "returns just the integer value with units" do
|
317
317
|
@pressure.metric?.should be_true
|
318
|
-
@pressure.to_s.should == "#{@mb.to_i} #{
|
318
|
+
@pressure.to_s.should == "#{@mb.to_i} #{Data::Pressure::METRIC_UNITS}"
|
319
319
|
|
320
320
|
@pressure.imperial!
|
321
321
|
@pressure.metric?.should be_false
|
322
|
-
@pressure.to_s.should == "#{@in.to_i} #{
|
322
|
+
@pressure.to_s.should == "#{@in.to_i} #{Data::Pressure::IMPERIAL_UNITS}"
|
323
323
|
end
|
324
324
|
|
325
325
|
it "returns just the units" do
|
326
326
|
@pressure.metric?.should be_true
|
327
|
-
@pressure.units.should ==
|
327
|
+
@pressure.units.should == Data::Pressure::METRIC_UNITS
|
328
328
|
|
329
329
|
@pressure.imperial!
|
330
330
|
@pressure.metric?.should be_false
|
331
|
-
@pressure.units.should ==
|
331
|
+
@pressure.units.should == Data::Pressure::IMPERIAL_UNITS
|
332
332
|
end
|
333
333
|
|
334
334
|
end
|
@@ -5,17 +5,17 @@ describe "Speed" do
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
it "defines METRIC_UNITS" do
|
8
|
-
|
9
|
-
|
8
|
+
Data::Speed.const_defined?("METRIC_UNITS").should be_true
|
9
|
+
Data::Speed::METRIC_UNITS.should == "kph"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "defines IMPERIAL_UNITS" do
|
13
|
-
|
14
|
-
|
13
|
+
Data::Speed.const_defined?("IMPERIAL_UNITS").should be_true
|
14
|
+
Data::Speed::IMPERIAL_UNITS.should == "mph"
|
15
15
|
end
|
16
16
|
|
17
17
|
before(:each) do
|
18
|
-
@speed =
|
18
|
+
@speed = Data::Speed.new
|
19
19
|
end
|
20
20
|
|
21
21
|
it "responds to kilometers" do
|
@@ -60,21 +60,21 @@ describe "Speed" do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it "requires a value, that is either Integer or Float" do
|
63
|
-
|
64
|
-
|
63
|
+
Data::Speed.km_to_m(nil).should be_nil
|
64
|
+
Data::Speed.m_to_km(nil).should be_nil
|
65
65
|
|
66
66
|
not_float_or_integer = "string"
|
67
|
-
|
68
|
-
|
67
|
+
Data::Speed.km_to_m(not_float_or_integer).should be_nil
|
68
|
+
Data::Speed.m_to_km(not_float_or_integer).should be_nil
|
69
69
|
end
|
70
70
|
|
71
71
|
it "converts km/h to mph" do
|
72
72
|
# to get equality, we need to tone down the precision
|
73
|
-
((
|
73
|
+
((Data::Speed.km_to_m(@km)*10).round/10.0).should == @m
|
74
74
|
end
|
75
75
|
|
76
76
|
it "converts mph to km/h" do
|
77
|
-
|
77
|
+
Data::Speed.m_to_km(@m).should == @km
|
78
78
|
end
|
79
79
|
|
80
80
|
end
|
@@ -82,7 +82,7 @@ describe "Speed" do
|
|
82
82
|
describe "updating" do
|
83
83
|
|
84
84
|
before(:each) do
|
85
|
-
@speed =
|
85
|
+
@speed = Data::Speed.new
|
86
86
|
@m = 10.0
|
87
87
|
@km = 16.09
|
88
88
|
end
|
@@ -132,7 +132,7 @@ describe "Speed" do
|
|
132
132
|
describe "storing" do
|
133
133
|
|
134
134
|
before(:each) do
|
135
|
-
@speed =
|
135
|
+
@speed = Data::Speed.new
|
136
136
|
@m = 10.0
|
137
137
|
@km = 16.09
|
138
138
|
end
|
@@ -202,7 +202,7 @@ describe "Speed" do
|
|
202
202
|
describe "retrieving" do
|
203
203
|
|
204
204
|
before(:each) do
|
205
|
-
@speed =
|
205
|
+
@speed = Data::Speed.new
|
206
206
|
@m = 10.0
|
207
207
|
@km = 16.09
|
208
208
|
end
|
@@ -271,52 +271,52 @@ describe "Speed" do
|
|
271
271
|
before(:each) do
|
272
272
|
@m = 10.0
|
273
273
|
@km = 16.09
|
274
|
-
@speed_low =
|
274
|
+
@speed_low = Data::Speed.new
|
275
275
|
@speed_low.kph = (@km - 1.0)
|
276
|
-
@speed_high =
|
276
|
+
@speed_high = Data::Speed.new
|
277
277
|
@speed_high.kph = (@km + 1.0)
|
278
|
-
@speed =
|
278
|
+
@speed = Data::Speed.new
|
279
279
|
@speed.kph = @km
|
280
|
-
@speed_same =
|
280
|
+
@speed_same = Data::Speed.new
|
281
281
|
@speed_same.kph = @km
|
282
282
|
end
|
283
283
|
|
284
284
|
it "defines <=>" do
|
285
|
-
|
285
|
+
Data::Speed.method_defined?("<=>").should be_true
|
286
286
|
(@speed_low <=> @speed_high).should == -1
|
287
287
|
(@speed_high <=> @speed_low).should == 1
|
288
288
|
(@speed <=> @speed_same).should == 0
|
289
289
|
end
|
290
290
|
|
291
291
|
it "defines <" do
|
292
|
-
|
292
|
+
Data::Speed.method_defined?("<").should be_true
|
293
293
|
@speed_low.should < @speed_high
|
294
294
|
@speed_high.should_not < @speed_low
|
295
295
|
@speed.should_not < @speed_same
|
296
296
|
end
|
297
297
|
|
298
298
|
it "defines >" do
|
299
|
-
|
299
|
+
Data::Speed.method_defined?(">").should be_true
|
300
300
|
@speed_low.should_not > @speed_high
|
301
301
|
@speed_high.should > @speed_low
|
302
302
|
@speed.should_not > @speed_same
|
303
303
|
end
|
304
304
|
|
305
305
|
it "defines ==" do
|
306
|
-
|
306
|
+
Data::Speed.method_defined?("==").should be_true
|
307
307
|
@speed_low.should_not == @speed_high
|
308
308
|
@speed.should == @speed_same
|
309
309
|
end
|
310
310
|
|
311
311
|
it "defines <=" do
|
312
|
-
|
312
|
+
Data::Speed.method_defined?("<=").should be_true
|
313
313
|
@speed_low.should <= @speed_high
|
314
314
|
@speed_high.should_not <= @speed_low
|
315
315
|
@speed.should <= @speed_same
|
316
316
|
end
|
317
317
|
|
318
318
|
it "defines >=" do
|
319
|
-
|
319
|
+
Data::Speed.method_defined?(">=").should be_true
|
320
320
|
@speed_low.should_not >= @speed_high
|
321
321
|
@speed_high.should >= @speed_low
|
322
322
|
@speed.should >= @speed_same
|
@@ -328,8 +328,8 @@ describe "Speed" do
|
|
328
328
|
|
329
329
|
before(:each) do
|
330
330
|
@m = 10.51
|
331
|
-
@km = ((
|
332
|
-
@speed =
|
331
|
+
@km = ((Data::Speed.m_to_km(@m)*100).round/100.0)
|
332
|
+
@speed = Data::Speed.new
|
333
333
|
@speed.mph = @m
|
334
334
|
end
|
335
335
|
|
@@ -353,20 +353,20 @@ describe "Speed" do
|
|
353
353
|
|
354
354
|
it "returns just the integer value with units" do
|
355
355
|
@speed.metric?.should be_true
|
356
|
-
@speed.to_s.should == "#{@km.to_i} #{
|
356
|
+
@speed.to_s.should == "#{@km.to_i} #{Data::Speed::METRIC_UNITS}"
|
357
357
|
|
358
358
|
@speed.imperial!
|
359
359
|
@speed.metric?.should be_false
|
360
|
-
@speed.to_s.should == "#{@m.to_i} #{
|
360
|
+
@speed.to_s.should == "#{@m.to_i} #{Data::Speed::IMPERIAL_UNITS}"
|
361
361
|
end
|
362
362
|
|
363
363
|
it "returns just the units" do
|
364
364
|
@speed.metric?.should be_true
|
365
|
-
@speed.units.should ==
|
365
|
+
@speed.units.should == Data::Speed::METRIC_UNITS
|
366
366
|
|
367
367
|
@speed.imperial!
|
368
368
|
@speed.metric?.should be_false
|
369
|
-
@speed.units.should ==
|
369
|
+
@speed.units.should == Data::Speed::IMPERIAL_UNITS
|
370
370
|
end
|
371
371
|
|
372
372
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Data::Sun" do
|
4
|
+
|
5
|
+
describe "when initialized" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@sun = Data::Sun.new
|
9
|
+
@local_time_rise = Data::LocalTime.new.parse(Time.now)
|
10
|
+
@local_time_set = Data::LocalTime.new.parse(Time.now + (60*60*8))
|
11
|
+
end
|
12
|
+
|
13
|
+
it "responds to rise" do
|
14
|
+
@sun.respond_to?("rise").should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "responds to set" do
|
18
|
+
@sun.respond_to?("set").should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets sunrise" do
|
22
|
+
sun = Data::Sun.new(@local_time_rise,@local_time_set)
|
23
|
+
sun.rise.should == @local_time_rise
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets sunset" do
|
27
|
+
sun = Data::Sun.new(@local_time_rise,@local_time_set)
|
28
|
+
sun.set.should == @local_time_set
|
29
|
+
end
|
30
|
+
|
31
|
+
it "requires Data::LocalTime for sunrise" do
|
32
|
+
lambda { Data::Sun.new("",@local_time_set) }.should raise_error(ArgumentError)
|
33
|
+
lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "requires Data::LocalTime for sunset" do
|
37
|
+
lambda { Data::Sun.new(@local_time_rise,"") }.should raise_error(ArgumentError)
|
38
|
+
lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "responds to nil?" do
|
42
|
+
@sun.nil?.should be_true
|
43
|
+
sun = Data::Sun.new(@local_time_rise, @local_time_set)
|
44
|
+
sun.nil?.should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Temperature" do
|
3
|
+
describe "Data::Temperature" do
|
4
4
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
it "defines METRIC_UNITS" do
|
8
|
-
|
9
|
-
|
8
|
+
Data::Temperature.const_defined?("METRIC_UNITS").should be_true
|
9
|
+
Data::Temperature::METRIC_UNITS.should == "C"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "defines IMPERIAL_UNITS" do
|
13
|
-
|
14
|
-
|
13
|
+
Data::Temperature.const_defined?("IMPERIAL_UNITS").should be_true
|
14
|
+
Data::Temperature::IMPERIAL_UNITS.should == "F"
|
15
15
|
end
|
16
16
|
|
17
17
|
before(:each) do
|
18
|
-
@temp =
|
18
|
+
@temp = Data::Temperature.new
|
19
19
|
end
|
20
20
|
|
21
21
|
it "responds to celcius" do
|
@@ -57,47 +57,47 @@ describe "Temperature" do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "requires a value, that is either Integer or Float" do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
Data::Temperature.c_to_k(nil).should be_nil
|
61
|
+
Data::Temperature.c_to_f(nil).should be_nil
|
62
|
+
Data::Temperature.f_to_k(nil).should be_nil
|
63
|
+
Data::Temperature.f_to_c(nil).should be_nil
|
64
|
+
Data::Temperature.k_to_c(nil).should be_nil
|
65
|
+
Data::Temperature.k_to_f(nil).should be_nil
|
66
66
|
|
67
67
|
not_float_or_integer = "string"
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
Data::Temperature.c_to_k(not_float_or_integer).should be_nil
|
69
|
+
Data::Temperature.c_to_f(not_float_or_integer).should be_nil
|
70
|
+
Data::Temperature.f_to_k(not_float_or_integer).should be_nil
|
71
|
+
Data::Temperature.f_to_c(not_float_or_integer).should be_nil
|
72
|
+
Data::Temperature.k_to_c(not_float_or_integer).should be_nil
|
73
|
+
Data::Temperature.k_to_f(not_float_or_integer).should be_nil
|
74
74
|
end
|
75
75
|
|
76
76
|
it "converts C to K" do
|
77
77
|
# 0 C = 273.15 K
|
78
|
-
|
78
|
+
Data::Temperature.c_to_k(@c).should == @k
|
79
79
|
end
|
80
80
|
|
81
81
|
it "converts C to F" do
|
82
82
|
# Tf = (9/5)*Tc+32
|
83
|
-
|
83
|
+
Data::Temperature.c_to_f(@c).should == @f
|
84
84
|
end
|
85
85
|
|
86
86
|
it "converts F to C" do
|
87
87
|
# Tc = (5/9)*(Tf-32)
|
88
|
-
|
88
|
+
Data::Temperature.f_to_c(@f).should == @c
|
89
89
|
end
|
90
90
|
|
91
91
|
it "converts F to K" do
|
92
|
-
|
92
|
+
Data::Temperature.f_to_k(@f).should == @k
|
93
93
|
end
|
94
94
|
|
95
95
|
it "converts K to C" do
|
96
|
-
|
96
|
+
Data::Temperature.k_to_c(@k).should == @c
|
97
97
|
end
|
98
98
|
|
99
99
|
it "converts K to F" do
|
100
|
-
|
100
|
+
Data::Temperature.k_to_f(@k).should == @f
|
101
101
|
end
|
102
102
|
|
103
103
|
end
|
@@ -105,7 +105,7 @@ describe "Temperature" do
|
|
105
105
|
describe "updating" do
|
106
106
|
|
107
107
|
before(:each) do
|
108
|
-
@temp =
|
108
|
+
@temp = Data::Temperature.new
|
109
109
|
@f = 68.0
|
110
110
|
@c = 20.0
|
111
111
|
end
|
@@ -155,7 +155,7 @@ describe "Temperature" do
|
|
155
155
|
describe "storing" do
|
156
156
|
|
157
157
|
before(:each) do
|
158
|
-
@temp =
|
158
|
+
@temp = Data::Temperature.new
|
159
159
|
@f = 68.0
|
160
160
|
@c = 20.0
|
161
161
|
@k = 293.15
|
@@ -220,7 +220,7 @@ describe "Temperature" do
|
|
220
220
|
describe "retrieving" do
|
221
221
|
|
222
222
|
before(:each) do
|
223
|
-
@temp =
|
223
|
+
@temp = Data::Temperature.new
|
224
224
|
@f = 68.0
|
225
225
|
@c = 20.0
|
226
226
|
@k = 293.15
|
@@ -292,52 +292,52 @@ describe "Temperature" do
|
|
292
292
|
@f = 68.0
|
293
293
|
@c = 20.0
|
294
294
|
@k = 293.15
|
295
|
-
@temp_low =
|
295
|
+
@temp_low = Data::Temperature.new
|
296
296
|
@temp_low.k = (@k - 1.0)
|
297
|
-
@temp_high =
|
297
|
+
@temp_high = Data::Temperature.new
|
298
298
|
@temp_high.k = (@k + 1.0)
|
299
|
-
@temp =
|
299
|
+
@temp = Data::Temperature.new
|
300
300
|
@temp.k = @k
|
301
|
-
@temp_same =
|
301
|
+
@temp_same = Data::Temperature.new
|
302
302
|
@temp_same.k = @k
|
303
303
|
end
|
304
304
|
|
305
305
|
it "defines <=>" do
|
306
|
-
|
306
|
+
Data::Temperature.method_defined?("<=>").should be_true
|
307
307
|
(@temp_low <=> @temp_high).should == -1
|
308
308
|
(@temp_high <=> @temp_low).should == 1
|
309
309
|
(@temp <=> @temp_same).should == 0
|
310
310
|
end
|
311
311
|
|
312
312
|
it "defines <" do
|
313
|
-
|
313
|
+
Data::Temperature.method_defined?("<").should be_true
|
314
314
|
@temp_low.should < @temp_high
|
315
315
|
@temp_high.should_not < @temp_low
|
316
316
|
@temp.should_not < @temp_same
|
317
317
|
end
|
318
318
|
|
319
319
|
it "defines >" do
|
320
|
-
|
320
|
+
Data::Temperature.method_defined?(">").should be_true
|
321
321
|
@temp_low.should_not > @temp_high
|
322
322
|
@temp_high.should > @temp_low
|
323
323
|
@temp.should_not > @temp_same
|
324
324
|
end
|
325
325
|
|
326
326
|
it "defines ==" do
|
327
|
-
|
327
|
+
Data::Temperature.method_defined?("==").should be_true
|
328
328
|
@temp_low.should_not == @temp_high
|
329
329
|
@temp.should == @temp_same
|
330
330
|
end
|
331
331
|
|
332
332
|
it "defines <=" do
|
333
|
-
|
333
|
+
Data::Temperature.method_defined?("<=").should be_true
|
334
334
|
@temp_low.should <= @temp_high
|
335
335
|
@temp_high.should_not <= @temp_low
|
336
336
|
@temp.should <= @temp_same
|
337
337
|
end
|
338
338
|
|
339
339
|
it "defines >=" do
|
340
|
-
|
340
|
+
Data::Temperature.method_defined?(">=").should be_true
|
341
341
|
@temp_low.should_not >= @temp_high
|
342
342
|
@temp_high.should >= @temp_low
|
343
343
|
@temp.should >= @temp_same
|
@@ -349,9 +349,9 @@ describe "Temperature" do
|
|
349
349
|
|
350
350
|
before(:each) do
|
351
351
|
@c = 20.5
|
352
|
-
@f =
|
353
|
-
@k =
|
354
|
-
@temp =
|
352
|
+
@f = Data::Temperature.c_to_f(@c)
|
353
|
+
@k = Data::Temperature.c_to_k(@c)
|
354
|
+
@temp = Data::Temperature.new
|
355
355
|
@temp.k = @k
|
356
356
|
end
|
357
357
|
|
@@ -375,20 +375,20 @@ describe "Temperature" do
|
|
375
375
|
|
376
376
|
it "returns just the integer value with units" do
|
377
377
|
@temp.metric?.should be_true
|
378
|
-
@temp.to_s.should == "#{@c.to_i} #{
|
378
|
+
@temp.to_s.should == "#{@c.to_i} #{Data::Temperature::METRIC_UNITS}"
|
379
379
|
|
380
380
|
@temp.imperial!
|
381
381
|
@temp.metric?.should be_false
|
382
|
-
@temp.to_s.should == "#{@f.to_i} #{
|
382
|
+
@temp.to_s.should == "#{@f.to_i} #{Data::Temperature::IMPERIAL_UNITS}"
|
383
383
|
end
|
384
384
|
|
385
385
|
it "returns just the units" do
|
386
386
|
@temp.metric?.should be_true
|
387
|
-
@temp.units.should ==
|
387
|
+
@temp.units.should == Data::Temperature::METRIC_UNITS
|
388
388
|
|
389
389
|
@temp.imperial!
|
390
390
|
@temp.metric?.should be_false
|
391
|
-
@temp.units.should ==
|
391
|
+
@temp.units.should == Data::Temperature::IMPERIAL_UNITS
|
392
392
|
end
|
393
393
|
|
394
394
|
end
|