barometer 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/LICENSE +1 -1
  4. data/{README.rdoc → README.md} +124 -110
  5. data/Rakefile +1 -21
  6. data/TODO +8 -9
  7. data/barometer.gemspec +20 -19
  8. data/bin/barometer +36 -83
  9. data/lib/barometer.rb +13 -11
  10. data/lib/barometer/base.rb +10 -10
  11. data/lib/barometer/data.rb +1 -1
  12. data/lib/barometer/data/distance.rb +25 -25
  13. data/lib/barometer/data/geo.rb +9 -9
  14. data/lib/barometer/data/local_datetime.rb +24 -20
  15. data/lib/barometer/data/local_time.rb +13 -13
  16. data/lib/barometer/data/location.rb +6 -6
  17. data/lib/barometer/data/pressure.rb +24 -24
  18. data/lib/barometer/data/speed.rb +28 -28
  19. data/lib/barometer/data/sun.rb +7 -7
  20. data/lib/barometer/data/temperature.rb +29 -29
  21. data/lib/barometer/data/units.rb +9 -9
  22. data/lib/barometer/data/zone.rb +19 -19
  23. data/lib/barometer/formats.rb +1 -1
  24. data/lib/barometer/formats/coordinates.rb +7 -7
  25. data/lib/barometer/formats/format.rb +6 -6
  26. data/lib/barometer/formats/geocode.rb +5 -5
  27. data/lib/barometer/formats/icao.rb +6 -6
  28. data/lib/barometer/formats/postalcode.rb +3 -3
  29. data/lib/barometer/formats/short_zipcode.rb +2 -2
  30. data/lib/barometer/formats/weather_id.rb +10 -10
  31. data/lib/barometer/formats/woe_id.rb +20 -20
  32. data/lib/barometer/formats/zipcode.rb +3 -3
  33. data/lib/barometer/key_file_parser.rb +20 -0
  34. data/lib/barometer/measurements/measurement.rb +32 -32
  35. data/lib/barometer/measurements/result.rb +39 -39
  36. data/lib/barometer/measurements/result_array.rb +12 -12
  37. data/lib/barometer/query.rb +15 -15
  38. data/lib/barometer/services.rb +3 -3
  39. data/lib/barometer/translations/icao_country_codes.yml +20 -20
  40. data/lib/barometer/translations/weather_country_codes.yml +1 -1
  41. data/lib/barometer/translations/zone_codes.yml +2 -2
  42. data/lib/barometer/version.rb +3 -0
  43. data/lib/barometer/weather.rb +27 -27
  44. data/lib/barometer/weather_services/noaa.rb +314 -3
  45. data/lib/barometer/weather_services/service.rb +32 -30
  46. data/lib/barometer/weather_services/weather_bug.rb +35 -33
  47. data/lib/barometer/weather_services/wunderground.rb +31 -29
  48. data/lib/barometer/weather_services/yahoo.rb +36 -35
  49. data/lib/barometer/web_services/geocode.rb +5 -7
  50. data/lib/barometer/web_services/noaa_station_id.rb +53 -0
  51. data/lib/barometer/web_services/placemaker.rb +11 -13
  52. data/lib/barometer/web_services/timezone.rb +5 -7
  53. data/lib/barometer/web_services/weather_id.rb +4 -6
  54. data/lib/barometer/web_services/web_service.rb +4 -4
  55. data/spec/barometer_spec.rb +25 -27
  56. data/spec/cassettes/Barometer.json +1 -0
  57. data/spec/cassettes/Query.json +1 -0
  58. data/spec/cassettes/Query_Format_Coordinates.json +1 -0
  59. data/spec/cassettes/Query_Format_Geocode.json +1 -0
  60. data/spec/cassettes/Query_Format_WeatherID.json +1 -0
  61. data/spec/cassettes/Query_Format_WoeID.json +1 -0
  62. data/spec/cassettes/WeatherService.json +1 -0
  63. data/spec/cassettes/WeatherService_Noaa.json +1 -0
  64. data/spec/cassettes/WeatherService_WeatherBug.json +1 -0
  65. data/spec/cassettes/WeatherService_Wunderground.json +1 -0
  66. data/spec/cassettes/WeatherService_Yahoo.json +1 -0
  67. data/spec/cassettes/WebService_Geocode.json +1 -0
  68. data/spec/cassettes/WebService_NoaaStation.json +1 -0
  69. data/spec/data/distance_spec.rb +60 -60
  70. data/spec/data/geo_spec.rb +23 -23
  71. data/spec/data/local_datetime_spec.rb +44 -44
  72. data/spec/data/local_time_spec.rb +47 -47
  73. data/spec/data/location_spec.rb +16 -16
  74. data/spec/data/pressure_spec.rb +61 -61
  75. data/spec/data/speed_spec.rb +69 -69
  76. data/spec/data/sun_spec.rb +25 -25
  77. data/spec/data/temperature_spec.rb +68 -68
  78. data/spec/data/units_spec.rb +21 -21
  79. data/spec/data/zone_spec.rb +35 -35
  80. data/spec/formats/coordinates_spec.rb +27 -27
  81. data/spec/formats/format_spec.rb +17 -25
  82. data/spec/formats/geocode_spec.rb +23 -31
  83. data/spec/formats/icao_spec.rb +26 -32
  84. data/spec/formats/postalcode_spec.rb +22 -28
  85. data/spec/formats/short_zipcode_spec.rb +20 -26
  86. data/spec/formats/weather_id_spec.rb +57 -67
  87. data/spec/formats/woe_id_spec.rb +59 -59
  88. data/spec/formats/zipcode_spec.rb +39 -47
  89. data/spec/key_file_parser_spec.rb +28 -0
  90. data/spec/measurements/measurement_spec.rb +79 -133
  91. data/spec/measurements/result_array_spec.rb +23 -38
  92. data/spec/measurements/result_spec.rb +100 -128
  93. data/spec/query_spec.rb +83 -100
  94. data/spec/spec_helper.rb +24 -6
  95. data/spec/weather_services/noaa_spec.rb +179 -0
  96. data/spec/weather_services/services_spec.rb +28 -36
  97. data/spec/weather_services/weather_bug_spec.rb +57 -77
  98. data/spec/weather_services/wunderground_spec.rb +36 -65
  99. data/spec/weather_services/yahoo_spec.rb +38 -60
  100. data/spec/weather_spec.rb +79 -79
  101. data/spec/web_services/geocode_spec.rb +7 -11
  102. data/spec/web_services/noaa_station_id_spec.rb +33 -0
  103. data/spec/web_services/placemaker_spec.rb +7 -12
  104. data/spec/web_services/web_services_spec.rb +3 -9
  105. metadata +214 -163
  106. data/VERSION.yml +0 -5
  107. data/lib/barometer/weather_services/google.rb +0 -142
  108. data/lib/barometer/weather_services/weather_dot_com.rb +0 -279
  109. data/spec/fakeweb_helper.rb +0 -179
  110. data/spec/fixtures/formats/weather_id/90210.xml +0 -7
  111. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +0 -3
  112. data/spec/fixtures/formats/weather_id/ksfo.xml +0 -1
  113. data/spec/fixtures/formats/weather_id/manhattan.xml +0 -7
  114. data/spec/fixtures/formats/weather_id/new_york.xml +0 -1
  115. data/spec/fixtures/formats/weather_id/the_hills.xml +0 -1
  116. data/spec/fixtures/geocode/40_73_v3.json +0 -497
  117. data/spec/fixtures/geocode/90210_v3.json +0 -63
  118. data/spec/fixtures/geocode/T5B4M9_v3.json +0 -68
  119. data/spec/fixtures/geocode/atlanta_v3.json +0 -58
  120. data/spec/fixtures/geocode/calgary_ab_v3.json +0 -58
  121. data/spec/fixtures/geocode/ksfo_v3.json +0 -73
  122. data/spec/fixtures/geocode/newyork_ny_v3.json +0 -58
  123. data/spec/fixtures/services/google/calgary_ab.xml +0 -1
  124. data/spec/fixtures/services/placemaker/T5B4M9.xml +0 -65
  125. data/spec/fixtures/services/placemaker/atlanta.xml +0 -65
  126. data/spec/fixtures/services/placemaker/coords.xml +0 -65
  127. data/spec/fixtures/services/placemaker/ksfo.xml +0 -65
  128. data/spec/fixtures/services/placemaker/new_york.xml +0 -65
  129. data/spec/fixtures/services/placemaker/the_hills.xml +0 -65
  130. data/spec/fixtures/services/placemaker/w615702.xml +0 -47
  131. data/spec/fixtures/services/weather_bug/90210_current.xml +0 -93
  132. data/spec/fixtures/services/weather_bug/90210_forecast.xml +0 -76
  133. data/spec/fixtures/services/weather_dot_com/90210.xml +0 -1
  134. data/spec/fixtures/services/wunderground/current_calgary_ab.xml +0 -9
  135. data/spec/fixtures/services/wunderground/forecast_calgary_ab.xml +0 -13
  136. data/spec/fixtures/services/yahoo/90210.xml +0 -3
  137. data/spec/weather_services/google_spec.rb +0 -181
  138. data/spec/weather_services/weather_dot_com_spec.rb +0 -224
