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
@@ -1,53 +1,53 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Data::Temperature" do
|
4
|
-
|
4
|
+
|
5
5
|
describe "when initialized" do
|
6
|
-
|
6
|
+
|
7
7
|
it "defines METRIC_UNITS" do
|
8
8
|
Data::Temperature.const_defined?("METRIC_UNITS").should be_true
|
9
9
|
Data::Temperature::METRIC_UNITS.should == "C"
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "defines IMPERIAL_UNITS" do
|
13
13
|
Data::Temperature.const_defined?("IMPERIAL_UNITS").should be_true
|
14
14
|
Data::Temperature::IMPERIAL_UNITS.should == "F"
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
before(:each) do
|
18
18
|
@temp = Data::Temperature.new
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "responds to celcius" do
|
22
22
|
@temp.celsius.should be_nil
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "responds to fahrenheit" do
|
26
26
|
@temp.fahrenheit.should be_nil
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "responds to kelvin" do
|
30
30
|
@temp.kelvin.should be_nil
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "responds to metric_default" do
|
34
34
|
lambda { @temp.metric_default = 5 }.should_not raise_error(NotImplementedError)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "responds to imperial_default" do
|
38
38
|
lambda { @temp.imperial_default = 5 }.should_not raise_error(NotImplementedError)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "responds to nil?" do
|
42
42
|
@temp.nil?.should be_true
|
43
43
|
@temp.c = 5
|
44
44
|
@temp.nil?.should be_false
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
describe "conversion" do
|
50
|
-
|
50
|
+
|
51
51
|
# For all conversions
|
52
52
|
# 20.0 C = 293.15 K = 68.0 F
|
53
53
|
before(:each) do
|
@@ -55,7 +55,7 @@ describe "Data::Temperature" do
|
|
55
55
|
@c = 20.0
|
56
56
|
@k = 293.15
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
it "requires a value, that is either Integer or Float" do
|
60
60
|
Data::Temperature.c_to_k(nil).should be_nil
|
61
61
|
Data::Temperature.c_to_f(nil).should be_nil
|
@@ -63,7 +63,7 @@ describe "Data::Temperature" do
|
|
63
63
|
Data::Temperature.f_to_c(nil).should be_nil
|
64
64
|
Data::Temperature.k_to_c(nil).should be_nil
|
65
65
|
Data::Temperature.k_to_f(nil).should be_nil
|
66
|
-
|
66
|
+
|
67
67
|
not_float_or_integer = "string"
|
68
68
|
Data::Temperature.c_to_k(not_float_or_integer).should be_nil
|
69
69
|
Data::Temperature.c_to_f(not_float_or_integer).should be_nil
|
@@ -72,56 +72,56 @@ describe "Data::Temperature" do
|
|
72
72
|
Data::Temperature.k_to_c(not_float_or_integer).should be_nil
|
73
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
|
104
|
-
|
104
|
+
|
105
105
|
describe "updating" do
|
106
|
-
|
106
|
+
|
107
107
|
before(:each) do
|
108
108
|
@temp = Data::Temperature.new
|
109
109
|
@f = 68.0
|
110
110
|
@c = 20.0
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
it "nils F if new C converts to a F that changes more then 1 degree" do
|
114
114
|
@temp.fahrenheit = (@f + 1.1)
|
115
115
|
@temp.update_fahrenheit(@c)
|
116
116
|
@temp.fahrenheit.should be_nil
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
it "doesn't update F if new C converts to a F that does not change more then 1 degree" do
|
120
120
|
@temp.fahrenheit = (@f + 0.9)
|
121
121
|
@temp.update_fahrenheit(@c)
|
122
122
|
@temp.fahrenheit.should == (@f + 0.9)
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
it "doesn't set F if not already set" do
|
126
126
|
@temp.fahrenheit.should be_nil
|
127
127
|
@temp.celsius.should be_nil
|
@@ -129,19 +129,19 @@ describe "Data::Temperature" do
|
|
129
129
|
@temp.fahrenheit.should be_nil
|
130
130
|
@temp.celsius.should be_nil
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
it "nils C if new F converts to a C that changes more then 1 degree" do
|
134
134
|
@temp.celsius = (@c + 1.1)
|
135
135
|
@temp.update_celsius(@f)
|
136
136
|
@temp.celsius.should be_nil
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
it "doesn't update C if new F converts to a C that does not change more then 1 degree" do
|
140
140
|
@temp.celsius = (@c + 0.9)
|
141
141
|
@temp.update_celsius(@f)
|
142
142
|
@temp.celsius.should == (@c + 0.9)
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it "doesn't set C if not already set" do
|
146
146
|
@temp.fahrenheit.should be_nil
|
147
147
|
@temp.celsius.should be_nil
|
@@ -149,18 +149,18 @@ describe "Data::Temperature" do
|
|
149
149
|
@temp.fahrenheit.should be_nil
|
150
150
|
@temp.celsius.should be_nil
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
describe "storing" do
|
156
|
-
|
156
|
+
|
157
157
|
before(:each) do
|
158
158
|
@temp = Data::Temperature.new
|
159
159
|
@f = 68.0
|
160
160
|
@c = 20.0
|
161
161
|
@k = 293.15
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
it "doesn't update C if nil value (or equivalent)" do
|
165
165
|
@temp.celsius.should be_nil
|
166
166
|
@temp.c = nil
|
@@ -168,7 +168,7 @@ describe "Data::Temperature" do
|
|
168
168
|
@temp.c = "na"
|
169
169
|
@temp.celsius.should be_nil
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
it "stores C, convert to K and reset F" do
|
173
173
|
@temp.celsius.should be_nil
|
174
174
|
@temp.fahrenheit = (@f + 1.1)
|
@@ -178,7 +178,7 @@ describe "Data::Temperature" do
|
|
178
178
|
@temp.kelvin.should == @k
|
179
179
|
@temp.fahrenheit.should be_nil
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
it "doesn't update F if nil value (or equivalent)" do
|
183
183
|
@temp.fahrenheit.should be_nil
|
184
184
|
@temp.f = nil
|
@@ -186,7 +186,7 @@ describe "Data::Temperature" do
|
|
186
186
|
@temp.f = "na"
|
187
187
|
@temp.fahrenheit.should be_nil
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
it "stores F, convert to K and reset C" do
|
191
191
|
@temp.fahrenheit.should be_nil
|
192
192
|
@temp.celsius = (@c + 1.1)
|
@@ -196,7 +196,7 @@ describe "Data::Temperature" do
|
|
196
196
|
@temp.kelvin.should == @k
|
197
197
|
@temp.celsius.should be_nil
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
it "doesn't update K if nil value (or equivalent)" do
|
201
201
|
@temp.kelvin.should be_nil
|
202
202
|
@temp.k = nil
|
@@ -204,7 +204,7 @@ describe "Data::Temperature" do
|
|
204
204
|
@temp.k = "na"
|
205
205
|
@temp.kelvin.should be_nil
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
it "stores K, convert to F and C" do
|
209
209
|
@temp.celsius.should be_nil
|
210
210
|
@temp.fahrenheit.should be_nil
|
@@ -214,24 +214,24 @@ describe "Data::Temperature" do
|
|
214
214
|
@temp.fahrenheit.should == @f
|
215
215
|
@temp.kelvin.should == @k
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
describe "retrieving" do
|
221
|
-
|
221
|
+
|
222
222
|
before(:each) do
|
223
223
|
@temp = Data::Temperature.new
|
224
224
|
@f = 68.0
|
225
225
|
@c = 20.0
|
226
226
|
@k = 293.15
|
227
227
|
end
|
228
|
-
|
228
|
+
|
229
229
|
it "returns C if it exists" do
|
230
230
|
@temp.c = @c
|
231
231
|
@temp.celsius.should == @c
|
232
232
|
@temp.c.should == @c
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
it "auto converts from K if C is nil and K exists" do
|
236
236
|
@temp.f = @f
|
237
237
|
@temp.fahrenheit.should == @f
|
@@ -239,7 +239,7 @@ describe "Data::Temperature" do
|
|
239
239
|
@temp.celsius.should be_nil
|
240
240
|
@temp.c.should == @c
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
it "allows a float to be returned for C" do
|
244
244
|
c = 20.12
|
245
245
|
@temp.c = c
|
@@ -247,20 +247,20 @@ describe "Data::Temperature" do
|
|
247
247
|
@temp.c(true).should == c.to_i
|
248
248
|
@temp.c(false).should == c.to_f
|
249
249
|
end
|
250
|
-
|
250
|
+
|
251
251
|
it "allows only 2 decimal precision for C" do
|
252
252
|
c = 20.1234
|
253
253
|
@temp.c = c
|
254
254
|
@temp.celsius.should == c
|
255
255
|
@temp.c(false).should == 20.12
|
256
256
|
end
|
257
|
-
|
257
|
+
|
258
258
|
it "returns F if it exists" do
|
259
259
|
@temp.f = @f
|
260
260
|
@temp.fahrenheit.should == @f
|
261
261
|
@temp.f.should == @f
|
262
262
|
end
|
263
|
-
|
263
|
+
|
264
264
|
it "auto converts from K if F is nil and K exists" do
|
265
265
|
@temp.c = @c
|
266
266
|
@temp.celsius.should == @c
|
@@ -268,7 +268,7 @@ describe "Data::Temperature" do
|
|
268
268
|
@temp.fahrenheit.should be_nil
|
269
269
|
@temp.f.should == @f
|
270
270
|
end
|
271
|
-
|
271
|
+
|
272
272
|
it "allows a float to be returned for F" do
|
273
273
|
f = 68.12
|
274
274
|
@temp.f = f
|
@@ -276,18 +276,18 @@ describe "Data::Temperature" do
|
|
276
276
|
@temp.f(true).should == f.to_i
|
277
277
|
@temp.f(false).should == f.to_f
|
278
278
|
end
|
279
|
-
|
279
|
+
|
280
280
|
it "allows only 2 decimal precision for F" do
|
281
281
|
f = 68.1234
|
282
282
|
@temp.f = f
|
283
283
|
@temp.fahrenheit.should == f
|
284
284
|
@temp.f(false).should == 68.12
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
end
|
288
|
-
|
288
|
+
|
289
289
|
describe "operators" do
|
290
|
-
|
290
|
+
|
291
291
|
before(:each) do
|
292
292
|
@f = 68.0
|
293
293
|
@c = 20.0
|
@@ -301,52 +301,52 @@ describe "Data::Temperature" do
|
|
301
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
|
344
344
|
end
|
345
|
-
|
345
|
+
|
346
346
|
end
|
347
|
-
|
347
|
+
|
348
348
|
describe "changing units" do
|
349
|
-
|
349
|
+
|
350
350
|
before(:each) do
|
351
351
|
@c = 20.5
|
352
352
|
@f = Data::Temperature.c_to_f(@c)
|
@@ -354,11 +354,11 @@ describe "Data::Temperature" do
|
|
354
354
|
@temp = Data::Temperature.new
|
355
355
|
@temp.k = @k
|
356
356
|
end
|
357
|
-
|
357
|
+
|
358
358
|
it "returns just the integer value (no units)" do
|
359
359
|
@temp.metric?.should be_true
|
360
360
|
@temp.to_i.should == @c.to_i
|
361
|
-
|
361
|
+
|
362
362
|
@temp.imperial!
|
363
363
|
@temp.metric?.should be_false
|
364
364
|
@temp.to_i.should == @f.to_i
|
@@ -372,7 +372,7 @@ describe "Data::Temperature" do
|
|
372
372
|
@temp.metric?.should be_false
|
373
373
|
@temp.to_f.should == @f.to_f
|
374
374
|
end
|
375
|
-
|
375
|
+
|
376
376
|
it "returns just the integer value with units" do
|
377
377
|
@temp.metric?.should be_true
|
378
378
|
@temp.to_s.should == "#{@c.to_i} #{Data::Temperature::METRIC_UNITS}"
|
@@ -381,7 +381,7 @@ describe "Data::Temperature" do
|
|
381
381
|
@temp.metric?.should be_false
|
382
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
387
|
@temp.units.should == Data::Temperature::METRIC_UNITS
|
@@ -392,5 +392,5 @@ describe "Data::Temperature" do
|
|
392
392
|
end
|
393
393
|
|
394
394
|
end
|
395
|
-
|
396
|
-
end
|
395
|
+
|
396
|
+
end
|
data/spec/data/units_spec.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Units" do
|
4
|
-
|
4
|
+
|
5
5
|
describe "when initialized" do
|
6
|
-
|
6
|
+
|
7
7
|
before(:each) do
|
8
8
|
@units = Data::Units.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "responds to metric, defaults to true" do
|
12
12
|
@units.metric.should be_true
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "allows metric to be set" do
|
16
16
|
@units.metric.should be_true
|
17
|
-
|
17
|
+
|
18
18
|
@units2 = Data::Units.new(false)
|
19
19
|
@units2.metric.should be_false
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "stubs metric_default" do
|
23
23
|
lambda { @units.metric_default = 5 }.should raise_error(NotImplementedError)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "stubs imperial_default" do
|
27
27
|
lambda { @units.imperial_default = 5 }.should raise_error(NotImplementedError)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
describe "changing units" do
|
33
|
-
|
33
|
+
|
34
34
|
before(:each) do
|
35
35
|
@units = Data::Units.new
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "indicates if metric?" do
|
39
39
|
@units.metric.should be_true
|
40
40
|
@units.metric?.should be_true
|
@@ -42,13 +42,13 @@ describe "Units" do
|
|
42
42
|
@units.metric.should be_false
|
43
43
|
@units.metric?.should be_false
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "changes to imperial" do
|
47
47
|
@units.metric?.should be_true
|
48
48
|
@units.imperial!
|
49
49
|
@units.metric?.should be_false
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "changes to metric" do
|
53
53
|
@units.metric = false
|
54
54
|
@units.metric?.should be_false
|
@@ -57,9 +57,9 @@ describe "Units" do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
describe "when assigning values" do
|
62
|
-
|
62
|
+
|
63
63
|
before(:each) do
|
64
64
|
module Barometer
|
65
65
|
class Data::Units
|
@@ -77,25 +77,25 @@ describe "Units" do
|
|
77
77
|
@test_value_a = 5.5
|
78
78
|
@test_value_b = 9.9
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "assigns metric_default" do
|
82
82
|
@units_metric.metric?.should be_true
|
83
83
|
@units_metric << @test_value_a
|
84
84
|
@units_metric.a.should == @test_value_a
|
85
|
-
|
85
|
+
|
86
86
|
@units_metric << [@test_value_b, @test_value_a]
|
87
87
|
@units_metric.a.should == @test_value_b
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "assigns imperial_default" do
|
91
91
|
@units_imperial.metric?.should be_false
|
92
92
|
@units_imperial << @test_value_a
|
93
93
|
@units_imperial.b.should == @test_value_a
|
94
|
-
|
94
|
+
|
95
95
|
@units_imperial << [@test_value_a, @test_value_b]
|
96
96
|
@units_imperial.b.should == @test_value_b
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
end
|
100
100
|
|
101
|
-
end
|
101
|
+
end
|