barometer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +266 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/barometer +63 -0
  5. data/lib/barometer.rb +52 -0
  6. data/lib/barometer/base.rb +52 -0
  7. data/lib/barometer/data.rb +15 -0
  8. data/lib/barometer/data/current.rb +93 -0
  9. data/lib/barometer/data/distance.rb +131 -0
  10. data/lib/barometer/data/forecast.rb +66 -0
  11. data/lib/barometer/data/geo.rb +98 -0
  12. data/lib/barometer/data/location.rb +20 -0
  13. data/lib/barometer/data/measurement.rb +161 -0
  14. data/lib/barometer/data/pressure.rb +133 -0
  15. data/lib/barometer/data/speed.rb +147 -0
  16. data/lib/barometer/data/sun.rb +35 -0
  17. data/lib/barometer/data/temperature.rb +164 -0
  18. data/lib/barometer/data/units.rb +55 -0
  19. data/lib/barometer/data/zone.rb +124 -0
  20. data/lib/barometer/extensions/graticule.rb +50 -0
  21. data/lib/barometer/extensions/httparty.rb +21 -0
  22. data/lib/barometer/query.rb +228 -0
  23. data/lib/barometer/services.rb +6 -0
  24. data/lib/barometer/services/google.rb +146 -0
  25. data/lib/barometer/services/noaa.rb +6 -0
  26. data/lib/barometer/services/service.rb +324 -0
  27. data/lib/barometer/services/weather_bug.rb +6 -0
  28. data/lib/barometer/services/weather_dot_com.rb +6 -0
  29. data/lib/barometer/services/wunderground.rb +285 -0
  30. data/lib/barometer/services/yahoo.rb +274 -0
  31. data/lib/barometer/weather.rb +187 -0
  32. data/spec/barometer_spec.rb +162 -0
  33. data/spec/data_current_spec.rb +225 -0
  34. data/spec/data_distance_spec.rb +336 -0
  35. data/spec/data_forecast_spec.rb +150 -0
  36. data/spec/data_geo_spec.rb +90 -0
  37. data/spec/data_location_spec.rb +59 -0
  38. data/spec/data_measurement_spec.rb +411 -0
  39. data/spec/data_pressure_spec.rb +336 -0
  40. data/spec/data_speed_spec.rb +374 -0
  41. data/spec/data_sun_spec.rb +76 -0
  42. data/spec/data_temperature_spec.rb +396 -0
  43. data/spec/data_zone_spec.rb +133 -0
  44. data/spec/fixtures/current_calgary_ab.xml +1 -0
  45. data/spec/fixtures/forecast_calgary_ab.xml +1 -0
  46. data/spec/fixtures/geocode_40_73.xml +1 -0
  47. data/spec/fixtures/geocode_90210.xml +1 -0
  48. data/spec/fixtures/geocode_T5B4M9.xml +1 -0
  49. data/spec/fixtures/geocode_calgary_ab.xml +1 -0
  50. data/spec/fixtures/geocode_newyork_ny.xml +1 -0
  51. data/spec/fixtures/google_calgary_ab.xml +1 -0
  52. data/spec/fixtures/yahoo_90210.xml +1 -0
  53. data/spec/query_spec.rb +469 -0
  54. data/spec/service_google_spec.rb +144 -0
  55. data/spec/service_wunderground_spec.rb +330 -0
  56. data/spec/service_yahoo_spec.rb +299 -0
  57. data/spec/services_spec.rb +1106 -0
  58. data/spec/spec_helper.rb +14 -0
  59. data/spec/units_spec.rb +101 -0
  60. data/spec/weather_spec.rb +265 -0
  61. metadata +119 -0
