Class: Hamweather::Forecast
- Inherits:
-
Object
- Object
- Hamweather::Forecast
- Defined in:
- lib/hamweather/forecast.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#dailies ⇒ Object
> day_proxy_object.high_farenheit => hour_proxy_object.high_farenheit.
-
#forecast ⇒ Object
> day_proxy_object.high_farenheit => hour_proxy_object.high_farenheit.
-
#hourlies ⇒ Object
> day_proxy_object.high_farenheit => hour_proxy_object.high_farenheit.
Class Method Summary collapse
-
.fetch(location_uri) ⇒ Object
TODO stub out calls to this where possible.
Instance Method Summary collapse
- #each_day ⇒ Object
- #each_hour ⇒ Object
-
#initialize(location) ⇒ Forecast
constructor
A new instance of Forecast.
Constructor Details
#initialize(location) ⇒ Forecast
Returns a new instance of Forecast.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hamweather/forecast.rb', line 14 def initialize(location) # Construct url from api key, location uri # Request url, get xml then parse xml_data = self.class.fetch(location.to_uri).gsub!(/\n/,'') data = Hpricot.parse(xml_data) @dailies = {} @hourlies = {} data.at(:wxforecast).children.each do |day| #TODO make ordered hash @dailies[day[:date].to_s] = Daily.new(day) end data.at(:wxshortterm).children.each do |hour| #TODO make ordered hash @hourlies[hour[:time]] = Hourly.new(hour) @dailies[hour[:date]].hours[hour[:time]] = Hourly.new(hour) end end |
Instance Attribute Details
#dailies ⇒ Object
> day_proxy_object.high_farenheit
> hour_proxy_object.high_farenheit
12 13 14 |
# File 'lib/hamweather/forecast.rb', line 12 def dailies @dailies end |
#forecast ⇒ Object
> day_proxy_object.high_farenheit
> hour_proxy_object.high_farenheit
12 13 14 |
# File 'lib/hamweather/forecast.rb', line 12 def forecast @forecast end |
#hourlies ⇒ Object
> day_proxy_object.high_farenheit
> hour_proxy_object.high_farenheit
12 13 14 |
# File 'lib/hamweather/forecast.rb', line 12 def hourlies @hourlies end |
Class Method Details
.fetch(location_uri) ⇒ Object
TODO stub out calls to this where possible. TODO / or raise an error.
37 38 39 |
# File 'lib/hamweather/forecast.rb', line 37 def self.fetch(location_uri) Net::HTTP.get URI.parse("http://hwlite.hamweather.net/#{Hamweather.api_key}/#{location_uri}") end |
Instance Method Details
#each_day ⇒ Object
41 42 43 44 45 |
# File 'lib/hamweather/forecast.rb', line 41 def each_day @dailies.each_pair do |key, value| yield value end end |
#each_hour ⇒ Object
47 48 49 50 51 |
# File 'lib/hamweather/forecast.rb', line 47 def each_hour @hourlies.each_pair do |key, value| yield value end end |