Class: Forecast::Adapters::YahooAdapter

Inherits:
Object
  • Object
show all
Includes:
Forecast::Adapter
Defined in:
lib/forecast/adapters/yahoo_adapter.rb

Constant Summary collapse

URL_YQL =
'http://query.yahooapis.com/v1/public/yql'
URL_RSS =
'http://weather.yahooapis.com/forecastrss'

Instance Method Summary collapse

Methods included from Forecast::Adapter

#config, included, #initialize, instance, #options

Instance Method Details

#current(latitude, longitude) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/forecast/adapters/yahoo_adapter.rb', line 10

def current(latitude, longitude)
  forecast = nil
  doc = get_rss(latitude, longitude)
  if doc
    forecast = Forecast.new
    doc.elements.each('rss/channel/item/yweather:condition') do |elem|
      elem.attributes.each() do |attr|
        name = attr[0]
        value = attr[1]
        case name
          when 'date'
            forecast.date = DateTime.parse(value)
          when 'temp'
            forecast.temp = value.to_i
          when 'text'
            forecast.condition = get_condition(value)
        end
      end
    end
  end
  return forecast
end

#daily(latitude, longitude) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/forecast/adapters/yahoo_adapter.rb', line 38

def daily(latitude, longitude)
  doc = get_rss(latitude, longitude)
  forecasts = Forecast::Collection.new
  if doc
    doc.elements.each('rss/channel/item/yweather:forecast') do |elem|
      forecast = Forecast.new
      elem.attributes.each() do |attr|
        puts 'attr' + attr.to_s
        name = attr[0]
        value = attr[1]
        case name
          when 'date'
            forecast.date = DateTime.parse(value)
          when 'low'
            forecast.temp_min = get_temp(value)
          when 'high'
            forecast.temp_max = get_temp(value)
          when 'text'
            forecast.condition = get_condition(value)
        end
      end
      forecast.temp = (forecast.temp_min + forecast.temp_max) / 2
      forecasts << forecast
    end
  end
  return forecasts
end

#hourly(latitude, longitude) ⇒ Object



33
34
35
36
# File 'lib/forecast/adapters/yahoo_adapter.rb', line 33

def hourly(latitude, longitude)
  # not supported
  return []
end