barometer 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.rdoc +78 -70
  2. data/VERSION.yml +2 -2
  3. data/bin/barometer +100 -37
  4. data/lib/barometer.rb +12 -8
  5. data/lib/barometer/base.rb +48 -20
  6. data/lib/barometer/data.rb +5 -1
  7. data/lib/barometer/data/current.rb +23 -15
  8. data/lib/barometer/data/distance.rb +15 -5
  9. data/lib/barometer/data/forecast.rb +23 -5
  10. data/lib/barometer/data/geo.rb +16 -54
  11. data/lib/barometer/data/local_datetime.rb +137 -0
  12. data/lib/barometer/data/local_time.rb +134 -0
  13. data/lib/barometer/data/location.rb +6 -1
  14. data/lib/barometer/data/measurement.rb +71 -42
  15. data/lib/barometer/data/night.rb +69 -0
  16. data/lib/barometer/data/pressure.rb +15 -5
  17. data/lib/barometer/data/speed.rb +16 -5
  18. data/lib/barometer/data/sun.rb +8 -20
  19. data/lib/barometer/data/temperature.rb +22 -9
  20. data/lib/barometer/data/units.rb +10 -19
  21. data/lib/barometer/data/zone.rb +135 -9
  22. data/lib/barometer/formats.rb +12 -0
  23. data/lib/barometer/formats/coordinates.rb +42 -0
  24. data/lib/barometer/formats/format.rb +46 -0
  25. data/lib/barometer/formats/geocode.rb +51 -0
  26. data/lib/barometer/formats/icao.rb +37 -0
  27. data/lib/barometer/formats/postalcode.rb +22 -0
  28. data/lib/barometer/formats/short_zipcode.rb +17 -0
  29. data/lib/barometer/formats/weather_id.rb +107 -0
  30. data/lib/barometer/formats/zipcode.rb +31 -0
  31. data/lib/barometer/query.rb +61 -232
  32. data/lib/barometer/services.rb +14 -4
  33. data/lib/barometer/translations/icao_country_codes.yml +9 -0
  34. data/lib/barometer/translations/weather_country_codes.yml +17 -0
  35. data/lib/barometer/weather.rb +51 -30
  36. data/lib/barometer/{services → weather_services}/google.rb +23 -26
  37. data/lib/barometer/weather_services/noaa.rb +6 -0
  38. data/lib/barometer/{services → weather_services}/service.rb +101 -92
  39. data/lib/barometer/weather_services/weather_bug.rb +6 -0
  40. data/lib/barometer/weather_services/weather_dot_com.rb +261 -0
  41. data/lib/barometer/{services → weather_services}/wunderground.rb +58 -76
  42. data/lib/barometer/{services → weather_services}/yahoo.rb +91 -121
  43. data/lib/barometer/web_services/geocode.rb +33 -0
  44. data/lib/barometer/web_services/weather_id.rb +37 -0
  45. data/lib/barometer/web_services/web_service.rb +32 -0
  46. data/lib/demometer/demometer.rb +31 -4
  47. data/lib/demometer/views/forecast.erb +20 -0
  48. data/lib/demometer/views/index.erb +10 -3
  49. data/lib/demometer/views/measurement.erb +8 -3
  50. data/lib/demometer/views/readme.erb +63 -24
  51. data/spec/barometer_spec.rb +18 -36
  52. data/spec/{data_current_spec.rb → data/current_spec.rb} +73 -49
  53. data/spec/{data_distance_spec.rb → data/distance_spec.rb} +30 -30
  54. data/spec/{data_forecast_spec.rb → data/forecast_spec.rb} +57 -15
  55. data/spec/data/geo_spec.rb +91 -0
  56. data/spec/data/local_datetime_spec.rb +269 -0
  57. data/spec/data/local_time_spec.rb +239 -0
  58. data/spec/{data_location_spec.rb → data/location_spec.rb} +12 -1
  59. data/spec/{data_measurement_spec.rb → data/measurement_spec.rb} +135 -66
  60. data/spec/data/night_measurement_spec.rb +136 -0
  61. data/spec/{data_pressure_spec.rb → data/pressure_spec.rb} +29 -29
  62. data/spec/{data_speed_spec.rb → data/speed_spec.rb} +30 -30
  63. data/spec/data/sun_spec.rb +49 -0
  64. data/spec/{data_temperature_spec.rb → data/temperature_spec.rb} +44 -44
  65. data/spec/{units_spec.rb → data/units_spec.rb} +6 -6
  66. data/spec/{data_zone_spec.rb → data/zone_spec.rb} +15 -15
  67. data/spec/fixtures/formats/weather_id/90210.xml +1 -0
  68. data/spec/fixtures/formats/weather_id/atlanta.xml +1 -0
  69. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +1 -0
  70. data/spec/fixtures/formats/weather_id/new_york.xml +1 -0
  71. data/spec/fixtures/{geocode_40_73.xml → geocode/40_73.xml} +0 -0
  72. data/spec/fixtures/{geocode_90210.xml → geocode/90210.xml} +0 -0
  73. data/spec/fixtures/{geocode_T5B4M9.xml → geocode/T5B4M9.xml} +0 -0
  74. data/spec/fixtures/geocode/atlanta.xml +1 -0
  75. data/spec/fixtures/{geocode_calgary_ab.xml → geocode/calgary_ab.xml} +0 -0
  76. data/spec/fixtures/{geocode_ksfo.xml → geocode/ksfo.xml} +0 -0
  77. data/spec/fixtures/{geocode_newyork_ny.xml → geocode/newyork_ny.xml} +0 -0
  78. data/spec/fixtures/{google_calgary_ab.xml → services/google/calgary_ab.xml} +0 -0
  79. data/spec/fixtures/services/weather_dot_com/90210.xml +1 -0
  80. data/spec/fixtures/{current_calgary_ab.xml → services/wunderground/current_calgary_ab.xml} +0 -0
  81. data/spec/fixtures/{forecast_calgary_ab.xml → services/wunderground/forecast_calgary_ab.xml} +0 -0
  82. data/spec/fixtures/{yahoo_90210.xml → services/yahoo/90210.xml} +0 -0
  83. data/spec/formats/coordinates_spec.rb +158 -0
  84. data/spec/formats/format_spec.rb +73 -0
  85. data/spec/formats/geocode_spec.rb +179 -0
  86. data/spec/formats/icao_spec.rb +61 -0
  87. data/spec/formats/postalcode_spec.rb +59 -0
  88. data/spec/formats/short_zipcode_spec.rb +53 -0
  89. data/spec/formats/weather_id_spec.rb +191 -0
  90. data/spec/formats/zipcode_spec.rb +111 -0
  91. data/spec/query_spec.rb +261 -288
  92. data/spec/spec_helper.rb +128 -4
  93. data/spec/{service_google_spec.rb → weather_services/google_spec.rb} +46 -46
  94. data/spec/weather_services/services_spec.rb +1118 -0
  95. data/spec/weather_services/weather_dot_com_spec.rb +327 -0
  96. data/spec/weather_services/wunderground_spec.rb +332 -0
  97. data/spec/{service_yahoo_spec.rb → weather_services/yahoo_spec.rb} +65 -81
  98. data/spec/weather_spec.rb +73 -61
  99. data/spec/web_services/geocode_spec.rb +45 -0
  100. data/spec/web_services/web_services_spec.rb +26 -0
  101. metadata +88 -36
  102. data/lib/barometer/services/noaa.rb +0 -6
  103. data/lib/barometer/services/weather_bug.rb +0 -6
  104. data/lib/barometer/services/weather_dot_com.rb +0 -6
  105. data/spec/data_geo_spec.rb +0 -94
  106. data/spec/data_sun_spec.rb +0 -76
  107. data/spec/service_wunderground_spec.rb +0 -330
  108. data/spec/services_spec.rb +0 -1106
