Object
This is where we get access to the contents parsed by Nokogiri in a object-oriented way. We also use this class to do the i18n stuff.
Astronomy:
astronomy = response.astronomy astronomy['sunrise'] => "6:01 am" astronomy['sunset'] => "7:20 pm"
# File lib/yahoo_weatherman/response.rb, line 91 def astronomy attribute('yweather:astronomy') end
Returns a hash containing the actual weather condition details:
condition = response.condition condition['text'] => "Tornado" condition['code'] => 0 condition['temp'] => 21 condition['date'] => #<Date: -1/2,0,2299161>
# File lib/yahoo_weatherman/response.rb, line 26 def condition condition = item_attribute('yweather:condition') translate! do_convertions(condition, [:code, :to_i], [:temp, :to_i], [:date, :to_date], :text) end
A short HTML snippet (raw text) with a simple weather description.
# File lib/yahoo_weatherman/response.rb, line 137 def description text_attribute('description') end
Description image. You might gonna need this if you have to customize the forecast summary.
# File lib/yahoo_weatherman/response.rb, line 130 def description_image parsed_description.css('img').first # there's only one end
Forecasts for the next 2 days.
forecast = response.forecasts.first forecast['low'] => 20 forecast['high'] => 31 forecast['text'] => "Tornado" forecast['code'] => 0 forecast['day'] => "Sat"
# File lib/yahoo_weatherman/response.rb, line 53 def forecasts item_attribute('yweather:forecast').collect do |forecast| convertions = [[:date, :to_date], [:low, :to_i], [:high, :to_i], [:code, :to_i], :day, :text] translate! do_convertions(forecast, *convertions) end end
A hash like object providing image info:
image = reponse.image image['width'] => 142 image['height'] => 18 image['title'] => "Yahoo! Weather" image['link'] => "http://weather.yahoo.com"
# File lib/yahoo_weatherman/response.rb, line 121 def image image = Weatherman::Image.new(attribute 'image') do_convertions(image, [:width, :to_i], [:height, :to_i], :title, :link, :url) end
Latitude:
response.latitude => -49.90
# File lib/yahoo_weatherman/response.rb, line 99 def latitude geo_attribute('lat') end
Location:
location = response.location location['country'] => "Brazil" location['region'] => "MG" location['city'] => Belo Horizonte
# File lib/yahoo_weatherman/response.rb, line 68 def location translate! attribute('yweather:location') end
Longitude;
response.longitude => -45.32
# File lib/yahoo_weatherman/response.rb, line 108 def longitude geo_attribute('long') end
Description parsed by Nokogiri. This is better then description if you have to walk through its nodes.
# File lib/yahoo_weatherman/response.rb, line 146 def parsed_description @parsed_description ||= Nokogiri::HTML(description) end
Generated with the Darkfish Rdoc Generator 2.