Sha256: a65891795307b643d450420788448d92df3f7088b40ff9bab11042e775cd1e10

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

class YahooWeather::Response
  attr_reader :doc, :title, :link, :description,
              :language, :last_build_date, :ttl,
              :lat, :long

  def initialize(doc)
    @doc = doc
    @title            = get_text('item/title')
    @link             = get_text('link')
    @description      = get_text('description')
    @language         = get_text('language')
    @last_build_date  = Time.parse(get_text('lastBuildDate'))
    @ttl              = get_text('ttl').to_i
    @lat              = get_text('item/geo|lat').to_f
    @long             = get_text('item/geo|long').to_f
  end

  def location
    YahooWeather::Location.new(@doc.at('yweather|location'))
  end

  def units
    YahooWeather::Units.new(@doc.at('yweather|units'))
  end

  def astronomy
    YahooWeather::Astronomy.new(@doc.at('yweather|astronomy'))
  end

  def atmosphere
    YahooWeather::Atmosphere.new(@doc.at('yweather|atmosphere'))
  end

  def condition
    YahooWeather::Condition.new(@doc.at('item/yweather|condition'))
  end

  def wind
    YahooWeather::Wind.new(@doc.at('yweather|wind'))
  end

  def forecasts
    forecasts = []
    @doc.search('item/yweather|forecast').each do |forecast|
      forecasts << YahooWeather::Forecast.new(forecast)
    end
    forecasts
  end

private
  def get_text(tag_name)
    @doc.at(tag_name).children.text
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yahoo_weather-1.0.7 lib/yahoo_weather/response.rb
yahoo_weather-1.0.6 lib/yahoo_weather/response.rb
yahoo_weather-1.0.5 lib/yahoo_weather/response.rb
yahoo_weather-1.0.4 lib/yahoo_weather/response.rb
yahoo_weather-1.0.3 lib/yahoo_weather/response.rb
yahoo_weather-1.0.2 lib/yahoo_weather/response.rb
yahoo_weather-1.0.1 lib/yahoo_weather/response.rb
yahoo_weather-1.0.0 lib/yahoo_weather/response.rb