@@ -1,59 +1,59 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Location" do
4
-
4
+
5
5
  describe "when initialized" do
6
-
6
+
7
7
  before(:each) do
8
8
  @location = Data::Location.new
9
9
  end
10
-
10
+
11
11
  it "responds to id" do
12
12
  @location.id.should be_nil
13
13
  end
14
-
14
+
15
15
  it "responds to name" do
16
16
  @location.name.should be_nil
17
17
  end
18
-
18
+
19
19
  it "responds to city" do
20
20
  @location.city.should be_nil
21
21
  end
22
-
22
+
23
23
  it "responds to state_name" do
24
24
  @location.state_name.should be_nil
25
25
  end
26
-
26
+
27
27
  it "responds to state_code" do
28
28
  @location.state_code.should be_nil
29
29
  end
30
-
30
+
31
31
  it "responds to country" do
32
32
  @location.country.should be_nil
33
33
  end
34
-
34
+
35
35
  it "responds to country_code" do
36
36
  @location.country_code.should be_nil
37
37
  end
38
-
38
+
39
39
  it "responds to zip_code" do
40
40
  @location.zip_code.should be_nil
41
41
  end
42
-
42
+
43
43
  it "responds to latitude" do
44
44
  @location.latitude.should be_nil
45
45
  end
