barometer 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+
4
+ require 'barometer'
5
+ Barometer.google_geocode_key ||= "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
6
+
7
+ class Webometer < Sinatra::Default
8
+
9
+ get '/' do
10
+ erb :index
11
+ end
12
+
13
+ post '/' do
14
+ # apply options
15
+ Barometer.force_geocode = (params[:query][:geocode].to_s == "1" ? true : false)
16
+ Barometer.selection = { 1 => [ params[:query][:source].to_sym ] }
17
+ metric = (params[:query][:metric].to_s == "1" ? true : false)
18
+
19
+ if params[:query] && !params[:query][:q].empty?
20
+ @barometer = Barometer.new(params[:query][:q])
21
+ @weather = @barometer.measure(metric)
22
+ end
23
+ erb :index
24
+ end
25
+
26
+ get '/contributing.html' do
27
+ erb :contributing
28
+ end
29
+
30
+ get '/readme.html' do
31
+ erb :readme
32
+ end
33
+
34
+ end
@@ -4,7 +4,7 @@ describe "Barometer" do
4
4
 
5
5
  before(:each) do
6
6
  @preference_hash = { 1 => [:wunderground] }
7
- @key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
7
+ @key = KEY
8
8
  end
9
9
 
10
10
  describe "and class methods" do
@@ -35,6 +35,10 @@ describe "Geo" do
35
35
  @geo.country.should be_nil
36
36
  end
37
37
 
38
+ it "responds to address" do
39
+ @geo.address.should be_nil
40
+ end
41
+
38
42
  it "responds to coordinates" do
39
43
  @geo.longitude = "99.99"
40
44
  @geo.latitude = "88.88"
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>KSFO</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>San Francisco Airport, United States</address> <AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AddressLine>San Francisco Airport</AddressLine></Country></AddressDetails> <ExtendedData> <LatLonBox north="37.6401700" south="37.6041790" east="-122.3548940" west="-122.4015610" /> </ExtendedData> <Point><coordinates>-122.3899790,37.6152230,0</coordinates></Point> </Placemark> </Response></kml>
data/spec/query_spec.rb CHANGED
@@ -7,6 +7,7 @@ describe "Query" do
7
7
  @postal_code = "T5B 4M9"
8
8
  @coordinates = "40.756054,-73.986951"
9
9
  @geocode = "New York, NY"
10
+ @icao = "KSFO"
10
11
 
11
12
  # actual conversions
12
13
  @zipcode_to_coordinates = "34.1030032,-118.4104684"
@@ -26,18 +27,28 @@ describe "Query" do
26
27
  Barometer::Query.is_us_zipcode?(@zipcode).should be_true
27
28
  Barometer::Query.is_us_zipcode?(@postal_code).should be_false
28
29
  Barometer::Query.is_us_zipcode?(@coordinates).should be_false
30
+ Barometer::Query.is_coordinates?(@icao).should be_false
29
31
  end
30
32
 
31
33
  it "detects a postalcode" do
32
34
  Barometer::Query.is_canadian_postcode?(@postal_code).should be_true
33
35
  Barometer::Query.is_canadian_postcode?(@zipcode).should be_false
34
36
  Barometer::Query.is_canadian_postcode?(@coordinates).should be_false
37
+ Barometer::Query.is_coordinates?(@icao).should be_false
35
38
  end
36
39
 
37
40
  it "detects a coordinates" do
38
41
  Barometer::Query.is_coordinates?(@coordinates).should be_true
39
42
  Barometer::Query.is_coordinates?(@zipcode).should be_false
40
43
  Barometer::Query.is_coordinates?(@postal_code).should be_false
44
+ Barometer::Query.is_coordinates?(@icao).should be_false
45
+ end
46
+
47
+ it "detects an ICAO" do
48
+ Barometer::Query.is_icao?(@coordinates).should be_false
49
+ Barometer::Query.is_icao?(@zipcode).should be_false
50
+ Barometer::Query.is_icao?(@postal_code).should be_false
51
+ Barometer::Query.is_icao?(@icao).should be_true
41
52
  end
42
53
 
43
54
  end
@@ -58,6 +69,7 @@ describe "Query" do
58
69
  @query.country_code.should == "US"
59
70
  @query.zipcode?.should be_true
60
71
  @query.postalcode?.should be_false
72
+ @query.icao?.should be_false
61
73
  @query.coordinates?.should be_false
62
74
  @query.geocode?.should be_false
63
75
  end
@@ -71,6 +83,21 @@ describe "Query" do
71
83
  @query.country_code.should == "CA"
72
84
  @query.zipcode?.should be_false
