Parent

Class/Module Index [+]

Quicksearch

Weatherman::Response

Response

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.

Attributes

document_root[RW]

Public Class Methods

new(raw, language = nil) click to toggle source
# File lib/yahoo_weatherman/response.rb, line 12
def initialize(raw, language = nil)
  @document_root = Nokogiri::XML(raw).xpath('rss/channel')
  @i18n = Weatherman::I18N.new(language)
end

Public Instance Methods

astronomy() click to toggle source

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
condition() click to toggle source

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
description() click to toggle source

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
Also aliased as: summary
description_image() click to toggle source

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() click to toggle source

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
image() click to toggle source

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() click to toggle source

Latitude:

response.latitude => -49.90
# File lib/yahoo_weatherman/response.rb, line 99
def latitude
  geo_attribute('lat')
end
location() click to toggle source

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() click to toggle source

Longitude;

response.longitude => -45.32
# File lib/yahoo_weatherman/response.rb, line 108
def longitude
  geo_attribute('long')
end
parsed_description() click to toggle source

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
summary() click to toggle source
Alias for: description
units() click to toggle source

Units:

units = response.units
units['temperature']  => "C"
units['distance']  => "km"
units['pressure']  => "mb"
units['speed']  => "km/h"
# File lib/yahoo_weatherman/response.rb, line 80
def units
  attribute('yweather:units')
end
wind() click to toggle source

Wind’s details:

wind = response.wind
wind['chill'] => 21 
wind['direction'] => 340 
wind['chill'] => 9.66
# File lib/yahoo_weatherman/response.rb, line 39
def wind
  do_convertions(attribute('yweather:wind'), [:chill, :to_i], [:direction, :to_i], [:speed, :to_f]) 
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.