46
-
46
+
47
47
  it "responds to longitude" do
48
48
  @location.longitude.should be_nil
49
49
  end
50
-
50
+
51
51
  it "responds to coordinates" do
52
52
  @location.longitude = "99.99"
53
53
  @location.latitude = "88.88"
54
54
  @location.coordinates.should == [@location.latitude, @location.longitude].join(',')
55
55
  end
56
-
56
+
57
57
  it "should print a string" do
58
58
  @location = Data::Location.new
59
59
  @location.to_s.should == ""
@@ -66,5 +66,5 @@ describe "Location" do
66
66
  end
67
67
 
68
68
  end
69
-
70
- end
69
+
70
+ end
@@ -1,95 +1,95 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Pressure" do
4
-
4
+
5
5
  describe "when initialized" do
6
-
6
+
7
7
  before(:each) do
8
8
  @pressure = Data::Pressure.new
9
9
  end
10
-
10
+
11
11
  it "defines METRIC_UNITS" do
12
12
  Data::Pressure.const_defined?("METRIC_UNITS").should be_true
13
13
  Data::Pressure::METRIC_UNITS.should == "mb"
14
14
  end
15
-
15
+
16
16
  it "defines IMPERIAL_UNITS" do
17
17
  Data::Pressure.const_defined?("IMPERIAL_UNITS").should be_true
18
18
  Data::Pressure::IMPERIAL_UNITS.should == "in"
19
19
  end
20
-
20
+
21
21
  it "responds to millibars" do
22
22
  @pressure.millibars.should be_nil
23
23
  end
24
-
24
+
25
25
  it "responds to inches" do
26
26
  @pressure.inches.should be_nil
27
27
  end
28
-
28
+
29
29
  it "responds to metric_default" do
30
30
  lambda { @pressure.metric_default = 5 }.should_not raise_error(NotImplementedError)
31
31
  end
32
-
32
+
33
33
  it "responds to imperial_default" do
34
34
  lambda { @pressure.imperial_default = 5 }.should_not raise_error(NotImplementedError)
35
35
  end
36
-
36
+
37
37
  it "responds to nil?" do
38
38
  @pressure.nil?.should be_true
39
39
  @pressure.mb = 5
40
40
  @pressure.nil?.should be_false
41
41
  end
42
-
42
+
43
43
  end
44
-
44
+
45
45
  describe "conversion" do
46
-
46
+
47
47
  # For all conversions
