attack-barometer 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ unavailable.
10
10
 
11
11
  == version
12
12
 
13
- Version 0.1.0 is the current release of this gem.
13
+ Version 0.3.0 is the current release of this gem.
14
14
  The gem is available from github (attack-barometer) or rubyforge (barometer).
15
15
  It is fully functional (for three weather service APIs).
16
16
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 3
2
+ :patch: 1
3
3
  :major: 0
4
- :minor: 2
4
+ :minor: 3
data/bin/barometer CHANGED
@@ -65,7 +65,7 @@ require 'yaml'
65
65
  KEY_FILE = File.expand_path(File.join('~', '.barometer'))
66
66
 
67
67
  class App
68
- VERSION = '0.2.3'
68
+ VERSION = '0.3.0'
69
69
 
70
70
  attr_reader :options
71
71
 
@@ -168,11 +168,11 @@ class App
168
168
 
169
169
  def output_help
170
170
  output_version
171
- RDoc::usage() #exits app
171
+ RDoc::usage('Usage') #exits app
172
172
  end
173
173
 
174
174
  def output_usage
175
- RDoc::usage('usage') # gets usage from comments above
175
+ RDoc::usage('Usage') # gets usage from comments above
176
176
  end
177
177
 
178
178
  def output_version
@@ -237,7 +237,10 @@ def pretty_summary(s)
237
237
  return unless s
238
238
  section("AVERAGES") do
239
239
  pretty_hash({
240
- "humidity" => s.humidity.to_i, "temperature" => s.temperature })
240
+ "humidity" => s.humidity.to_i, "temperature" => s.temperature,
241
+ "wind" => s.wind, "pressure" => s.pressure,
242
+ "dew_point" => s.dew_point, "heat_index" => s.heat_index,
243
+ "wind_chill" => s.wind_chill, "visibility" => s.visibility })
241
244
  end