@@ -7,9 +7,29 @@
7
7
  <%= data("High", forecast.high) %>
8
8
  <%= data("Low", forecast.low) %>
9
9
  <%= data("POP", forecast.pop) %>
10
+ <%= data("Humidity", forecast.humidity) %>
11
+ <% if forecast.wind %>
12
+ <%= data("Wind Speed", forecast.wind) %>
13
+ <%= data("Wind Direction", forecast.wind.direction) %>
14
+ <%= data("Wind Degrees", forecast.wind.degrees) %>
15
+ <% end %>
10
16
  <% if forecast.sun %>
11
17
  <%= data("Sun Rise", forecast.sun.rise) %>
12
18
  <%= data("Sun Set", forecast.sun.set) %>
13
19
  <% end %>
14
20
  </ul>
21
+ <% if forecast.night %>
22
+ <ul>- Night -
23
+ <%= data("Date", forecast.night.date) %>
24
+ <%= data("Date", forecast.night.icon) %>
25
+ <%= data("Date", forecast.night.condition) %>
26
+ <%= data("Date", forecast.night.pop) %>
27
+ <%= data("Date", forecast.night.humidity) %>
28
+ <% if forecast.night.wind %>
29
+ <%= data("Wind Speed", forecast.night.wind) %>
30
+ <%= data("Wind Direction", forecast.night.wind.direction) %>
31
+ <%= data("Wind Degrees", forecast.night.wind.degrees) %>
32
+ <% end %>
33
+ </ul>
34
+ <% end %>
15
35
  </p>