48
48
  # 721.64 mb = 21.31 in
49
49
  before(:each) do
50
50
  @in = 21.31
51
51
  @mb = 721.64
52
52
  end
53
-
53
+
54
54
  it "requires a value, that is either Integer or Float" do
55
55
  Data::Pressure.mb_to_in(nil).should be_nil
56
56
  Data::Pressure.in_to_mb(nil).should be_nil
57
-
57
+
58
58
  not_float_or_integer = "string"
59
59
  Data::Pressure.mb_to_in(not_float_or_integer).should be_nil
60
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
72
-
72
+
73
73
  describe "updating" do
74
-
74
+
75
75
  before(:each) do
76
76
  @pressure = Data::Pressure.new
77
77
  @in = 21.31
78
78
  @mb = 721.64
79
79
  end
80
-
80
+
81
81
  it "nils IN if new MB converts to a IN that changes more then 1 unit" do
82
82
  @pressure.inches = (@in + 1.1)
83
83
  @pressure.update_inches(@mb)
84
84
  @pressure.inches.should be_nil
85
85
  end
86
-
86
+
87
87
  it "doesn't update IN if new MB converts to a IN that does not change more then 1 unit" do
88
88
  @pressure.inches = (@in + 0.9)
89
89
  @pressure.update_inches(@mb)
90
90
  @pressure.inches.should == (@in + 0.9)
91
91
  end
92
-
92
+
93
93
  it "doesn't set IN if not already set" do
94
94
  @pressure.inches.should be_nil
95
95
  @pressure.millibars.should be_nil
@@ -97,19 +97,19 @@ describe "Pressure" do
97
97
  @pressure.inches.should be_nil
98
98
  @pressure.millibars.should be_nil
99
99
  end
100
-
100
+
101
101
  it "nils MB if new IN converts to a MB that changes more then 1 unit" do
102
102
  @pressure.millibars = (@mb + 1.1)
103
103
  @pressure.update_millibars(@in)
104
104
  @pressure.millibars.should be_nil
105
105
  end
106
-
106
+
107
107
  it "doesn't update MB if new IN converts to a MB that does not change more then 1 unit" do
108
108
  @pressure.millibars = (@mb + 0.9)
109
109
  @pressure.update_millibars(@in)
110
110
  @pressure.millibars.should == (@mb + 0.9)
111
111
  end
112
-
112
+
113
113
  it "doesn't set MB if not already set" do
114
114
  @pressure.inches.should be_nil
115
115
  @pressure.millibars.should be_nil
@@ -117,17 +117,17 @@ describe "Pressure" do
117
117
  @pressure.inches.should be_nil
118
118
  @pressure.millibars.should be_nil
119
119
  end
120
-
120
+
121
121
  end
122
-
122
+
123
123
  describe "storing" do
124
-
124
+
125
125
  before(:each) do
126
126
  @pressure = Data::Pressure.new
127
127
  @in = 21.31
128
128
  @mb = 721.64
129
129
  end
130
-
130
+
131
131
  it "doesn't update MB if nil value (or equivalent)" do
132
132
  @pressure.millibars.should be_nil
133
133
  @pressure.mb = nil
@@ -135,7 +135,7 @@ describe "Pressure" do
135
135
  @pressure.mb = "na"
136
136
  @pressure.millibars.should be_nil
137
137
  end
138
-
138
+
139
139
  it "stores MB and resets IN" do
140
140
  @pressure.millibars.should be_nil
141
141
  @pressure.inches = (@in + 1.1)
@@ -143,7 +143,7 @@ describe "Pressure" do
143
143
  @pressure.millibars.should == @mb
144
144
  @pressure.inches.should be_nil
145
145
  end
146
-
146
+
147
147
  it "doesn't update IN if nil value (or equivalent)" do
148
148
  @pressure.inches.should be_nil
149
149
  @pressure.in = nil
@@ -151,7 +151,7 @@ describe "Pressure" do
151
151
  @pressure.in = "na"
152
152
  @pressure.inches.should be_nil
153
153
  end
154
-
154
+
155
155
  it "stores IN and resets MB" do
156
156
  @pressure.inches.should be_nil
157
157
  @pressure.millibars = (@mb + 1.1)
@@ -159,30 +159,30 @@ describe "Pressure" do
159
159
  @pressure.inches.should == @in
160
160
  @pressure.millibars.should be_nil