@@ -0,0 +1,336 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Pressure" do
4
+
5
+ describe "when initialized" do
6
+
7
+ before(:each) do
8
+ @pressure = Barometer::Pressure.new
9
+ end
10
+
11
+ it "defines METRIC_UNITS" do
12
+ Barometer::Pressure.const_defined?("METRIC_UNITS").should be_true
13
+ Barometer::Pressure::METRIC_UNITS.should == "mb"
14
+ end
15
+
16
+ it "defines IMPERIAL_UNITS" do
17
+ Barometer::Pressure.const_defined?("IMPERIAL_UNITS").should be_true
18
+ Barometer::Pressure::IMPERIAL_UNITS.should == "in"
19
+ end
20
+
21
+ it "responds to millibars" do
22
+ @pressure.millibars.should be_nil
23
+ end
24
+
25
+ it "responds to inches" do
26
+ @pressure.inches.should be_nil
27
+ end
28
+
29
+ it "responds to metric_default" do
30
+ lambda { @pressure.metric_default = 5 }.should_not raise_error(NotImplementedError)
31
+ end
32
+
33
+ it "responds to imperial_default" do
34
+ lambda { @pressure.imperial_default = 5 }.should_not raise_error(NotImplementedError)
35
+ end
36
+
37
+ it "responds to nil?" do
38
+ @pressure.nil?.should be_true
39
+ @pressure.mb = 5
40
+ @pressure.nil?.should be_false
41
+ end
42
+
43
+ end
44
+
45
+ describe "conversion" do
46
+
47
+ # For all conversions
48
+ # 721.64 mb = 21.31 in
49
+ before(:each) do
50
+ @in = 21.31
51
+ @mb = 721.64
52
+ end
53
+
54
+ it "requires a value, that is either Integer or Float" do
55
+ Barometer::Pressure.mb_to_in(nil).should be_nil
56
+ Barometer::Pressure.in_to_mb(nil).should be_nil
57
+
58
+ not_float_or_integer = "string"
59
+ Barometer::Pressure.mb_to_in(not_float_or_integer).should be_nil
60
+ Barometer::Pressure.in_to_mb(not_float_or_integer).should be_nil
61
+ end
62
+
63
+ it "converts MB to IN" do
64
+ ((Barometer::Pressure.mb_to_in(@mb)*100).round/100.0).should == @in
65
+ end
66
+
67
+ it "converts IN to MB" do
68
+ ((Barometer::Pressure.in_to_mb(@in)*100).round/100.0).should == @mb
69
+ end
70
+
71
+ end
72
+
73
+ describe "updating" do
74
+
75
+ before(:each) do
76
+ @pressure = Barometer::Pressure.new
77
+ @in = 21.31
78
+ @mb = 721.64
79
+ end
80
+
81
+ it "nils IN if new MB converts to a IN that changes more then 1 unit" do
82
+ @pressure.inches = (@in + 1.1)
83
+ @pressure.update_inches(@mb)
84
+ @pressure.inches.should be_nil
85
+ end
86
+
87
+ it "doesn't update IN if new MB converts to a IN that does not change more then 1 unit" do
88
+ @pressure.inches = (@in + 0.9)
89
+ @pressure.update_inches(@mb)
90
+ @pressure.inches.should == (@in + 0.9)
91
+ end
92
+
93
+ it "doesn't set IN if not already set" do
94
+ @pressure.inches.should be_nil
95
+ @pressure.millibars.should be_nil
96
+ @pressure.update_inches(@mb)
97
+ @pressure.inches.should be_nil
98
+ @pressure.millibars.should be_nil
99
+ end
100
+
101
+ it "nils MB if new IN converts to a MB that changes more then 1 unit" do
102
+ @pressure.millibars = (@mb + 1.1)
103
+ @pressure.update_millibars(@in)
104
+ @pressure.millibars.should be_nil
105
+ end
106
+
107
+ it "doesn't update MB if new IN converts to a MB that does not change more then 1 unit" do
108
+ @pressure.millibars = (@mb + 0.9)
109
+ @pressure.update_millibars(@in)
110
+ @pressure.millibars.should == (@mb + 0.9)
111
+ end
112
+
113
+ it "doesn't set MB if not already set" do
114
+ @pressure.inches.should be_nil
115
+ @pressure.millibars.should be_nil
116
+ @pressure.update_millibars(@in)
117
+ @pressure.inches.should be_nil
118
+ @pressure.millibars.should be_nil
119
+ end
120
+
121
+ end
122
+
123
+ describe "storing" do
124
+
125
+ before(:each) do
126
+ @pressure = Barometer::Pressure.new
127
+ @in = 21.31
128
+ @mb = 721.64
129
+ end
130
+
131
+ it "doesn't update MB if nil value (or equivalent)" do
132
+ @pressure.millibars.should be_nil
133
+ @pressure.mb = nil
134
+ @pressure.millibars.should be_nil
135
+ @pressure.mb = "na"
136
+ @pressure.millibars.should be_nil
137
+ end
138
+
139
+ it "stores MB and resets IN" do
140
+ @pressure.millibars.should be_nil
141
+ @pressure.inches = (@in + 1.1)
142
+ @pressure.mb = @mb
143
+ @pressure.millibars.should == @mb
144
+ @pressure.inches.should be_nil
145
+ end
146
+
147
+ it "doesn't update IN if nil value (or equivalent)" do
148
+ @pressure.inches.should be_nil
149
+ @pressure.in = nil
150
+ @pressure.inches.should be_nil
151
+ @pressure.in = "na"
152
+ @pressure.inches.should be_nil
153
+ end
154
+
155
+ it "stores IN and resets MB" do
156
+ @pressure.inches.should be_nil
157
+ @pressure.millibars = (@mb + 1.1)
158
+ @pressure.in = @in
159
+ @pressure.inches.should == @in
160
+ @pressure.millibars.should be_nil
161
+ end
162
+
163
+ end
164
+
165
+ describe "retrieving" do
166
+
167
+ before(:each) do
168
+ @pressure = Barometer::Pressure.new
169
+ @in = 21.31
170
+ @mb = 721.64
171
+ end
172
+
173
+ it "returns MB if it exists" do
174
+ @pressure.mb = @mb
175
+ @pressure.millibars.should == @mb
176
+ @pressure.mb(false).should == @mb
177
+ end
178
+
179
+ it "auto converts from IN if MB is nil and IN exists" do
180
+ @pressure.in = @in
181
+ @pressure.inches.should == @in
182
+ @pressure.millibars.should be_nil
183
+ @pressure.mb(false).should == @mb
184
+ end
185
+
186
+ it "allows a float to be returned for MB" do
187
+ mb = 721.12
188
+ @pressure.mb = mb
189
+ @pressure.millibars.should == mb
190
+ @pressure.mb(true).should == mb.to_i
191
+ @pressure.mb(false).should == mb.to_f
192
+ end
193
+
194
+ it "allows only 2 decimal precision for MB" do
195
+ mb = 721.1234
196
+ @pressure.mb = mb
197
+ @pressure.millibars.should == mb
198
+ @pressure.mb(false).should == 721.12
199
+ end
200
+
201
+ it "returns IN if it exists" do
202
+ @pressure.in = @in
203
+ @pressure.inches.should == @in
204
+ @pressure.in(false).should == @in
205
+ end
206
+
207
+ it "auto converts from MB if IN is nil and MB exists" do
208
+ @pressure.mb = @mb
209
+ @pressure.millibars.should == @mb
210
+ @pressure.inches.should be_nil
211
+ @pressure.in(false).should == @in
212
+ end
213
+
214
+ it "allows a float to be returned for IN" do
215
+ inches = 21.12
216
+ @pressure.in = inches
217
+ @pressure.inches.should == inches
218
+ @pressure.in(true).should == inches.to_i
219
+ @pressure.in(false).should == inches.to_f
220
+ end
221
+
222
+ it "allows only 2 decimal precision for IN" do
223
+ inches = 21.1234
224
+ @pressure.in = inches
225
+ @pressure.inches.should == inches
226
+ @pressure.in(false).should == 21.12
227
+ end
228
+
229
+ end
230
+
231
+ describe "operators" do
232
+
233
+ before(:each) do
234
+ @in = 21.31
235
+ @mb = 721.64
236
+ @pressure_low = Barometer::Pressure.new
237
+ @pressure_low.mb = (@mb - 1.0)
238
+ @pressure_high = Barometer::Pressure.new
239
+ @pressure_high.mb = (@mb + 1.0)
240
+ @pressure = Barometer::Pressure.new
241
+ @pressure.mb = @mb
242
+ @pressure_same = Barometer::Pressure.new
243
+ @pressure_same.mb = @mb
244
+ end
245
+
246
+ it "defines <=>" do
247
+ Barometer::Pressure.method_defined?("<=>").should be_true
248
+ (@pressure_low <=> @pressure_high).should == -1
249
+ (@pressure_high <=> @pressure_low).should == 1
250
+ (@pressure <=> @pressure_same).should == 0
251
+ end
252
+
253
+ it "defines <" do
254
+ Barometer::Pressure.method_defined?("<").should be_true
255
+ @pressure_low.should < @pressure_high
256
+ @pressure_high.should_not < @pressure_low
257
+ @pressure.should_not < @pressure_same
258
+ end
259
+
260
+ it "defines >" do
261
+ Barometer::Pressure.method_defined?(">").should be_true
262
+ @pressure_low.should_not > @pressure_high
263
+ @pressure_high.should > @pressure_low
264
+ @pressure.should_not > @pressure_same
265
+ end
266
+
267
+ it "defines ==" do
268
+ Barometer::Pressure.method_defined?("==").should be_true
269
+ @pressure_low.should_not == @pressure_high
270
+ @pressure.should == @pressure_same
271
+ end
272
+
273
+ it "defines <=" do
274
+ Barometer::Pressure.method_defined?("<=").should be_true
275
+ @pressure_low.should <= @pressure_high
276
+ @pressure_high.should_not <= @pressure_low
277
+ @pressure.should <= @pressure_same
278
+ end
279
+
280
+ it "defines >=" do
281
+ Barometer::Pressure.method_defined?(">=").should be_true
282
+ @pressure_low.should_not >= @pressure_high
283
+ @pressure_high.should >= @pressure_low
284
+ @pressure.should >= @pressure_same
285
+ end
286
+
287
+ end
288
+
289
+ describe "changing units" do
290
+
291
+ before(:each) do
292
+ @in = 21.31
293
+ @mb = 721.64
294
+ @pressure = Barometer::Pressure.new
295
+ @pressure.mb = @mb
296
+ end
297
+
298
+ it "returns just the integer value (no units)" do
299
+ @pressure.metric?.should be_true
300
+ @pressure.to_i.should == @mb.to_i
301
+
302
+ @pressure.imperial!
303
+ @pressure.metric?.should be_false
304
+ @pressure.to_i.should == @in.to_i
305
+ end
306
+
307
+ it "returns just the float value (no units)" do
308
+ @pressure.metric?.should be_true
309
+ @pressure.to_f.should == @mb.to_f
310
+
311
+ @pressure.imperial!
312
+ @pressure.metric?.should be_false
313
+ @pressure.to_f.should == @in.to_f
314
+ end
315
+
316
+ it "returns just the integer value with units" do
317
+ @pressure.metric?.should be_true
318
+ @pressure.to_s.should == "#{@mb.to_i} #{Barometer::Pressure::METRIC_UNITS}"
319
+
320
+ @pressure.imperial!
321
+ @pressure.metric?.should be_false
322
+ @pressure.to_s.should == "#{@in.to_i} #{Barometer::Pressure::IMPERIAL_UNITS}"
323
+ end
324
+
325
+ it "returns just the units" do
326
+ @pressure.metric?.should be_true
327
+ @pressure.units.should == Barometer::Pressure::METRIC_UNITS
328
+
329
+ @pressure.imperial!
330
+ @pressure.metric?.should be_false
331
+ @pressure.units.should == Barometer::Pressure::IMPERIAL_UNITS
332
+ end
333
+
334
+ end
335
+
336
+ end
@@ -0,0 +1,374 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Speed" do
4
+
5
+ describe "when initialized" do
6
+
7
+ it "defines METRIC_UNITS" do
8
+ Barometer::Speed.const_defined?("METRIC_UNITS").should be_true
9
+ Barometer::Speed::METRIC_UNITS.should == "kph"
10
+ end
11
+
12
+ it "defines IMPERIAL_UNITS" do
13
+ Barometer::Speed.const_defined?("IMPERIAL_UNITS").should be_true
14
+ Barometer::Speed::IMPERIAL_UNITS.should == "mph"
15
+ end
16
+
17
+ before(:each) do
18
+ @speed = Barometer::Speed.new
19
+ end
20
+
21
+ it "responds to kilometers" do
22
+ @speed.kilometers.should be_nil
23
+ end
24
+
25
+ it "responds to miles" do
26
+ @speed.miles.should be_nil
27
+ end
28
+
29
+ it "responds to degrees" do
30
+ @speed.degrees.should be_nil
31
+ end
32
+
33
+ it "responds to direction" do
34
+ @speed.direction.should be_nil
35
+ end
36
+
37
+ it "responds to metric_default" do
38
+ lambda { @speed.metric_default = 5 }.should_not raise_error(NotImplementedError)
39
+ end
40
+
41
+ it "responds to imperial_default" do
42
+ lambda { @speed.imperial_default = 5 }.should_not raise_error(NotImplementedError)
43
+ end
44
+
45
+ it "responds to nil?" do
46
+ @speed.nil?.should be_true
47
+ @speed.kph = 5
48
+ @speed.nil?.should be_false
49
+ end
50
+
51
+ end
52
+
53
+ describe "conversion" do
54
+
55
+ # For all conversions
56
+ # 16.09 km/h = 10.0 mph
57
+ before(:each) do
58
+ @m = 10.0
59
+ @km = 16.09
60
+ end
61
+
62
+ it "requires a value, that is either Integer or Float" do
63
+ Barometer::Speed.km_to_m(nil).should be_nil
64
+ Barometer::Speed.m_to_km(nil).should be_nil
65
+
66
+ not_float_or_integer = "string"
67
+ Barometer::Speed.km_to_m(not_float_or_integer).should be_nil
68
+ Barometer::Speed.m_to_km(not_float_or_integer).should be_nil
69
+ end
70
+
71
+ it "converts km/h to mph" do
72
+ # to get equality, we need to tone down the precision
73
+ ((Barometer::Speed.km_to_m(@km)*10).round/10.0).should == @m
74
+ end
75
+
76
+ it "converts mph to km/h" do
77
+ Barometer::Speed.m_to_km(@m).should == @km
78
+ end
79
+
80
+ end
81
+
82
+ describe "updating" do
83
+
84
+ before(:each) do
85
+ @speed = Barometer::Speed.new
86
+ @m = 10.0
87
+ @km = 16.09
88
+ end
89
+
90
+ it "nils M if new KM converts to a M that changes more then 1 unit" do
91
+ @speed.miles = (@m + 1.1)
92
+ @speed.update_miles(@km)
93
+ @speed.miles.should be_nil
94
+ end
95
+
96
+ it "doesn't update M if new KM converts to a M that does not change more then 1 unit" do
97
+ @speed.miles = (@m + 0.9)
98
+ @speed.update_miles(@km)
99
+ @speed.miles.should == (@m + 0.9)
100
+ end
101
+
102
+ it "doesn't set M if not already set" do
103
+ @speed.miles.should be_nil
104
+ @speed.kilometers.should be_nil
105
+ @speed.update_miles(@km)
106
+ @speed.miles.should be_nil
107
+ @speed.kilometers.should be_nil
108
+ end
109
+
110
+ it "nils KM if new M converts to a KM that changes more then 1 unit" do
111
+ @speed.kilometers = (@km + 1.1)
112
+ @speed.update_kilometers(@m)
113
+ @speed.kilometers.should be_nil
114
+ end
115
+
116
+ it "doesn't update KM if new M converts to a KM that does not change more then 1 unit" do
117
+ @speed.kilometers = (@km + 0.9)
118
+ @speed.update_kilometers(@m)
119
+ @speed.kilometers.should == (@km + 0.9)
120
+ end
121
+
122
+ it "doesn't set KM if not already set" do
123
+ @speed.miles.should be_nil
124
+ @speed.kilometers.should be_nil
125
+ @speed.update_kilometers(@m)
126
+ @speed.miles.should be_nil
127
+ @speed.kilometers.should be_nil
128
+ end
129
+
130
+ end
131
+
132
+ describe "storing" do
133
+
134
+ before(:each) do
135
+ @speed = Barometer::Speed.new
136
+ @m = 10.0
137
+ @km = 16.09
138
+ end
139
+
140
+ it "doesn't update KM if nil value (or equivalent)" do
141
+ @speed.kilometers.should be_nil
142
+ @speed.kph = nil
143
+ @speed.kilometers.should be_nil
144
+ @speed.kph = "na"
145
+ @speed.kilometers.should be_nil
146
+ end
147
+
148
+ it "stores KM and resets M" do
149
+ @speed.kilometers.should be_nil
150
+ @speed.miles = (@m + 1.1)
151
+ @speed.kph = @km
152
+ @speed.kilometers.should == @km
153
+ @speed.miles.should be_nil
154
+ end
155
+
156
+ it "doesn't update M if nil value (or equivalent)" do
157
+ @speed.miles.should be_nil
158
+ @speed.mph = nil
159
+ @speed.miles.should be_nil
160
+ @speed.mph = "na"
161
+ @speed.miles.should be_nil
162
+ end
163
+
164
+ it "stores M, resets KM" do
165
+ @speed.miles.should be_nil
166
+ @speed.kilometers = (@km + 1.1)
167
+ @speed.mph = @m
168
+ @speed.miles.should == @m
169
+ @speed.kilometers.should be_nil
170
+ end
171
+
172
+ it "doesn't update direction if nil value (or equivalent)" do
173
+ @speed.direction.should be_nil
174
+ @speed.direction = nil
175
+ @speed.direction.should be_nil
176
+ @speed.direction = "na"
177
+ @speed.direction.should_not be_nil
178
+ end
179
+
180
+ it "stores direction" do
181
+ @speed.direction.should be_nil
182
+ @speed.direction = "SSW"
183
+ @speed.direction.should == "SSW"
184
+ end
185
+
186
+ it "doesn't update degrees if nil value (or equivalent)" do
187
+ @speed.degrees.should be_nil
188
+ @speed.degrees = nil
189
+ @speed.degrees.should be_nil
190
+ @speed.degrees = "na"
191
+ @speed.degrees.should be_nil
192
+ end
193
+
194
+ it "stores degrees" do
195
+ @speed.degrees.should be_nil
196
+ @speed.degrees = 90.0
197
+ @speed.degrees.should == 90.0
198
+ end
199
+
200
+ end
201
+
202
+ describe "retrieving" do
203
+
204
+ before(:each) do
205
+ @speed = Barometer::Speed.new
206
+ @m = 10.0
207
+ @km = 16.09
208
+ end
209
+
210
+ it "returns KM if it exists" do
211
+ @speed.kph = @km
212
+ @speed.kilometers.should == @km
213
+ @speed.kph(false).should == @km
214
+ end
215
+
216
+ it "auto converts from M if KM is nil and M exists" do
217
+ @speed.mph = @m
218
+ @speed.miles.should == @m
219
+ @speed.kilometers.should be_nil
220
+ @speed.kph(false).should == @km
221
+ end
222
+
223
+ it "allows a float to be returned for KM" do
224
+ km = 16.12
225
+ @speed.kph = km
226
+ @speed.kilometers.should == km
227
+ @speed.kph(true).should == km.to_i
228
+ @speed.kph(false).should == km.to_f
229
+ end
230
+
231
+ it "allows only 2 decimal precision for KM" do
232
+ km = 16.1234
233
+ @speed.kph = km
234
+ @speed.kilometers.should == km
235
+ @speed.kph(false).should == 16.12
236
+ end
237
+
238
+ it "returns M if it exists" do
239
+ @speed.mph = @m
240
+ @speed.miles.should == @m
241
+ @speed.mph.should == @m
242
+ end
243
+
244
+ it "auto converts from KM if M is nil and KM exists" do
245
+ @speed.kph = @km
246
+ @speed.kilometers.should == @km
247
+ @speed.miles.should be_nil
248
+ # to get equality, we need to tone down the precision
249
+ ((@speed.mph*10).round/10.0).should == @m
250
+ end
251
+
252
+ it "allows a float to be returned for M" do
253
+ m = 10.12
254
+ @speed.mph = m
255
+ @speed.miles.should == m
256
+ @speed.mph(true).should == m.to_i
257
+ @speed.mph(false).should == m.to_f
258
+ end
259
+
260
+ it "allows only 2 decimal precision for M" do
261
+ m = 10.1234
262
+ @speed.mph = m
263
+ @speed.miles.should == m
264
+ @speed.mph(false).should == 10.12
265
+ end
266
+
267
+ end
268
+
269
+ describe "operators" do
270
+
271
+ before(:each) do
272
+ @m = 10.0
273
+ @km = 16.09
274
+ @speed_low = Barometer::Speed.new
275
+ @speed_low.kph = (@km - 1.0)
276
+ @speed_high = Barometer::Speed.new
277
+ @speed_high.kph = (@km + 1.0)
278
+ @speed = Barometer::Speed.new
279
+ @speed.kph = @km
280
+ @speed_same = Barometer::Speed.new
281
+ @speed_same.kph = @km
282
+ end
283
+
284
+ it "defines <=>" do
285
+ Barometer::Speed.method_defined?("<=>").should be_true
286
+ (@speed_low <=> @speed_high).should == -1
287
+ (@speed_high <=> @speed_low).should == 1
288
+ (@speed <=> @speed_same).should == 0
289
+ end
290
+
291
+ it "defines <" do
292
+ Barometer::Speed.method_defined?("<").should be_true
293
+ @speed_low.should < @speed_high
294
+ @speed_high.should_not < @speed_low
295
+ @speed.should_not < @speed_same
296
+ end
297
+
298
+ it "defines >" do
299
+ Barometer::Speed.method_defined?(">").should be_true
300
+ @speed_low.should_not > @speed_high
301
+ @speed_high.should > @speed_low
302
+ @speed.should_not > @speed_same
303
+ end
304
+
305
+ it "defines ==" do
306
+ Barometer::Speed.method_defined?("==").should be_true
307
+ @speed_low.should_not == @speed_high
308
+ @speed.should == @speed_same
309
+ end
310
+
311
+ it "defines <=" do
312
+ Barometer::Speed.method_defined?("<=").should be_true
313
+ @speed_low.should <= @speed_high
314
+ @speed_high.should_not <= @speed_low
315
+ @speed.should <= @speed_same
316
+ end
317
+
318
+ it "defines >=" do
319
+ Barometer::Speed.method_defined?(">=").should be_true
320
+ @speed_low.should_not >= @speed_high
321
+ @speed_high.should >= @speed_low
322
+ @speed.should >= @speed_same
323
+ end
324
+
325
+ end
326
+
327
+ describe "changing units" do
328
+
329
+ before(:each) do
330
+ @m = 10.51
331
+ @km = ((Barometer::Speed.m_to_km(@m)*100).round/100.0)
332
+ @speed = Barometer::Speed.new
333
+ @speed.mph = @m
334
+ end
335
+
336
+ it "returns just the integer value (no units)" do
337
+ @speed.metric?.should be_true
338
+ @speed.to_i.should == @km.to_i
339
+
340
+ @speed.imperial!
341
+ @speed.metric?.should be_false
342
+ @speed.to_i.should == @m.to_i
343
+ end
344
+
345
+ it "returns just the float value (no units)" do
346
+ @speed.metric?.should be_true
347
+ @speed.to_f.should == @km.to_f
348
+
349
+ @speed.imperial!
350
+ @speed.metric?.should be_false
351
+ @speed.to_f.should == @m.to_f
352
+ end
353
+
354
+ it "returns just the integer value with units" do
355
+ @speed.metric?.should be_true
356
+ @speed.to_s.should == "#{@km.to_i} #{Barometer::Speed::METRIC_UNITS}"
357
+
358
+ @speed.imperial!
359
+ @speed.metric?.should be_false
360
+ @speed.to_s.should == "#{@m.to_i} #{Barometer::Speed::IMPERIAL_UNITS}"
361
+ end
362
+
363
+ it "returns just the units" do
364
+ @speed.metric?.should be_true
365
+ @speed.units.should == Barometer::Speed::METRIC_UNITS
366
+
367
+ @speed.imperial!
368
+ @speed.metric?.should be_false
369
+ @speed.units.should == Barometer::Speed::IMPERIAL_UNITS
370
+ end
371
+
372
+ end
373
+
374
+ end