@@ -17,6 +17,7 @@
17
17
  <input type="checkbox" name="query[source]" value="wunderground" checked="checked" /> Wunderground
18
18
  <input type="checkbox" name="query[source]" value="yahoo" /> Yahoo
19
19
  <input type="checkbox" name="query[source]" value="google" /> Google
20
+ <input type="checkbox" name="query[source]" value="weather_dot_com" /> Weather.com
20
21
  <br/>
21
22
  Force Geocode? :
22
23
  <input id="query_geocode" name="query[geocode]" type="checkbox" value="1" checked="checked" />
@@ -60,16 +61,22 @@
60
61
  <h3>Query</h3>
61
62
  <p>
62
63
  <ul>
64
+ <%= data("Query", @barometer.query.q) %>
63
65
  <%= data("Format", @barometer.query.format) %>
64
- <% if @barometer.query.geo %>
66
+ <%= data("Country Code", @barometer.query.country_code) %>
67
+ </ul>
68
+ <% if @barometer.query.geo %>
69
+ <ul> - Geo -
70
+ <%= data("Query", @barometer.query.geo.query) %>
71
+ <%= data("Address", @barometer.query.geo.address) %>
65
72
  <%= data("Locality", @barometer.query.geo.locality) %>
66
73
  <%= data("Region", @barometer.query.geo.region) %>
67
74
  <%= data("Country", @barometer.query.geo.country) %>
68
75
  <%= data("Country Code", @barometer.query.geo.country_code) %>
69
76
  <%= data("Latitude", @barometer.query.geo.latitude) %>
70
77
  <%= data("Longitude", @barometer.query.geo.longitude) %>
71
- <% end %>
72
- </ul>
78
+ </ul>
79
+ <% end %>
73
80
  </p>
74
81
  <% end %>
75
82
 
@@ -1,11 +1,16 @@
1
1
  <h2><%= measurement.source.to_s.capitalize %></h2>
2
2
  <p>
3
3
  <ul>
4
+ <%= data("Measured At", measurement.measured_at) %>
4
5
  <%= data("Source", measurement.source) %>
5
- <%= data("Time", measurement.time) %>
6
+ <%= data("Time Stamp", measurement.utc_time_stamp) %>
6
7
  <%= data("Metric", measurement.metric?) %>
7
8
  <%= data("Success", measurement.success?) %>
8
9
  </ul>
10
+ <ul>- Modified Query -
11
+ <%= data("Query", measurement.query) %>
12
+ <%= data("Format", measurement.format) %>
13
+ </ul>
9
14
  </p>
10
15
 
11
16
  <% if measurement.location %>
@@ -60,8 +65,8 @@
60
65
  <h3>Current</h3>
61
66
  <p>
62
67
  <ul>