161
161
  end
162
-
162
+
163
163
  end
164
-
164
+
165
165
  describe "retrieving" do
166
-
166
+
167
167
  before(:each) do
168
168
  @pressure = Data::Pressure.new
169
169
  @in = 21.31
170
170
  @mb = 721.64
171
171
  end
172
-
172
+
173
173
  it "returns MB if it exists" do
174
174
  @pressure.mb = @mb
175
175
  @pressure.millibars.should == @mb
176
176
  @pressure.mb(false).should == @mb
177
177
  end
178
-
178
+
179
179
  it "auto converts from IN if MB is nil and IN exists" do
180
180
  @pressure.in = @in
181
181
  @pressure.inches.should == @in
182
182
  @pressure.millibars.should be_nil
183
183
  @pressure.mb(false).should == @mb
184
184
  end
185
-
185
+
186
186
  it "allows a float to be returned for MB" do
187
187
  mb = 721.12
188
188
  @pressure.mb = mb
@@ -190,27 +190,27 @@ describe "Pressure" do
190
190
  @pressure.mb(true).should == mb.to_i
191
191
  @pressure.mb(false).should == mb.to_f
192
192
  end
193
-
193
+
194
194
  it "allows only 2 decimal precision for MB" do
195
195
  mb = 721.1234
196
196
  @pressure.mb = mb
197
197
  @pressure.millibars.should == mb
198
198
  @pressure.mb(false).should == 721.12
199
199
  end
200
-
200
+
201
201
  it "returns IN if it exists" do
202
202
  @pressure.in = @in
203
203
  @pressure.inches.should == @in
204
204
  @pressure.in(false).should == @in
205
205
  end
206
-
206
+
207
207
  it "auto converts from MB if IN is nil and MB exists" do
208
208
  @pressure.mb = @mb
209
209
  @pressure.millibars.should == @mb
210
210
  @pressure.inches.should be_nil
211
211
  @pressure.in(false).should == @in
212
212
  end
213
-
213
+
214
214
  it "allows a float to be returned for IN" do
215
215
  inches = 21.12
216
216
  @pressure.in = inches
@@ -218,18 +218,18 @@ describe "Pressure" do
218
218
  @pressure.in(true).should == inches.to_i
219
219
  @pressure.in(false).should == inches.to_f
220
220
  end
221
-
221
+
222
222
  it "allows only 2 decimal precision for IN" do
223
223
  inches = 21.1234
224
224
  @pressure.in = inches
225
225
  @pressure.inches.should == inches
226
226
  @pressure.in(false).should == 21.12
227
227
  end
228
-
228
+
229
229
  end
230
-
230
+
231
231
  describe "operators" do
232
-
232
+
233
233
  before(:each) do
234
234
  @in = 21.31
235
235
  @mb = 721.64
@@ -242,63 +242,63 @@ describe "Pressure" do
242
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
285
285
  end
286
-
286
+
287
287
  end
288
-
288
+
289
289
  describe "changing units" do
290
-
290
+
291
291
  before(:each) do
292
292
  @in = 21.31
293
293
  @mb = 721.64
294
294
  @pressure = Data::Pressure.new
295
295
  @pressure.mb = @mb
296
296
  end
297
-
297
+
298
298
  it "returns just the integer value (no units)" do
299
299
  @pressure.metric?.should be_true
300
300
  @pressure.to_i.should == @mb.to_i
301
-
301
+
302
302
  @pressure.imperial!
303
303
  @pressure.metric?.should be_false
304
304
  @pressure.to_i.should == @in.to_i
@@ -312,7 +312,7 @@ describe "Pressure" do
312
312
  @pressure.metric?.should be_false
313
313
  @pressure.to_f.should == @in.to_f
314
314
  end
315
-
315
+
316
316
  it "returns just the integer value with units" do
317
317
  @pressure.metric?.should be_true
318
318
  @pressure.to_s.should == "#{@mb.to_i} #{Data::Pressure::METRIC_UNITS}"
@@ -321,7 +321,7 @@ describe "Pressure" do
321
321
  @pressure.metric?.should be_false
322
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
327
  @pressure.units.should == Data::Pressure::METRIC_UNITS
@@ -332,5 +332,5 @@ describe "Pressure" do
332
332
  end
333
333
 
334
334
  end
335
-
336
- end
335
+
336
+ end