242
245
  section("SUMMARY#{ " (@ #{@options.at})" if @options.at }") do
243
246
  pretty_hash({
@@ -375,17 +378,13 @@ end
375
378
 
376
379
  def run_web_mode(query=nil)
377
380
 
378
- puts
379
- puts "This is currently disabled"
380
- puts
381
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/demometer/demometer.rb')
382
+ require 'vegas'
381
383
 
382
- #require File.expand_path(File.dirname(__FILE__) + '/../lib/webometer/webometer.rb')
383
- #require 'vegas'
384
-
385
- #Vegas::Runner.new(Webometer, 'webometer') do |opts, app|
384
+ Vegas::Runner.new(Demometer, 'demometer') do |opts, app|
386
385
  # opts is an option parser object
387
386
  # app is your app class
388
- #end
387
+ end
389
388
  end
390
389
 
391
390
  def geocode_google_key_message
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'barometer'
4
+
5
+ # load API keys
6
+ keys = YAML.load_file(File.expand_path(File.join('~', '.barometer')))
7
+ if keys["geocode_google"]
8
+ Barometer.google_geocode_key = keys["geocode_google"]
9
+ else
10
+ exit
11
+ end
12
+
13
+ class Demometer < Sinatra::Default
14
+
15
+ get '/' do
16
+ erb :index
17
+ end
18
+
19
+ post '/' do
20
+ # apply options
21
+ Barometer.force_geocode = (params[:query][:geocode].to_s == "1" ? true : false)
22
+ Barometer.selection = { 1 => [ params[:query][:source].to_sym ] }
23
+ metric = (params[:query][:metric].to_s == "1" ? true : false)
24
+
25
+ if params[:query] && !params[:query][:q].empty?
26
+ @barometer = Barometer.new(params[:query][:q])
27
+ @weather = @barometer.measure(metric)
28
+ end
29
+ erb :index
30
+ end
31
+
32
+ get '/contributing.html' do
33
+ erb :contributing
34
+ end
35
+
36
+ get '/readme.html' do
37
+ erb :readme
38
+ end
39
+
40
+ end
@@ -0,0 +1 @@
1
+ /* nothing to see here */
Binary file
@@ -0,0 +1,32 @@
1
+ <h1 id='contribute'>Contribute</h1>
2
+
3
+ <p>Want to advance Barometer? Help out by contributing!</p>
4
+
5
+ <h2 id='find_a_bug'>Find a bug?</h2>
6
+
7
+ <p>Add it to GitHub by <a href='http://github.com/attack/barometer/issues'>creating a new issue</a>. Be sure to include all relevant information, like the versions of Barometer and Ruby you&#8217;re using. A <a href='http://gist.github.com/'>gist</a> of the code that caused the issue as well as any error messages are also very helpful.</p>
8
+
9
+ <h2 id='have_a_patch'>Have a patch?</h2>
10
+
11
+ <p>Bugs and feature requests that include patches are much more likely to get attention. Here are some guidelines that will help ensure your patch can be applied as quickly as possible:</p>
12
+
13
+ <ol>
14
+ <li>
15
+ <p><strong>Use <a href='http://git-scm.com'>Git</a> and <a href='http://github.com'>GitHub</a>:</strong> The easiest way to get setup is to fork the <a href='http://github.com/attack/barometer/'>attack/barometer repo</a>.
16
+ </p>
17
+
18
+ </li>
19
+
20
+ <li>
21
+ <p><strong>Write spec tests:</strong> If you add or modify functionality, it must include spec tests.</p>
22
+ </li>
23
+
24
+ <li>
25
+ <p><strong>Mind the <code>README</code>:</strong> If the patch adds or modifies a major feature, modify the <code>README.rdoc</code> file to reflect that.</p>
26
+
27
+ </li>
28
+
29
+ <li>
30
+ <p><strong>Push it:</strong> Once you&#8217;re ready, push your changes to a topic branch and add a note to the ticket with the URL to your branch. Or, say something like, &#8220;you can find the patch on johndoe/foobranch&#8221;.</p>
31
+ </li>
32
+ </ol>
@@ -0,0 +1,14 @@
1
+ <h4>for: <%= forecast.date %></h4>
2
+ <p>
3
+ <ul>
4
+ <li>Date: <%= forecast.date %></li>
5
+ <li>Icon: <%= forecast.icon %></li>
6
+ <li>Condition: <%= forecast.condition %></li>
7
+ <li>High: <%= forecast.high %></li>
8
+ <li>Low: <%= forecast.low %></li>
9
+ <li>POP: <%= forecast.pop %></li>
10
+ <% if forecast.sun %>
11
+ <li>Sun: rise - <%= forecast.sun.rise %>, set - <%= forecast.sun.set %></li>
12
+ <% end %>
13
+ </ul>
14
+ </p>
@@ -0,0 +1,80 @@
1
+ <h2 id='demo'>Measure the weather for:</h2>
2
+
3
+ <br/>
4
+ <form action="/" class="" id="" method="post">
5
+ <div class="text-input">
6
+ <input id="query_q" name="query[q]" size="25" type="text" />
7
+ </div>
8
+ <div class="submit-input">
9
+ <input src="/images/go.png" type="image" value="go &rarr;" />
10
+ </div>
11
+ <br/>
12
+ <div class="options-input">
13
+ Metric? :
14
+ <input id="query_metric" name="query[metric]" type="checkbox" value="1" checked="checked" />
15
+ <br/>
16
+ Source :
17
+ <input type="radio" name="query[source]" value="wunderground" checked="checked" /> Wunderground
18
+ <input type="radio" name="query[source]" value="yahoo" /> Yahoo
19
+ <input type="radio" name="query[source]" value="google" /> Google
20
+ <br/>
21
+ Force Geocode? :
22
+ <input id="query_geocode" name="query[geocode]" type="checkbox" value="1" checked="checked" />
23
+ </div>
24
+ </form>
25
+
26
+ <p>&nbsp;</p>
27
+ <br/>
28
+
29
+ <% if params[:query] && !params[:query][:q].empty? %>
30
+ <h2>query: "<%= params[:query][:q] %>"</h2>
31
+ <% end %>
32
+
33
+ <% if @weather %>
34
+
35
+ <h2>Averages</h2>
36
+ <p>
37
+ <ul>
38
+ <li>Humidity: <%= @weather.humidity.to_i %></li>
39
+ <li>Temperature: <%= @weather.temperature %></li>
40
+ <li>Wind: <%= @weather.wind %></li>
41
+ <li>Pressure: <%= @weather.pressure %></li>
42
+ <li>Dew Point: <%= @weather.dew_point %></li>
43
+ <li>Heat Index: <%= @weather.heat_index %></li>
44
+ <li>Wind Chill: <%= @weather.wind_chill %></li>
45
+ <li>Visibility: <%= @weather.visibility %></li>
46
+ </ul>
47
+ </p>
48
+
49
+ <h2>Summary</h2>
50
+ <p>
51
+ <ul>
52
+ <li>Day?: <%= @weather.day? %></li>
53
+ <li>Sunny?: <%= @weather.sunny? %></li>
54
+ <li>Windy?: <%= @weather.windy? %></li>
55
+ <li>Wet?: <%= @weather.wet? %></li>
56
+ </ul>
57
+ </p>
58
+
59
+ <% if @barometer.query %>
60
+ <h3>Query</h3>
61
+ <p>
62
+ <ul>
63
+ <li>Format: <%= @barometer.query.format %></li>
64
+ <% if @barometer.query.geo %>
65
+ <li>Locality: <%= @barometer.query.geo.locality %></li>
66
+ <li>Region: <%= @barometer.query.geo.region %></li>
67
+ <li>Country: <%= @barometer.query.geo.country %></li>
68
+ <li>Country Code: <%= @barometer.query.geo.country_code %></li>
69
+ <li>Latitude: <%= @barometer.query.geo.latitude %></li>
70
+ <li>Longitude: <%= @barometer.query.geo.longitude %></li>
71
+ <% end %>
72
+ </ul>
73
+ </p>
74
+ <% end %>
75
+
76
+ <% @weather.measurements.each do |measurement| %>
77
+ <%= erb(:measurement, :locals => { :measurement => measurement }, :layout => false) %>
78
+ <% end %>
79
+
80
+ <% end %>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <title>Barometer</title>
6
+ <!--> <link rel='stylesheet' href='/css/master.css' type='text/css' media="screen, projection">
7
+ <link rel='stylesheet' href='/css/syntax.css' type='text/css' media="screen, projection">
8
+ <link rel='stylesheet' href='/css/print.css' type='text/css' media="print">
9
+ <link rel='shortcut icon' href='/images/favicon.ico'>-->
10
+ <link rel='alternate' href='http://attack.github.com/feed.xml' type='application/atom+xml' title='Barometers Blog'>
11
+
12
+ </head>
13
+ <body id=''>
14
+
15
+ <div id='wrap'>
16
+
17
+ <div id='head'>
18
+ <h1><a href='/'>Barometer</a></h1>
19
+ <ul>
20
+ <li><a href='/'>Demo</a></li>
21
+ <li><a href='/readme.html'>README</a></li>
22
+ <li><a href='/contributing.html'>Contribute</a></li>
23
+ <li><a class="out" href='http://github.com/attack/barometer'>Code</a></li>
24
+ </ul>
25
+ </div>
26
+
27
+ <div id='content'>
28
+ <%= yield %>
29
+ </div>
30
+
31
+ <div id='foot'>
32
+ </div>
33
+
34
+ </div>
35
+
36
+ <a href="http://github.com/attack/barometer"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub" /></a>
37
+ </body>
38
+ </html>
@@ -0,0 +1,88 @@
1
+ <h2><%= measurement.source.to_s.capitalize %></h2>
2
+ <p>
3
+ <ul>
4
+ <li>Source: <%= measurement.source %></li>
5
+ <li>Time: <%= measurement.time %></li>
6
+ <li>Metric: <%= measurement.metric? %></li>
7
+ <li>Success: <%= measurement.success? %></li>
8
+ </ul>
9
+ </p>
10
+
11
+ <% if measurement.location %>
12
+ <h3>Location</h3>
13
+ <p>
14
+ <ul>
15
+ <li>id: <%= measurement.location.id %></li>
16
+ <li>Name: <%= measurement.location.name %></li>
17
+ <li>City: <%= measurement.location.city %> %</li>
18
+ <li>State Name: <%= measurement.location.state_name %></li>
19
+ <li>State Code: <%= measurement.location.state_code %></li>
20
+ <li>Country: <%= measurement.location.country %></li>
21
+ <li>Country Code: <%= measurement.location.country_code %></li>
22
+ <li>Zip Code: <%= measurement.location.zip_code %></li>
23
+ <li>Latitude: <%= measurement.location.latitude %></li>
24
+ <li>Longitude: <%= measurement.location.longitude %></li>
25
+ </ul>
26
+ </p>
27
+ <% end %>
28
+
29
+ <% if measurement.station %>
30
+ <h3>Station</h3>
31
+ <p>
32
+ <ul>
33
+ <li>id: <%= measurement.station.id %></li>
34
+ <li>Name: <%= measurement.station.name %></li>
35
+ <li>City: <%= measurement.station.city %> %</li>
36
+ <li>State Name: <%= measurement.station.state_name %></li>
37
+ <li>State Code: <%= measurement.station.state_code %></li>
38
+ <li>Country: <%= measurement.station.country %></li>
39
+ <li>Country Code: <%= measurement.station.country_code %></li>
40
+ <li>Zip Code: <%= measurement.station.zip_code %></li>
41
+ <li>Latitude: <%= measurement.station.latitude %></li>
42
+ <li>Longitude: <%= measurement.station.longitude %></li>
43
+ </ul>
44
+ </p>
45
+ <% end %>
46
+
47
+ <% if measurement.timezone %>
48
+ <h3>Timezone</h3>
49
+ <p>
50
+ <ul>
51
+ <li>Long: <%= measurement.timezone.timezone %></li>
52
+ <li>Code: <%= measurement.timezone.code %></li>
53
+ <li>DST?: <%= measurement.timezone.dst? %></li>
54
+ </ul>
55
+ </p>
56
+ <% end %>
57
+
58
+ <% if measurement.current %>
59
+ <h3>Current</h3>
60
+ <p>
61
+ <ul>
62
+ <li>Time: <%= measurement.current.time %></li>
63
+ <li>Local Time: <%= measurement.current.local_time %></li>
64
+ <li>Humidity: <%= measurement.current.humidity %> %</li>
65
+ <li>Icon: <%= measurement.current.icon %></li>
66
+ <li>Condition: <%= measurement.current.condition %></li>
67
+ <li>Temperature: <%= measurement.current.temperature %></li>
68
+ <li>Dew Point: <%= measurement.current.dew_point %></li>
69
+ <li>Heat Index: <%= measurement.current.heat_index %></li>
70
+ <li>Wind Chill: <%= measurement.current.wind_chill %></li>
71
+ <li>Wind: <%= measurement.current.wind %> @ <%= measurement.current.wind.direction %> [<%= measurement.current.wind.degrees %> degrees]</li>
72
+ <li>Pressure: <%= measurement.current.pressure %></li>
73
+ <li>Visibility: <%= measurement.current.visibility %></li>
74
+ <% if measurement.current.sun %>
75
+ <li>Sun: rise - <%= measurement.current.sun.rise %>, set - <%= measurement.current.sun.set %></li>
76
+ <% end %>
77
+ </ul>
78
+ </p>
79
+ <% end %>
80
+
81
+ <% if measurement.forecast %>
82
+ <h3>Forecast</h3>
83
+
84
+ <% measurement.forecast.each do |forecast| %>
85
+ <%= erb(:forecast, :locals => { :forecast => forecast }, :layout => false) %>
86
+ <% end %>
87
+
88
+ <% end %>
@@ -0,0 +1,386 @@
1
+ <h1>barometer</h1>
2
+ <p>
3
+ A multi API consuming weather forecasting superstar.
4
+ </p>
5
+ <p>
6
+ Barometer provides a common public API to one or more weather services
7
+ (APIs) of your choice. Weather services can co-exist to retrieve extensive
8
+ information, or they can be used in a hierarchical configuration where
9
+ lower preferred weather services are only used if previous services are
10
+ unavailable.
11
+ </p>
12
+ <h2>version</h2>
13
+ <p>
14
+
15
+ Version 0.3.0 is the current release of this gem. The gem is available from
16
+ github (attack-barometer) or rubyforge (barometer). It is fully functional
17
+ (for three weather service APIs).
18
+ </p>
19
+ <h2>status</h2>
20
+ <p>
21
+ Currently this project is in development and will only work for a few
22
+ weather services (wunderground, google, yahoo).
23
+ </p>
24
+ <p>
25
+ Features to be added next:
26
+ </p>
27
+ <ul>
28
+ <li>even more weather service drivers (noaa, weather.com, weatherbug)
29
+
30
+ </li>
31
+ </ul>
32
+ <h1>dependencies</h1>
33
+ <h3>Google API key</h3>
34
+
35
+ <p>
36
+ In most cases you will need to have a free google geocode api key. Get one
37
+ here: <a href="http://code.google.com/apis/maps/signup.html">code.google.com/apis/maps/signup.html</a>
38
+ Then put it in the file &#8217;~/.barometer&#8217; by adding the line:
39
+ geocode_google: YOUR_KEY_HERE
40
+ </p>
41
+ <p>
42
+ You will need this for:
43
+ </p>
44
+ <ul>
45
+ <li>using the Barometer gem (unless you use queries that are directly supported
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>
50
+ </ul>
51
+ <h3>HTTParty</h3>
52
+ <p>
53
+ Why? HTTParty was created and designed specifically for consuming web
54
+ services. I choose to use this over using the Net::HTTP library directly to
55
+ allow for faster development of this project.
56
+ </p>
57
+ <p>
58
+ HTTParty is also extended to include configurable Timeout support.
59
+ </p>
60
+ <h3>tzinfo</h3>
61
+ <p>
62
+ Why? Barometer deals with time information for locations all over the
63
+ world. This information doesn&#8217;t mean that much if it can&#8217;t be
64
+ converted to times that don&#8217;t correspond to the applicable timezone.
65
+ Tzinfo handles this time zone manipulation.
66
+
67
+ </p>
68
+ <h3>graticule (very soft dependency)</h3>
69
+ <p>
70
+ Why? Barometer returns the weather for a given location. Most weather
71
+ service APIs are somewhat restricted on the query format they receive. To
72
+ bridge this gap and allow for maximum flexibility on the
73
+ &#8216;barometer&#8217; query format, the query will be geo-coded using the
74
+ Google geocoding service, if required. Graticule can provide this geocoding
75
+ interface.
76
+ </p>
77
+ <p>
78
+ Using Graticule requires a free Google API key for geocoding. It is
79
+ possible to use barometer without geocoding, though your query format will
80
+ be limited to that of the weather service API.
81
+ </p>
82
+ <p>
83
+ ALTERNATE: If you supply a Google API key but don&#8217;t install the
84
+ Graticule gem, HTTParty will be used instead to provide the same geocoding.
85
+ Basically Graticule is only used if it exists.
86
+ </p>
87
+ <p>
88
+
89
+ NOTE: you can force Barometer not to use Graticule, even if you have it
90
+ installed using the following:
91
+ </p>
92
+ <pre>
93
+ Barometer.skip_graticule = true
94
+ </pre>
95
+ <h1>usage</h1>
96
+ <p>
97
+ You can use barometer right out of the box, as it is configured to use one
98
+ register-less (no API key required) international weather service
99
+ (wunderground.com).
100
+ </p>
101
+ <p>
102
+ For better results, signup for a google-map key and enhance your barometer
103
+ with geo-coding.
104
+ </p>
105
+ <pre>
106
+ require 'barometer'
107
+
108
+ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
109
+
110
+ barometer = Barometer.new(&quot;Paris&quot;)
111
+ weather = barometer.measure
112
+
113
+ puts weather.current.temperture
114
+ </pre>
115
+ <h2>multiple weather API, with hierarchy</h2>
116
+ <pre>
117
+ require 'barometer'
118
+
119
+ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
120
+ # use yahoo and google, if they both fail, use wunderground
121
+ Barometer.selection = { 1 =&gt; [:yahoo, :google], 2 =&gt; :wunderground }
122
+
123
+ barometer = Barometer.new(&quot;Paris&quot;)
124
+ weather = barometer.measure
125
+
126
+ puts weather.current.temperture
127
+
128
+ </pre>
129
+ <h2>command line</h2>
130
+ <p>
131
+ You can use barometer from the command line.
132
+ </p>
133
+ <pre>
134
+ # barometer berlin
135
+ </pre>
136
+ <p>
137
+ This will output the weather information for the given query. See the help
138
+ for more command line information.
139
+ </p>
140
+ <pre>
141
+ # barometer -h
142
+ </pre>
143
+
144
+ <h3>web demo</h3>
145
+ <p>
146
+ There is a Sinatra application that demos the functionality of Barometer,
147
+ and provides Barometer information. Start this local demo with:
148
+ </p>
149
+ <pre>
150
+ # barometer -w
151
+ </pre>
152
+ <p>
153
+ NOTE: This requires the gems &quot;sinatra&quot; and &quot;vegas&quot;.
154
+ </p>
155
+
156
+ <h3>fail</h3>
157
+ <p>
158
+ What would cause a weather service to fail? The most obvious is that the
159
+ particular weather service in currently unavailable or not reachable. Other
160
+ possible reasons would include not having the API (or a valid API key for
161
+ the particular weather service, if required), not providing a valid query,
162
+ or providing a query for a location not supported by the weather service.
163
+ </p>
164
+ <p>
165
+ For example, if you look at the example above, the query of
166
+ &quot;Paris&quot; refers to a city in France. Yahoo weather services only
167
+ supports weather results for USA (at least at the time of writing).
168
+ Therefore, Barometer would not use Yahoo, just Google and failover to use
169
+ Wunderground (if needed).
170
+ </p>
171
+ <h3>bootstrapping</h3>
172
+ <p>
173
+ You can use weather service drivers directly. Below is an example to use
174
+ Wunderground, but since the driver interface is abstracted it will be the
175
+ same for all supported services.
176
+ </p>
177
+ <pre>
178
+
179
+ require 'barometer'
180
+ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
181
+
182
+ query = Barometer::Query.new(&quot;Paris&quot;)
183
+ weather = Barometer::Service.source(:wunderground).measure(query)
184
+
185
+ puts weather.current.temperture
186
+
187
+ # OR, even more raw
188
+
189
+ measurement = Barometer::Measurement.new
190
+ weather = Barometer::Wunderground.measure_all(measurement, &quot;Paris&quot;)
191
+
192
+ puts weather.current.temperture
193
+ </pre>
194
+ <p>
195
+ NOTE: The disadvantage to using the drivers directly is that you lose the
196
+ advantage of redundancy/failover added by the Module as a whole.
197
+ </p>
198
+ <p>
199
+ NOTE: You still must create the Barometer::Query object with your query
200
+ string instead of directly feeding the query string to the service (as in
201
+ bootstrap example #1). The Barometer::Query object has behavior required by
202
+ the service that a regular String doesn&#8217;t have. Using a driver
203
+ directly WILL accept a String (as in bootstrap example #2).
204
+
205
+ </p>
206
+ <h2>searching</h2>
207
+ <p>
208
+ After you have measured the data, Barometer provides several methods to
209
+ help you get the data you are after. All examples assume you already have
210
+ measured the data as shown in the above examples.
211
+ </p>
212
+ <h3>by preference (default service)</h3>
213
+ <pre>
214
+ weather.default # returns measurement for default source
215
+ weather.current # returns current_measurement for default
216
+ weather.now # returns current_measurement for default
217
+ weather.forecast # returns all forecast_measurements for default
218
+ weather.today # returns forecast_measurement for default today
219
+ weather.tomorrow # returns forecast_measurement for default tomorrow
220
+
221
+ puts weather.now.temperature.c
222
+ puts weather.tomorrow.high.c
223
+ </pre>
224
+ <h3>by source</h3>
225
+ <pre>
226
+ weather.source(:wunderground) # returns measurement for specified source
227
+ weather.sources # lists all successful sources
228
+
229
+ puts weather.source(:wunderground).current.temperature.c
230
+
231
+ </pre>
232
+ <h3>by date</h3>
233
+ <pre>
234
+ # note, the date is the date of the locations weather, not the date of the
235
+ # user measuring the weather
236
+ date = Date.parse(&quot;01-01-2009&quot;)
237
+ weather.for(date) # returns forecast_measurement for default on date
238
+ weather.source(:wunderground).for(date) # same as above but specific source
239
+
240
+ puts weather.source(:wunderground).for(date).high.c
241
+ </pre>
242
+ <h3>by time</h3>
243
+ <pre>
244
+ # note, the time is the time of the locations weather, not the time of the
245
+ # user measuring the weather
246
+ time = Time.parse(&quot;13:00 01-01-2009&quot;)
247
+ weather.for(time) # returns forecast_measurement for default at time
248
+ weather.source(:wunderground).for(time) # same as above but specific source
249
+
250
+ puts weather.source(:wunderground).for(time).low.f
251
+
252
+ </pre>
253
+ <h2>averages</h2>
254
+ <p>
255
+ If you consume more then one weather service, Barometer can provide
256
+ averages for the values (currently only for the &#8216;current&#8217;
257
+ values and not the forecasted values).
258
+ </p>
259
+ <pre>
260
+ require 'barometer'
261
+
262
+ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
263
+ # use yahoo and wunderground
264
+ Barometer.selection = { 1 =&gt; [:yahoo, :wunderground] }
265
+
266
+ barometer = Barometer.new(&quot;90210&quot;)
267
+ weather = barometer.measure
268
+
269
+ puts weather.temperture
270
+
271
+ </pre>
272
+ <p>
273
+ This will calculate the average temperature as given by :yahoo and
274
+ :wunderground
275
+ </p>
276
+ <h2>simple answers</h2>
277
+ <p>
278
+ After you have measured the data, Barometer provides several &quot;simple
279
+ answer&quot; methods to help you get answers to some basic questions. All
280
+ examples assume you already have measured the data as shown in the above
281
+ examples.
282
+ </p>
283
+ <p>
284
+ All of these questions are ultimately specific to the weather source(s) you
285
+ are configured to use. All sources that have successfully measured data
286
+ will be asked, but if there is no data that can answer the question then
287
+ there will be no answer.
288
+ </p>
289
+ <h3>is it windy?</h3>
290
+
291
+ <pre>
292
+ # 1st parameter is the threshold wind speed for being windy
293
+ # 2nd parameter is the utc_time for which you want to know the answer,
294
+ # this defaults to the current time
295
+ # NOTE: in my example the values are metric, so the threshold is 10 kph
296
+
297
+ weather.windy?(10)
298
+ </pre>
299
+ <h3>is it wet?</h3>
300
+ <pre>
301
+ # 1st parameter is the threshold pop (%) for being wet
302
+ # 2nd parameter is the utc_time for which you want to know the answer,
303
+ # this defaults to the current time
304
+ # NOTE: in my example the threshold is 50 %
305
+
306
+ weather.wet?(50)
307
+ </pre>
308
+ <h3>is it sunny?</h3>
309
+ <pre>
310
+ # 1st parameter is the utc_time for which you want to know the answer,
311
+ # this defaults to the current time
312
+
313
+ weather.sunny?
314
+ </pre>
315
+ <h3>is it day?</h3>
316
+
317
+ <pre>
318
+ # 1st parameter is the utc_time for which you want to know the answer,
319
+ # this defaults to the current time
320
+
321
+ weather.day?
322
+ </pre>
323
+ <h3>is it night?</h3>
324
+ <pre>
325
+ # 1st parameter is the utc_time for which you want to know the answer,
326
+ # this defaults to the current time
327
+
328
+ weather.night?
329
+ </pre>
330
+ <h1>design</h1>
331
+ <ul>
332
+ <li>create a Barometer instance
333
+
334
+ </li>
335
+ <li>supply a query, there are very little restrictions on the format:
336
+
337
+ <ul>
338
+
339
+ <li>city, country, specific address (basically anything Google will geocode)
340
+
341
+ </li>
342
+ <li>US zip code (skips geocoding if weather service accepts this directly)
343
+
344
+ </li>
345
+ <li>postal code (skips geocoding if weather service accepts this directly)
346
+
347
+ </li>
348
+ <li>latitude and longitude (skips geocoding if weather service accepts this
349
+ directly)
350
+
351
+ </li>
352
+ <li>TODO: international airport code (skips geocoding if weather service
353
+ accepts this directly)
354
+
355
+ </li>
356
+ </ul>
357
+ </li>
358
+ <li>if geocoding required, geocode the query
359
+
360
+ </li>
361
+ <li>determine which weather services will be queried (one or multiple)
362
+
363
+ </li>
364
+ <li>query the weather services
365
+
366
+
367
+ </li>
368
+ <li>save the data
369
+
370
+ </li>
371
+ <li>repeat weather service queries as needed
372
+
373
+ </li>
374
+ </ul>
375
+ <h1>extending</h1>
376
+ <p>
377
+ Barometer attempts to be a common API to any weather service API. I have
378
+ included several weather service &#8216;drivers&#8217;, but I know there
379
+ are many more available. Please use the provided ones as examples to create
380
+ more.
381
+ </p>
382
+ <h2>copyright</h2>
383
+ <p>
384
+ Copyright &#169; 2009 Mark G. See LICENSE for details.
385
+
386
+ </p>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attack-barometer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.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-05-02 00:00:00 -07:00
12
+ date: 2009-05-03 00:00:00 -07:00
13
13
  default_executable: barometer
14
14
  dependencies: []
15
15
 
@@ -57,6 +57,20 @@ files:
57
57
  - lib/barometer/services.rb
58
58
  - lib/barometer/weather.rb
59
59
  - lib/barometer.rb
60
+ - lib/demometer
61
+ - lib/demometer/demometer.rb
62
+ - lib/demometer/public
63
+ - lib/demometer/public/css
64
+ - lib/demometer/public/css/master.css
65
+ - lib/demometer/public/images
66
+ - lib/demometer/public/images/go.png
67
+ - lib/demometer/views
68
+ - lib/demometer/views/contributing.erb
69
+ - lib/demometer/views/forecast.erb
70
+ - lib/demometer/views/index.erb
71
+ - lib/demometer/views/layout.erb
72
+ - lib/demometer/views/measurement.erb
73
+ - lib/demometer/views/readme.erb
60
74
  - spec/barometer_spec.rb
61
75
  - spec/data_current_spec.rb
62
76
  - spec/data_distance_spec.rb