63
- <%= data("Time", measurement.current.time) %>
64
- <%= data("Local Time", measurement.current.local_time) %>
68
+ <%= data("Measured At", measurement.current.current_at) %>
69
+ <%= data("Updated At", measurement.current.updated_at) %>
65
70
  <%= data("Humidity", measurement.current.humidity) %>
66
71
  <%= data("Icon", measurement.current.icon) %>
67
72
  <%= data("Condition", measurement.current.condition) %>
@@ -11,12 +11,12 @@ unavailable.
11
11
  </p>
12
12
  <h2>version</h2>
13
13
  <p>
14
-
15
- Version 0.3.1 is the current release of this gem. The gem is available from
14
+ Version 0.3.3 is the current release of this gem. The gem is available from
16
15
  github (attack-barometer) or rubyforge (barometer). It is fully functional
17
16
  (for three weather service APIs).
18
17
  </p>
19
18
  <h2>status</h2>
19
+
20
20
  <p>
21
21
  Currently this project is in development and will only work for a few
22
22
  weather services (wunderground, google, yahoo).
@@ -31,10 +31,10 @@ Features to be added next:
31
31
  </ul>
32
32
  <h1>dependencies</h1>
33
33
  <h3>Google API key</h3>
34
-
35
34
  <p>
36
35
  In most cases you will need to have a free google geocode api key. Get one
37
36
  here: <a href="http://code.google.com/apis/maps/signup.html">code.google.com/apis/maps/signup.html</a>
37
+
38
38
  Then put it in the file &#8217;~/.barometer&#8217; by adding the line:
39
39
  geocode_google: YOUR_KEY_HERE
40
40
  </p>
@@ -44,10 +44,17 @@ You will need this for:
44
44
  <ul>