73
85
  @query.postalcode?.should be_true
86
+ @query.icao?.should be_false
87
+ @query.coordinates?.should be_false
88
+ @query.geocode?.should be_false
89
+ end
90
+
91
+ it "recognizes icao" do
92
+ @query.q = @icao
93
+ @query.format.should be_nil
94
+ @query.analyze!
95
+ @query.format.to_sym.should == :icao
96
+
97
+ @query.country_code.should be_nil
98
+ @query.zipcode?.should be_false
99
+ @query.postalcode?.should be_false
100
+ @query.icao?.should be_true
74
101
  @query.coordinates?.should be_false
75
102
  @query.geocode?.should be_false
76
103
  end
@@ -84,6 +111,7 @@ describe "Query" do
84
111
  @query.country_code.should be_nil
85
112
  @query.zipcode?.should be_false
86
113
  @query.postalcode?.should be_false
114
+ @query.icao?.should be_false
87
115
  @query.coordinates?.should be_true
88
116
  @query.geocode?.should be_false
89
117
  end
@@ -97,6 +125,7 @@ describe "Query" do
97
125
  @query.country_code.should be_nil
98
126
  @query.zipcode?.should be_false
99
127
  @query.postalcode?.should be_false
128
+ @query.icao?.should be_false
100
129
  @query.coordinates?.should be_false
101
130
  @query.geocode?.should be_true
102
131
  end
@@ -168,7 +197,7 @@ describe "Query" do
168
197
  describe "when converting queries" do
169
198
 
170
199
  before(:each) do
171
- @key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
200
+ @key = KEY
172
201
  url_start = "http://maps.google.com/maps/geo?"
173
202
  #
174
203
  # for Graticule and/or HTTParty geocoding
@@ -221,6 +250,13 @@ describe "Query" do
221
250
  'geocode_40_73.xml')
222
251
  )
223
252
  )
253
+ FakeWeb.register_uri(:get,
254
+ "#{url_start}output=xml&q=KSFO&gl=&key=#{@key}",
255
+ :string => File.read(File.join(File.dirname(__FILE__),
256
+ 'fixtures',
257
+ 'geocode_ksfo.xml')
258
+ )
259
+ )
224
260
  end
225
261
 
226
262
  describe "to coordinates," do
@@ -253,6 +289,10 @@ describe "Query" do
253
289
  Barometer::Query.to_coordinates(@postal_code, :postalcode).first.should == "53.570447,-113.456083"
254
290
  end
255
291
 
292
+ it "converts from icao" do
293
+ Barometer::Query.to_coordinates(@icao, :icao).first.should == "37.615223,-122.389979"
294
+ end
295
+
256
296
  end
257
297
 
258
298
  describe "to geocode" do
@@ -275,6 +315,10 @@ describe "Query" do
275
315
  Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
276
316
  end
277
317
 
318
+ it "converts from icao" do
319
+ Barometer::Query.to_geocode(@icao, :icao).first.should == "San Francisco Airport, USA"
320
+ end
321
+
278
322
  end
279
323
 
280
324
  describe "when Graticule disabled," do
@@ -357,7 +401,7 @@ describe "Query" do
357
401
 
358
402
  before(:each) do
359
403
  @query = Barometer::Query.new(@zipcode)
360
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
404
+ Barometer::Query.google_geocode_key = KEY
361
405
  end
362
406
 
363
407
  it "converts to coordinates" do
@@ -384,7 +428,7 @@ describe "Query" do
384
428
 
385
429
  before(:each) do
386
430
  @query = Barometer::Query.new(@postal_code)
387
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
431
+ Barometer::Query.google_geocode_key = KEY
388
432
  end
389
433
 
390
434
  it "converts to coordinates" do
@@ -411,7 +455,7 @@ describe "Query" do
411
455
 
412
456
  before(:each) do
413
457
  @query = Barometer::Query.new(@geocode)
414
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
458
+ Barometer::Query.google_geocode_key = KEY
415
459
  end
416
460
 
417
461
  it "converts to coordinates" do
@@ -438,7 +482,7 @@ describe "Query" do
438
482
 
439
483
  before(:each) do
440
484
  @query = Barometer::Query.new(@coordinates)
441
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
485
+ Barometer::Query.google_geocode_key = KEY
442
486
  end
443
487
 
444
488
  it "converts to geocode" do
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "Wunderground" do
4
4
 
5
5
  before(:each) do
6
- @accepted_formats = [:zipcode, :postalcode, :coordinates, :geocode]
6
+ @accepted_formats = [:zipcode, :postalcode, :icao, :coordinates, :geocode]
7
7
  @base_uri = "http://api.wunderground.com/auto/wui/geo"
