barometer 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +7 -0
- data/LICENSE +1 -1
- data/{README.rdoc → README.md} +124 -110
- data/Rakefile +1 -21
- data/TODO +8 -9
- data/barometer.gemspec +20 -19
- data/bin/barometer +36 -83
- data/lib/barometer.rb +13 -11
- data/lib/barometer/base.rb +10 -10
- data/lib/barometer/data.rb +1 -1
- data/lib/barometer/data/distance.rb +25 -25
- data/lib/barometer/data/geo.rb +9 -9
- data/lib/barometer/data/local_datetime.rb +24 -20
- data/lib/barometer/data/local_time.rb +13 -13
- data/lib/barometer/data/location.rb +6 -6
- data/lib/barometer/data/pressure.rb +24 -24
- data/lib/barometer/data/speed.rb +28 -28
- data/lib/barometer/data/sun.rb +7 -7
- data/lib/barometer/data/temperature.rb +29 -29
- data/lib/barometer/data/units.rb +9 -9
- data/lib/barometer/data/zone.rb +19 -19
- data/lib/barometer/formats.rb +1 -1
- data/lib/barometer/formats/coordinates.rb +7 -7
- data/lib/barometer/formats/format.rb +6 -6
- data/lib/barometer/formats/geocode.rb +5 -5
- data/lib/barometer/formats/icao.rb +6 -6
- data/lib/barometer/formats/postalcode.rb +3 -3
- data/lib/barometer/formats/short_zipcode.rb +2 -2
- data/lib/barometer/formats/weather_id.rb +10 -10
- data/lib/barometer/formats/woe_id.rb +20 -20
- data/lib/barometer/formats/zipcode.rb +3 -3
- data/lib/barometer/key_file_parser.rb +20 -0
- data/lib/barometer/measurements/measurement.rb +32 -32
- data/lib/barometer/measurements/result.rb +39 -39
- data/lib/barometer/measurements/result_array.rb +12 -12
- data/lib/barometer/query.rb +15 -15
- data/lib/barometer/services.rb +3 -3
- data/lib/barometer/translations/icao_country_codes.yml +20 -20
- data/lib/barometer/translations/weather_country_codes.yml +1 -1
- data/lib/barometer/translations/zone_codes.yml +2 -2
- data/lib/barometer/version.rb +3 -0
- data/lib/barometer/weather.rb +27 -27
- data/lib/barometer/weather_services/noaa.rb +314 -3
- data/lib/barometer/weather_services/service.rb +32 -30
- data/lib/barometer/weather_services/weather_bug.rb +35 -33
- data/lib/barometer/weather_services/wunderground.rb +31 -29
- data/lib/barometer/weather_services/yahoo.rb +36 -35
- data/lib/barometer/web_services/geocode.rb +5 -7
- data/lib/barometer/web_services/noaa_station_id.rb +53 -0
- data/lib/barometer/web_services/placemaker.rb +11 -13
- data/lib/barometer/web_services/timezone.rb +5 -7
- data/lib/barometer/web_services/weather_id.rb +4 -6
- data/lib/barometer/web_services/web_service.rb +4 -4
- data/spec/barometer_spec.rb +25 -27
- data/spec/cassettes/Barometer.json +1 -0
- data/spec/cassettes/Query.json +1 -0
- data/spec/cassettes/Query_Format_Coordinates.json +1 -0
- data/spec/cassettes/Query_Format_Geocode.json +1 -0
- data/spec/cassettes/Query_Format_WeatherID.json +1 -0
- data/spec/cassettes/Query_Format_WoeID.json +1 -0
- data/spec/cassettes/WeatherService.json +1 -0
- data/spec/cassettes/WeatherService_Noaa.json +1 -0
- data/spec/cassettes/WeatherService_WeatherBug.json +1 -0
- data/spec/cassettes/WeatherService_Wunderground.json +1 -0
- data/spec/cassettes/WeatherService_Yahoo.json +1 -0
- data/spec/cassettes/WebService_Geocode.json +1 -0
- data/spec/cassettes/WebService_NoaaStation.json +1 -0
- data/spec/data/distance_spec.rb +60 -60
- data/spec/data/geo_spec.rb +23 -23
- data/spec/data/local_datetime_spec.rb +44 -44
- data/spec/data/local_time_spec.rb +47 -47
- data/spec/data/location_spec.rb +16 -16
- data/spec/data/pressure_spec.rb +61 -61
- data/spec/data/speed_spec.rb +69 -69
- data/spec/data/sun_spec.rb +25 -25
- data/spec/data/temperature_spec.rb +68 -68
- data/spec/data/units_spec.rb +21 -21
- data/spec/data/zone_spec.rb +35 -35
- data/spec/formats/coordinates_spec.rb +27 -27
- data/spec/formats/format_spec.rb +17 -25
- data/spec/formats/geocode_spec.rb +23 -31
- data/spec/formats/icao_spec.rb +26 -32
- data/spec/formats/postalcode_spec.rb +22 -28
- data/spec/formats/short_zipcode_spec.rb +20 -26
- data/spec/formats/weather_id_spec.rb +57 -67
- data/spec/formats/woe_id_spec.rb +59 -59
- data/spec/formats/zipcode_spec.rb +39 -47
- data/spec/key_file_parser_spec.rb +28 -0
- data/spec/measurements/measurement_spec.rb +79 -133
- data/spec/measurements/result_array_spec.rb +23 -38
- data/spec/measurements/result_spec.rb +100 -128
- data/spec/query_spec.rb +83 -100
- data/spec/spec_helper.rb +24 -6
- data/spec/weather_services/noaa_spec.rb +179 -0
- data/spec/weather_services/services_spec.rb +28 -36
- data/spec/weather_services/weather_bug_spec.rb +57 -77
- data/spec/weather_services/wunderground_spec.rb +36 -65
- data/spec/weather_services/yahoo_spec.rb +38 -60
- data/spec/weather_spec.rb +79 -79
- data/spec/web_services/geocode_spec.rb +7 -11
- data/spec/web_services/noaa_station_id_spec.rb +33 -0
- data/spec/web_services/placemaker_spec.rb +7 -12
- data/spec/web_services/web_services_spec.rb +3 -9
- metadata +214 -163
- data/VERSION.yml +0 -5
- data/lib/barometer/weather_services/google.rb +0 -142
- data/lib/barometer/weather_services/weather_dot_com.rb +0 -279
- data/spec/fakeweb_helper.rb +0 -179
- data/spec/fixtures/formats/weather_id/90210.xml +0 -7
- data/spec/fixtures/formats/weather_id/from_USGA0028.xml +0 -3
- data/spec/fixtures/formats/weather_id/ksfo.xml +0 -1
- data/spec/fixtures/formats/weather_id/manhattan.xml +0 -7
- data/spec/fixtures/formats/weather_id/new_york.xml +0 -1
- data/spec/fixtures/formats/weather_id/the_hills.xml +0 -1
- data/spec/fixtures/geocode/40_73_v3.json +0 -497
- data/spec/fixtures/geocode/90210_v3.json +0 -63
- data/spec/fixtures/geocode/T5B4M9_v3.json +0 -68
- data/spec/fixtures/geocode/atlanta_v3.json +0 -58
- data/spec/fixtures/geocode/calgary_ab_v3.json +0 -58
- data/spec/fixtures/geocode/ksfo_v3.json +0 -73
- data/spec/fixtures/geocode/newyork_ny_v3.json +0 -58
- data/spec/fixtures/services/google/calgary_ab.xml +0 -1
- data/spec/fixtures/services/placemaker/T5B4M9.xml +0 -65
- data/spec/fixtures/services/placemaker/atlanta.xml +0 -65
- data/spec/fixtures/services/placemaker/coords.xml +0 -65
- data/spec/fixtures/services/placemaker/ksfo.xml +0 -65
- data/spec/fixtures/services/placemaker/new_york.xml +0 -65
- data/spec/fixtures/services/placemaker/the_hills.xml +0 -65
- data/spec/fixtures/services/placemaker/w615702.xml +0 -47
- data/spec/fixtures/services/weather_bug/90210_current.xml +0 -93
- data/spec/fixtures/services/weather_bug/90210_forecast.xml +0 -76
- data/spec/fixtures/services/weather_dot_com/90210.xml +0 -1
- data/spec/fixtures/services/wunderground/current_calgary_ab.xml +0 -9
- data/spec/fixtures/services/wunderground/forecast_calgary_ab.xml +0 -13
- data/spec/fixtures/services/yahoo/90210.xml +0 -3
- data/spec/weather_services/google_spec.rb +0 -181
- data/spec/weather_services/weather_dot_com_spec.rb +0 -224
data/spec/data/speed_spec.rb
CHANGED
@@ -1,104 +1,104 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Speed" do
|
4
|
-
|
4
|
+
|
5
5
|
describe "when initialized" do
|
6
|
-
|
6
|
+
|
7
7
|
it "defines METRIC_UNITS" do
|
8
8
|
Data::Speed.const_defined?("METRIC_UNITS").should be_true
|
9
9
|
Data::Speed::METRIC_UNITS.should == "kph"
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "defines IMPERIAL_UNITS" do
|
13
13
|
Data::Speed.const_defined?("IMPERIAL_UNITS").should be_true
|
14
14
|
Data::Speed::IMPERIAL_UNITS.should == "mph"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
before(:each) do
|
18
18
|
@speed = Data::Speed.new
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "responds to kilometers" do
|
22
22
|
@speed.kilometers.should be_nil
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "responds to miles" do
|
26
26
|
@speed.miles.should be_nil
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "responds to degrees" do
|
30
30
|
@speed.degrees.should be_nil
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "responds to direction" do
|
34
34
|
@speed.direction.should be_nil
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "responds to metric_default" do
|
38
38
|
lambda { @speed.metric_default = 5 }.should_not raise_error(NotImplementedError)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "responds to imperial_default" do
|
42
42
|
lambda { @speed.imperial_default = 5 }.should_not raise_error(NotImplementedError)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "responds to nil?" do
|
46
46
|
@speed.nil?.should be_true
|
47
47
|
@speed.kph = 5
|
48
48
|
@speed.nil?.should be_false
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
describe "conversion" do
|
54
|
-
|
54
|
+
|
55
55
|
# For all conversions
|
56
56
|
# 16.09 km/h = 10.0 mph
|
57
57
|
before(:each) do
|
58
58
|
@m = 10.0
|
59
59
|
@km = 16.09
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it "requires a value, that is either Integer or Float" do
|
63
63
|
Data::Speed.km_to_m(nil).should be_nil
|
64
64
|
Data::Speed.m_to_km(nil).should be_nil
|
65
|
-
|
65
|
+
|
66
66
|
not_float_or_integer = "string"
|
67
67
|
Data::Speed.km_to_m(not_float_or_integer).should be_nil
|
68
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
|
81
|
-
|
81
|
+
|
82
82
|
describe "updating" do
|
83
|
-
|
83
|
+
|
84
84
|
before(:each) do
|
85
85
|
@speed = Data::Speed.new
|
86
86
|
@m = 10.0
|
87
87
|
@km = 16.09
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "nils M if new KM converts to a M that changes more then 1 unit" do
|
91
91
|
@speed.miles = (@m + 1.1)
|
92
92
|
@speed.update_miles(@km)
|
93
93
|
@speed.miles.should be_nil
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
it "doesn't update M if new KM converts to a M that does not change more then 1 unit" do
|
97
97
|
@speed.miles = (@m + 0.9)
|
98
98
|
@speed.update_miles(@km)
|
99
99
|
@speed.miles.should == (@m + 0.9)
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
it "doesn't set M if not already set" do
|
103
103
|
@speed.miles.should be_nil
|
104
104
|
@speed.kilometers.should be_nil
|
@@ -106,19 +106,19 @@ describe "Speed" do
|
|
106
106
|
@speed.miles.should be_nil
|
107
107
|
@speed.kilometers.should be_nil
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
it "nils KM if new M converts to a KM that changes more then 1 unit" do
|
111
111
|
@speed.kilometers = (@km + 1.1)
|
112
112
|
@speed.update_kilometers(@m)
|
113
113
|
@speed.kilometers.should be_nil
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
it "doesn't update KM if new M converts to a KM that does not change more then 1 unit" do
|
117
117
|
@speed.kilometers = (@km + 0.9)
|
118
118
|
@speed.update_kilometers(@m)
|
119
119
|
@speed.kilometers.should == (@km + 0.9)
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
it "doesn't set KM if not already set" do
|
123
123
|
@speed.miles.should be_nil
|
124
124
|
@speed.kilometers.should be_nil
|
@@ -126,17 +126,17 @@ describe "Speed" do
|
|
126
126
|
@speed.miles.should be_nil
|
127
127
|
@speed.kilometers.should be_nil
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
describe "storing" do
|
133
|
-
|
133
|
+
|
134
134
|
before(:each) do
|
135
135
|
@speed = Data::Speed.new
|
136
136
|
@m = 10.0
|
137
137
|
@km = 16.09
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
it "doesn't update KM if nil value (or equivalent)" do
|
141
141
|
@speed.kilometers.should be_nil
|
142
142
|
@speed.kph = nil
|
@@ -144,7 +144,7 @@ describe "Speed" do
|
|
144
144
|
@speed.kph = "na"
|
145
145
|
@speed.kilometers.should be_nil
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
it "stores KM and resets M" do
|
149
149
|
@speed.kilometers.should be_nil
|
150
150
|
@speed.miles = (@m + 1.1)
|
@@ -152,7 +152,7 @@ describe "Speed" do
|
|
152
152
|
@speed.kilometers.should == @km
|
153
153
|
@speed.miles.should be_nil
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
it "doesn't update M if nil value (or equivalent)" do
|
157
157
|
@speed.miles.should be_nil
|
158
158
|
@speed.mph = nil
|
@@ -160,7 +160,7 @@ describe "Speed" do
|
|
160
160
|
@speed.mph = "na"
|
161
161
|
@speed.miles.should be_nil
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
it "stores M, resets KM" do
|
165
165
|
@speed.miles.should be_nil
|
166
166
|
@speed.kilometers = (@km + 1.1)
|
@@ -168,7 +168,7 @@ describe "Speed" do
|
|
168
168
|
@speed.miles.should == @m
|
169
169
|
@speed.kilometers.should be_nil
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
it "doesn't update direction if nil value (or equivalent)" do
|
173
173
|
@speed.direction.should be_nil
|
174
174
|
@speed.direction = nil
|
@@ -176,13 +176,13 @@ describe "Speed" do
|
|
176
176
|
@speed.direction = "na"
|
177
177
|
@speed.direction.should_not be_nil
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
it "stores direction" do
|
181
181
|
@speed.direction.should be_nil
|
182
182
|
@speed.direction = "SSW"
|
183
183
|
@speed.direction.should == "SSW"
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
it "doesn't update degrees if nil value (or equivalent)" do
|
187
187
|
@speed.degrees.should be_nil
|
188
188
|
@speed.degrees = nil
|
@@ -190,36 +190,36 @@ describe "Speed" do
|
|
190
190
|
@speed.degrees = "na"
|
191
191
|
@speed.degrees.should be_nil
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
it "stores degrees" do
|
195
195
|
@speed.degrees.should be_nil
|
196
196
|
@speed.degrees = 90.0
|
197
197
|
@speed.degrees.should == 90.0
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
describe "retrieving" do
|
203
|
-
|
203
|
+
|
204
204
|
before(:each) do
|
205
205
|
@speed = Data::Speed.new
|
206
206
|
@m = 10.0
|
207
207
|
@km = 16.09
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
it "returns KM if it exists" do
|
211
211
|
@speed.kph = @km
|
212
212
|
@speed.kilometers.should == @km
|
213
213
|
@speed.kph(false).should == @km
|
214
214
|
end
|
215
|
-
|
215
|
+
|
216
216
|
it "auto converts from M if KM is nil and M exists" do
|
217
217
|
@speed.mph = @m
|
218
218
|
@speed.miles.should == @m
|
219
219
|
@speed.kilometers.should be_nil
|
220
220
|
@speed.kph(false).should == @km
|
221
|
-
end
|
222
|
-
|
221
|
+
end
|
222
|
+
|
223
223
|
it "allows a float to be returned for KM" do
|
224
224
|
km = 16.12
|
225
225
|
@speed.kph = km
|
@@ -227,28 +227,28 @@ describe "Speed" do
|
|
227
227
|
@speed.kph(true).should == km.to_i
|
228
228
|
@speed.kph(false).should == km.to_f
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
it "allows only 2 decimal precision for KM" do
|
232
232
|
km = 16.1234
|
233
233
|
@speed.kph = km
|
234
234
|
@speed.kilometers.should == km
|
235
235
|
@speed.kph(false).should == 16.12
|
236
236
|
end
|
237
|
-
|
237
|
+
|
238
238
|
it "returns M if it exists" do
|
239
239
|
@speed.mph = @m
|
240
240
|
@speed.miles.should == @m
|
241
241
|
@speed.mph.should == @m
|
242
242
|
end
|
243
|
-
|
243
|
+
|
244
244
|
it "auto converts from KM if M is nil and KM exists" do
|
245
245
|
@speed.kph = @km
|
246
246
|
@speed.kilometers.should == @km
|
247
247
|
@speed.miles.should be_nil
|
248
248
|
# to get equality, we need to tone down the precision
|
249
249
|
((@speed.mph*10).round/10.0).should == @m
|
250
|
-
end
|
251
|
-
|
250
|
+
end
|
251
|
+
|
252
252
|
it "allows a float to be returned for M" do
|
253
253
|
m = 10.12
|
254
254
|
@speed.mph = m
|
@@ -256,18 +256,18 @@ describe "Speed" do
|
|
256
256
|
@speed.mph(true).should == m.to_i
|
257
257
|
@speed.mph(false).should == m.to_f
|
258
258
|
end
|
259
|
-
|
259
|
+
|
260
260
|
it "allows only 2 decimal precision for M" do
|
261
261
|
m = 10.1234
|
262
262
|
@speed.mph = m
|
263
263
|
@speed.miles.should == m
|
264
264
|
@speed.mph(false).should == 10.12
|
265
265
|
end
|
266
|
-
|
266
|
+
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
describe "operators" do
|
270
|
-
|
270
|
+
|
271
271
|
before(:each) do
|
272
272
|
@m = 10.0
|
273
273
|
@km = 16.09
|
@@ -280,63 +280,63 @@ describe "Speed" do
|
|
280
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
|
323
323
|
end
|
324
|
-
|
324
|
+
|
325
325
|
end
|
326
|
-
|
326
|
+
|
327
327
|
describe "changing units" do
|
328
|
-
|
328
|
+
|
329
329
|
before(:each) do
|
330
330
|
@m = 10.51
|
331
331
|
@km = ((Data::Speed.m_to_km(@m)*100).round/100.0)
|
332
332
|
@speed = Data::Speed.new
|
333
333
|
@speed.mph = @m
|
334
334
|
end
|
335
|
-
|
335
|
+
|
336
336
|
it "returns just the integer value (no units)" do
|
337
337
|
@speed.metric?.should be_true
|
338
338
|
@speed.to_i.should == @km.to_i
|
339
|
-
|
339
|
+
|
340
340
|
@speed.imperial!
|
341
341
|
@speed.metric?.should be_false
|
342
342
|
@speed.to_i.should == @m.to_i
|
@@ -350,7 +350,7 @@ describe "Speed" do
|
|
350
350
|
@speed.metric?.should be_false
|
351
351
|
@speed.to_f.should == @m.to_f
|
352
352
|
end
|
353
|
-
|
353
|
+
|
354
354
|
it "returns just the integer value with units" do
|
355
355
|
@speed.metric?.should be_true
|
356
356
|
@speed.to_s.should == "#{@km.to_i} #{Data::Speed::METRIC_UNITS}"
|
@@ -359,7 +359,7 @@ describe "Speed" do
|
|
359
359
|
@speed.metric?.should be_false
|
360
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
365
|
@speed.units.should == Data::Speed::METRIC_UNITS
|
@@ -370,5 +370,5 @@ describe "Speed" do
|
|
370
370
|
end
|
371
371
|
|
372
372
|
end
|
373
|
-
|
374
|
-
end
|
373
|
+
|
374
|
+
end
|
data/spec/data/sun_spec.rb
CHANGED
@@ -1,102 +1,102 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Data::Sun" do
|
4
|
-
|
4
|
+
|
5
5
|
describe "when initialized" do
|
6
|
-
|
6
|
+
|
7
7
|
before(:each) do
|
8
8
|
@sun = Data::Sun.new
|
9
9
|
@local_time_rise = Data::LocalTime.new.parse(Time.now)
|
10
10
|
@local_time_set = Data::LocalTime.new.parse(Time.now + (60*60*8))
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "responds to rise" do
|
14
14
|
@sun.respond_to?("rise").should be_true
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "responds to set" do
|
18
18
|
@sun.respond_to?("set").should be_true
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "sets sunrise" do
|
22
22
|
sun = Data::Sun.new(@local_time_rise,@local_time_set)
|
23
23
|
sun.rise.should == @local_time_rise
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "sets sunset" do
|
27
27
|
sun = Data::Sun.new(@local_time_rise,@local_time_set)
|
28
28
|
sun.set.should == @local_time_set
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "requires Data::LocalTime for sunrise" do
|
32
32
|
lambda { Data::Sun.new("",@local_time_set) }.should raise_error(ArgumentError)
|
33
33
|
lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "requires Data::LocalTime for sunset" do
|
37
37
|
lambda { Data::Sun.new(@local_time_rise,"") }.should raise_error(ArgumentError)
|
38
38
|
lambda { Data::Sun.new(@local_time_rise,@local_time_set) }.should_not raise_error(ArgumentError)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "responds to nil?" do
|
42
42
|
@sun.nil?.should be_true
|
43
43
|
sun = Data::Sun.new(@local_time_rise, @local_time_set)
|
44
44
|
sun.nil?.should be_false
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
describe "comparisons" do
|
50
|
-
|
50
|
+
|
51
51
|
before(:each) do
|
52
52
|
now = Time.local(2009,5,5,11,40,00)
|
53
53
|
@mid_time = Data::LocalTime.new.parse(now)
|
54
54
|
@early_time = Data::LocalTime.new.parse(now - (60*60*8))
|
55
55
|
@late_time = Data::LocalTime.new.parse(now + (60*60*8))
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
describe "after_rise?" do
|
59
|
-
|
59
|
+
|
60
60
|
it "requires a LocalTime object" do
|
61
61
|
sun = Data::Sun.new(@early_time,@late_time)
|
62
62
|
lambda { sun.after_rise? }.should raise_error(ArgumentError)
|
63
63
|
lambda { sun.after_rise?("invalid") }.should raise_error(ArgumentError)
|
64
64
|
lambda { sun.after_rise?(@mid_time) }.should_not raise_error(ArgumentError)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it "returns true when after sun rise" do
|
68
68
|
sun = Data::Sun.new(@early_time,@late_time)
|
69
69
|
sun.after_rise?(@mid_time).should be_true
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it "returns false when before sun rise" do
|
73
73
|
sun = Data::Sun.new(@mid_time,@late_time)
|
74
74
|
sun.after_rise?(@early_time).should be_false
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
describe "before_set?" do
|
80
|
-
|
80
|
+
|
81
81
|
it "requires a LocalTime object" do
|
82
82
|
sun = Data::Sun.new(@early_time,@late_time)
|
83
83
|
lambda { sun.before_set? }.should raise_error(ArgumentError)
|
84
84
|
lambda { sun.before_set?("invalid") }.should raise_error(ArgumentError)
|
85
85
|
lambda { sun.before_set?(@mid_time) }.should_not raise_error(ArgumentError)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it "returns true when before sun set" do
|
89
89
|
sun = Data::Sun.new(@early_time,@late_time)
|
90
90
|
sun.before_set?(@mid_time).should be_true
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "returns false when before sun set" do
|
94
94
|
sun = Data::Sun.new(@early_time,@mid_time)
|
95
95
|
sun.before_set?(@late_time).should be_false
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
end
|
101
|
-
|
102
|
-
end
|
101
|
+
|
102
|
+
end
|