45
45
  <li>using the Barometer gem (unless you use queries that are directly supported
46
46
  by the weather source API, ie yahoo will take a zip code directly and
47
- doesn&#8217;t require any geocoding)</li>
48
- <li>running the Barometer binary</li>
49
- <li>running the Barometer Web Demo</li>
47
+ doesn&#8217;t require any geocoding)
48
+
49
+ </li>
50
+ <li>running the Barometer binary
51
+
52
+ </li>
53
+ <li>running the Barometer Web Demo
54
+
55
+ </li>
50
56
  </ul>
57
+
51
58
  <h3>HTTParty</h3>
52
59
  <p>
53
60
  Why? HTTParty was created and designed specifically for consuming web
@@ -63,9 +70,9 @@ Why? Barometer deals with time information for locations all over the
63
70
  world. This information doesn&#8217;t mean that much if it can&#8217;t be
64
71
  converted to times that don&#8217;t correspond to the applicable timezone.
65
72
  Tzinfo handles this time zone manipulation.
66
-
67
73
  </p>
68
74
  <h3>graticule (very soft dependency)</h3>
75
+
69
76
  <p>
70
77
  Why? Barometer returns the weather for a given location. Most weather
71
78
  service APIs are somewhat restricted on the query format they receive. To
@@ -85,11 +92,11 @@ Graticule gem, HTTParty will be used instead to provide the same geocoding.
85
92
  Basically Graticule is only used if it exists.
86
93
  </p>
87
94
  <p>
88
-
89
95
  NOTE: you can force Barometer not to use Graticule, even if you have it
90
96
  installed using the following:
91
97
  </p>
92
98
  <pre>
99
+
93
100
  Barometer.skip_graticule = true
94
101
  </pre>
95
102
  <h1>usage</h1>
@@ -106,26 +113,53 @@ with geo-coding.
106
113
  require 'barometer'
107
114
 
108
115
  Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
109
-
110
116
  barometer = Barometer.new(&quot;Paris&quot;)
111
117
  weather = barometer.measure
112
118
 
113
119
  puts weather.current.temperture
120
+
121
+ </pre>
122
+ <h2>source configuration</h2>
123
+ <p>
124
+ Barometer can be configured to use multiple weather service APIs (either in
125
+ a primary/failover config or in parallel). Each weather service can also
126
+ have its own config.
127
+ </p>
128
+ <p>
129
+ Weather services in parallel
130
+ </p>
131
+ <pre>
132
+ Barometer.config = { 1 =&gt; [:yahoo, :google] }
133
+ </pre>
134
+ <p>
135
+ Weather services in primary/failover
136
+
137
+ </p>
138
+ <pre>
139
+ Barometer.config = { 1 =&gt; [:yahoo], 2 =&gt; :wunderground }
140
+ </pre>
141
+ <p>
142
+ Weather services, one with some configuration. In this case we are setting
143
+ a weight value, this weight is respected when calculating averages.
144
+ </p>
145
+ <pre>
146
+ Barometer.config = { 1 =&gt; [{:wunderground =&gt; {:weight =&gt; 2}}, :google] }
147
+
114
148
  </pre>
115
- <h2>multiple weather API, with hierarchy</h2>
149
+ <h3>multiple weather API, with hierarchy</h3>
116
150
  <pre>
117
151
  require 'barometer'
118
152
 
119
153
  Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
120
154
  # use yahoo and google, if they both fail, use wunderground
121
- Barometer.selection = { 1 =&gt; [:yahoo, :google], 2 =&gt; :wunderground }
155
+ Barometer.config = { 1 =&gt; [:yahoo, :google], 2 =&gt; :wunderground }
122
156
 
123
157
  barometer = Barometer.new(&quot;Paris&quot;)
124
158
  weather = barometer.measure
125
159
 
126
160
  puts weather.current.temperture
127
-
128
161
  </pre>
162
+
129
163
  <h2>command line</h2>
130
164
  <p>
131
165
  You can use barometer from the command line.
@@ -140,8 +174,8 @@ for more command line information.
140
174
  <pre>
141
175
  # barometer -h
142
176
  </pre>
143
-
144
177
  <h3>web demo</h3>
178
+
145
179
  <p>
146
180
  There is a Sinatra application that demos the functionality of Barometer,
147
181
  and provides Barometer information. Start this local demo with:
@@ -152,8 +186,8 @@ and provides Barometer information. Start this local demo with:
152
186
  <p>
153
187
  NOTE: This requires the gems &quot;sinatra&quot; and &quot;vegas&quot;.
154
188
  </p>
155
-
156
189
  <h3>fail</h3>
190
+
157
191
  <p>
158
192
  What would cause a weather service to fail? The most obvious is that the
159
193
  particular weather service in currently unavailable or not reachable. Other
@@ -175,7 +209,6 @@ Wunderground, but since the driver interface is abstracted it will be the
175
209
  same for all supported services.
176
210
  </p>
177
211
  <pre>
178
-
179
212
  require 'barometer'
180
213
  Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
181
214
 
@@ -201,9 +234,9 @@ string instead of directly feeding the query string to the service (as in
201
234
  bootstrap example #1). The Barometer::Query object has behavior required by
202
235
  the service that a regular String doesn&#8217;t have. Using a driver
203
236
  directly WILL accept a String (as in bootstrap example #2).
204
-
205
237
  </p>
206
238
  <h2>searching</h2>
239
+
207
240
  <p>
208
241
  After you have measured the data, Barometer provides several methods to
209
242
  help you get the data you are after. All examples assume you already have
@@ -227,8 +260,8 @@ measured the data as shown in the above examples.
227
260
  weather.sources # lists all successful sources
228
261
 
229
262
  puts weather.source(:wunderground).current.temperature.c
230
-
231
263
  </pre>
264
+
232
265
  <h3>by date</h3>
233
266
  <pre>
234
267
  # note, the date is the date of the locations weather, not the date of the
@@ -248,9 +281,9 @@ measured the data as shown in the above examples.
248
281
  weather.source(:wunderground).for(time) # same as above but specific source
249
282
 
250
283
  puts weather.source(:wunderground).for(time).low.f
251
-
252
284
  </pre>
253
285
  <h2>averages</h2>
286
+
254
287
  <p>
255
288
  If you consume more then one weather service, Barometer can provide
256
289
  averages for the values (currently only for the &#8216;current&#8217;
@@ -261,7 +294,7 @@ values and not the forecasted values).
261
294
 
262
295
  Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
263
296
  # use yahoo and wunderground
264
- Barometer.selection = { 1 =&gt; [:yahoo, :wunderground] }
297
+ Barometer.config = { 1 =&gt; [:yahoo, :wunderground] }
265
298
 
266
299
  barometer = Barometer.new(&quot;90210&quot;)
267
300
  weather = barometer.measure
@@ -273,12 +306,19 @@ values and not the forecasted values).
273
306
  This will calculate the average temperature as given by :yahoo and
274
307
  :wunderground
275
308
  </p>
309
+ <h3>weights</h3>
310
+ <p>
311
+ You can weight the values from a weather service so that the values from
312
+ that web service have more influence then other values. The weights are set
313
+ in the config &#8230; see the config section
314
+ </p>
276
315
  <h2>simple answers</h2>
277
316
  <p>
278
317
  After you have measured the data, Barometer provides several &quot;simple
279
318
  answer&quot; methods to help you get answers to some basic questions. All
280
319
  examples assume you already have measured the data as shown in the above
281
320
  examples.
321
+
282
322
  </p>
283
323
  <p>
284
324
  All of these questions are ultimately specific to the weather source(s) you
@@ -287,7 +327,6 @@ will be asked, but if there is no data that can answer the question then
287
327
  there will be no answer.
288
328
  </p>
289
329
  <h3>is it windy?</h3>
290
-
291
330
  <pre>
292
331
  # 1st parameter is the threshold wind speed for being windy
293
332
  # 2nd parameter is the utc_time for which you want to know the answer,
@@ -306,6 +345,7 @@ there will be no answer.
306
345
  weather.wet?(50)
307
346
  </pre>
308
347
  <h3>is it sunny?</h3>
348
+
309
349
  <pre>
310
350
  # 1st parameter is the utc_time for which you want to know the answer,
311
351
  # this defaults to the current time
@@ -313,7 +353,6 @@ there will be no answer.
313
353
  weather.sunny?
314
354
  </pre>
315
355
  <h3>is it day?</h3>
316
-
317
356
  <pre>
318
357
  # 1st parameter is the utc_time for which you want to know the answer,
319
358
  # this defaults to the current time
@@ -328,6 +367,7 @@ there will be no answer.
328
367
  weather.night?
329
368
  </pre>
330
369
  <h1>design</h1>
370
+
331
371
  <ul>
332
372
  <li>create a Barometer instance
333
373
 
@@ -335,7 +375,6 @@ there will be no answer.
335
375
  <li>supply a query, there are very little restrictions on the format:
336
376
 
337
377
  <ul>
338
-
339
378
  <li>city, country, specific address (basically anything Google will geocode)
340
379
 
341
380
  </li>
@@ -355,6 +394,7 @@ accepts this directly)
355
394
  </li>
356
395
  </ul>
357
396
  </li>
397
+
358
398
  <li>if geocoding required, geocode the query
359
399
 
360
400
  </li>
@@ -363,7 +403,6 @@ accepts this directly)
363
403
  </li>