8
8
  end
9
9
 
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
  require 'spec'
3
3
  require 'fakeweb'
4
4
  require 'cgi'
5
+ require 'yaml'
5
6
 
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -9,6 +10,30 @@ require 'barometer'
9
10
 
10
11
  FakeWeb.allow_net_connect = false
11
12
 
13
+ KEY_FILE = File.expand_path(File.join('~', '.barometer'))
14
+
15
+ def geocode_google_key_message
16
+ puts
17
+ puts "Please update the key_file '#{KEY_FILE}' with your google api key"
18
+ puts "example:"
19
+ puts "geocode_google: YOUR_KEY_KERE"
20
+ puts
21
+ end
22
+
23
+ if File.exists?(KEY_FILE)
24
+ keys = YAML.load_file(KEY_FILE)
25
+ if keys["geocode_google"]
26
+ KEY = keys["geocode_google"]
27
+ else
28
+ geocode_google_key_message
29
+ exit
30
+ end
31
+ else
32
+ File.open(KEY_FILE, 'w') {|f| f << "geocode_google: YOUR_KEY_KERE" }
33
+ geocode_google_key_message
34
+ exit
35
+ end
36
+
12
37
  Spec::Runner.configure do |config|
13
38
 
14
39
  end
data/spec/weather_spec.rb CHANGED
@@ -78,6 +78,174 @@ describe "Weather" do
78
78
 
79
79
  end
80
80
 
81
+ describe "when calculating averages" do
82
+
83
+ before(:each) do
84
+ @weather = Barometer::Weather.new
85
+ @wunderground = Barometer::Measurement.new(:wunderground)
86
+ @wunderground.current = Barometer::CurrentMeasurement.new
87
+ @wunderground.success = true
88
+ @yahoo = Barometer::Measurement.new(:yahoo)
89
+ @yahoo.current = Barometer::CurrentMeasurement.new
90
+ @yahoo.success = true
91
+ @google = Barometer::Measurement.new(:google)
92
+ @weather.measurements << @wunderground
93
+ @weather.measurements << @yahoo
94
+ @weather.measurements << @google
95
+ end
96
+
97
+ describe "for temperature" do
98
+
99
+ before(:each) do
100
+ @weather.source(:wunderground).current.temperature = Barometer::Temperature.new
101
+ @weather.source(:wunderground).current.temperature.c = 10
102
+ @weather.source(:yahoo).current.temperature = Barometer::Temperature.new
103
+ @weather.source(:yahoo).current.temperature.c = 6
104
+ end
105
+
106
+ it "returns averages" do
107
+ @weather.temperature.c.should == 8
108
+ end
109
+
110
+ it "returns default when disabled" do
111
+ @weather.temperature(false).c.should == 10
112
+ end
113
+
114
+ end
115
+
116
+ describe "for wind" do
117
+
118
+ before(:each) do
119
+ @weather.source(:wunderground).current.wind = Barometer::Speed.new
120
+ @weather.source(:wunderground).current.wind.kph = 10
121
+ @weather.source(:yahoo).current.wind = Barometer::Speed.new
122
+ @weather.source(:yahoo).current.wind.kph = 6
123
+ end
124
+
125
+ it "returns averages" do
126
+ @weather.wind.kph.should == 8
127
+ end
128
+
129
+ it "returns default when disabled" do
130
+ @weather.wind(false).kph.should == 10
131
+ end
132
+
133
+ end
134
+
135
+ describe "for humidity" do
136
+
137
+ before(:each) do
138
+ @weather.source(:wunderground).current.humidity = 10
139
+ @weather.source(:yahoo).current.humidity = 6
140
+ end
141
+
142
+ it "returns averages" do
143
+ @weather.humidity.should == 8
144
+ end
145
+
146
+ it "returns default when disabled" do
147
+ @weather.humidity(false).should == 10
148
+ end
149
+
150
+ end
151
+
152
+ describe "for pressure" do
153
+
154
+ before(:each) do
155
+ @weather.source(:wunderground).current.pressure = Barometer::Pressure.new
156
+ @weather.source(:wunderground).current.pressure.mb = 10
157
+ @weather.source(:yahoo).current.pressure = Barometer::Pressure.new
158
+ @weather.source(:yahoo).current.pressure.mb = 6
159
+ end
160
+
161
+ it "returns averages" do
162
+ @weather.pressure.mb.should == 8
163
+ end
164
+
165
+ it "returns default when disabled" do
166
+ @weather.pressure(false).mb.should == 10
167
+ end
168
+
169
+ end
170
+
171
+ describe "for dew_point" do
172
+
173
+ before(:each) do
174
+ @weather.source(:wunderground).current.dew_point = Barometer::Temperature.new
175
+ @weather.source(:wunderground).current.dew_point.c = 10
176
+ @weather.source(:yahoo).current.dew_point = Barometer::Temperature.new
177
+ @weather.source(:yahoo).current.dew_point.c = 6
178
+ end
179
+
180
+ it "returns averages" do
181
+ @weather.dew_point.c.should == 8
182
+ end
183
+
184
+ it "returns default when disabled" do
185
+ @weather.dew_point(false).c.should == 10
186
+ end
187
+
188
+ end
189
+
190
+ describe "for heat_index" do
191
+
192
+ before(:each) do
193
+ @weather.source(:wunderground).current.heat_index = Barometer::Temperature.new
194
+ @weather.source(:wunderground).current.heat_index.c = 10
195
+ @weather.source(:yahoo).current.heat_index = Barometer::Temperature.new
196
+ @weather.source(:yahoo).current.heat_index.c = 6
197
+ end
198
+
199
+ it "returns averages" do
200
+ @weather.heat_index.c.should == 8
201
+ end
202
+
203
+ it "returns default when disabled" do
204
+ @weather.heat_index(false).c.should == 10
205
+ end
206
+
207
+ end
208
+
209
+ describe "for wind_chill" do
210
+
211
+ before(:each) do
212
+ @weather.source(:wunderground).current.wind_chill = Barometer::Temperature.new
213
+ @weather.source(:wunderground).current.wind_chill.c = 10
214
+ @weather.source(:yahoo).current.wind_chill = Barometer::Temperature.new
215
+ @weather.source(:yahoo).current.wind_chill.c = 6
216
+ end
217
+
218
+ it "returns averages" do
219
+ @weather.wind_chill.c.should == 8
220
+ end
221
+
222
+ it "returns default when disabled" do
223
+ @weather.wind_chill(false).c.should == 10
224
+ end
225
+
226
+ end
227
+
228
+ describe "for visibility" do
229
+
230
+ before(:each) do
231
+ @weather.source(:wunderground).current.visibility = Barometer::Distance.new
232
+ @weather.source(:wunderground).current.visibility.km = 10
233
+ @weather.source(:yahoo).current.visibility = Barometer::Distance.new
234
+ @weather.source(:yahoo).current.visibility.km = 6
235
+ end
236
+
237
+ it "returns averages" do
238
+ @weather.visibility.km.should == 8
239
+ end
240
+
241
+ it "returns default when disabled" do
242
+ @weather.visibility(false).km.should == 10
243
+ end
244
+
245
+ end
246
+
247
+ end
248
+
81
249
  describe "when answering the simple questions," do
