Module: Updog

Defined in:
lib/updog.rb

Class Method Summary collapse

Class Method Details

.get_weather(area) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/updog.rb', line 7

def self.get_weather(area)
  url       = "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(area)}"
  document  = Nokogiri::XML(open(url))
  
  qualitive = document.css('fcttext')
  
  document.css("simpleforecast forecastday").each_with_index do |forecastday, i|
    highs = forecastday.css('high')
    lows  = forecastday.css('low')
    
    print "\n"
    print forecastday.css("date weekday").first.content
    print "\n"
    print " High: #{highs.css('fahrenheit').first.content} F / #{highs.css('celsius').first.content} C \n"
    print " Low:  #{lows.css('fahrenheit').first.content} F / #{lows.css('celsius').first.content} C   \n"
    print " #{qualitive[i].content} \n" if qualitive[i]
  end
  
  print "\n"
end