364
404
  <li>query the weather services
365
405
 
366
-
367
406
  </li>
368
407
  <li>save the data
369
408
 
@@ -378,9 +417,9 @@ Barometer attempts to be a common API to any weather service API. I have
378
417
  included several weather service &#8216;drivers&#8217;, but I know there
379
418
  are many more available. Please use the provided ones as examples to create
380
419
  more.
420
+
381
421
  </p>
382
422
  <h2>copyright</h2>
383
423
  <p>
384
424
  Copyright &#169; 2009 Mark G. See LICENSE for details.
385
-
386
425
  </p>
@@ -3,22 +3,22 @@ require 'spec_helper'
3
3
  describe "Barometer" do
4
4
 
5
5
  before(:each) do
6
- @preference_hash = { 1 => [:wunderground] }
6
+ @config_hash = { 1 => [:wunderground] }
7
7
  @key = KEY
8
8
  end
9
9
 
10
10
  describe "and class methods" do
11
11
 
12
12
  it "defines selection" do
13
- Barometer::Base.respond_to?("selection").should be_true
14
- Barometer::Base.selection.should == { 1 => [:wunderground] }
15
- Barometer::Base.selection = { 1 => [:yahoo] }
16
- Barometer::Base.selection.should == { 1 => [:yahoo] }
17
- Barometer.selection = @preference_hash
13
+ Barometer::Base.respond_to?("config").should be_true
14
+ Barometer::Base.config.should == { 1 => [:wunderground] }
15
+ Barometer::Base.config = { 1 => [:yahoo] }
16
+ Barometer::Base.config.should == { 1 => [:yahoo] }
17
+ Barometer.config = @config_hash
18
18
  end