82
250
 
83
251
  before(:each) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barometer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark G
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-30 00:00:00 -06:00
12
+ date: 2009-05-02 00:00:00 -06:00
13
13
  default_executable: barometer
14
14
  dependencies: []
15
15
 
@@ -57,6 +57,23 @@ files:
57
57
  - lib/barometer/services.rb
58
58
  - lib/barometer/weather.rb
59
59
  - lib/barometer.rb
60
+ - lib/webometer
61
+ - lib/webometer/public
62
+ - lib/webometer/public/css
63
+ - lib/webometer/public/css/master.css
64
+ - lib/webometer/public/css/print.css
65
+ - lib/webometer/public/css/syntax.css
66
+ - lib/webometer/public/images
67
+ - lib/webometer/public/images/go.png
68
+ - lib/webometer/public/images/link-out.gif
69
+ - lib/webometer/views
70
+ - lib/webometer/views/contributing.erb
71
+ - lib/webometer/views/forecast.erb
72
+ - lib/webometer/views/index.erb
73
+ - lib/webometer/views/layout.erb
74
+ - lib/webometer/views/measurement.erb
75
+ - lib/webometer/views/readme.erb
76
+ - lib/webometer/webometer.rb
60
77
  - spec/barometer_spec.rb
61
78
  - spec/data_current_spec.rb
62
79
  - spec/data_distance_spec.rb
@@ -75,6 +92,7 @@ files:
75
92
  - spec/fixtures/geocode_40_73.xml
76
93
  - spec/fixtures/geocode_90210.xml
77
94
  - spec/fixtures/geocode_calgary_ab.xml
95
+ - spec/fixtures/geocode_ksfo.xml
78
96
  - spec/fixtures/geocode_newyork_ny.xml
79
97
  - spec/fixtures/geocode_T5B4M9.xml
80
98
  - spec/fixtures/google_calgary_ab.xml