19
19
 
20
20
  it "returns a Weather Service driver" do
21
- Barometer.source(:wunderground).should == Barometer::Wunderground
21
+ Barometer.source(:wunderground).should == Barometer::WeatherService::Wunderground
22
22
  end
23
23
 
24
24
  it "sets the Graticule Google geocoding API key" do
@@ -28,13 +28,6 @@ describe "Barometer" do
28
28
  Barometer.google_geocode_key.should == @key
29
29
  end
30
30
 
31
- it "skips the use of Graticule" do
32
- Barometer.respond_to?("skip_graticule").should be_true
33
- Barometer.skip_graticule.should be_false
34
- Barometer.skip_graticule = true
35
- Barometer.skip_graticule.should be_true
36
- end
37
-
38
31
  it "forces the geocoding of queries" do
39
32
  Barometer.respond_to?("force_geocode").should be_true
40
33
  Barometer.force_geocode.should be_false
@@ -107,41 +100,24 @@ describe "Barometer" do
107
100
  FakeWeb.register_uri(:get,
108
101
  "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(query_term)}",
109
102
  :string => File.read(File.join(File.dirname(__FILE__),
110
- 'fixtures',
103
+ 'fixtures/services/wunderground',
111
104
  'current_calgary_ab.xml')
112
105
  )
113
106
  )
114
107
  FakeWeb.register_uri(:get,
115
108
  "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(query_term)}",
116
109
  :string => File.read(File.join(File.dirname(__FILE__),
117
- 'fixtures',
110
+ 'fixtures/services/wunderground',
118
111
  'forecast_calgary_ab.xml')
119
112
  )
120
113
  )
121
114
  FakeWeb.register_uri(:get,
122
115
  "http://maps.google.com:80/maps/geo?gl=&q=Calgary%2CAB&output=xml&key=#{@key}",
123
116
  :string => File.read(File.join(File.dirname(__FILE__),
124
- 'fixtures',
125
- 'geocode_calgary_ab.xml')
126
- )
127
- )
128
-
129
-
130
- FakeWeb.register_uri(:get,
131
- "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=51.055149%2C-114.062438",
132
- :string => File.read(File.join(File.dirname(__FILE__),
133
- 'fixtures',
134
- 'current_calgary_ab.xml')
135
- )
136
- )
137
- FakeWeb.register_uri(:get,
138
- "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=51.055149%2C-114.062438",
139
- :string => File.read(File.join(File.dirname(__FILE__),
140
- 'fixtures',
141
- 'forecast_calgary_ab.xml')
117
+ 'fixtures/geocode',
118
+ 'calgary_ab.xml')
142
119
  )
143
120
  )
144
-
145
121
  end
146
122
 
147
123
  it "responds to measure" do
@@ -153,10 +129,16 @@ describe "Barometer" do
153
129
  end
154
130
 
155
131
  it "raises OutOfSources if no services successful" do
156
- Barometer::Base.selection = { 1 => [] }
132
+ Barometer::Base.config = { 1 => [] }
157
133
  lambda { @barometer.measure }.should raise_error(Barometer::OutOfSources)
158
134
  end
159
135
 
136
+ it "sets the weight" do
137
+ Barometer::Base.config = { 1 => {:wunderground => {:weight => 2}} }
138
+ @barometer.measure
139
+ @barometer.weather.measurements.first.weight.should == 2
140
+ end
141
+
160
142
  end
161
143
 
162
144
  end