Class: Weatherboy
- Inherits:
-
Object
show all
- Defined in:
- lib/weatherboy.rb,
lib/weatherboy/alert.rb,
lib/weatherboy/radar.rb,
lib/weatherboy/webcam.rb,
lib/weatherboy/current.rb,
lib/weatherboy/version.rb,
lib/weatherboy/forecast.rb
Defined Under Namespace
Classes: Alert, Current, Forecast, Radar, Webcam
Constant Summary
collapse
- BASE_URL =
"http://api.wunderground.com/auto/wui/geo/"
- VERSION =
"1.0.2"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(loc = nil) ⇒ Weatherboy
Returns a new instance of Weatherboy.
17
18
19
|
# File 'lib/weatherboy.rb', line 17
def initialize(loc=nil)
@location = loc
end
|
Instance Attribute Details
#location ⇒ Object
Returns the value of attribute location.
12
13
14
|
# File 'lib/weatherboy.rb', line 12
def location
@location
end
|
Instance Method Details
#alerts ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/weatherboy.rb', line 27
def alerts
verify
alerts = []
doc = makeCall(BASE_URL+"AlertsXML/index.xml?query=#{@location}")
doc.elements.each('alerts/alert/AlertItem') do |alert_doc|
alerts << Weatherboy::Alert.new(alert_doc)
end
alerts
end
|
#current ⇒ Object
21
22
23
24
25
|
# File 'lib/weatherboy.rb', line 21
def current
verify
doc = makeCall(BASE_URL+"WXCurrentObXML/index.xml?query=#{@location}")
Weatherboy::Current.new(doc)
end
|
#forecasts ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/weatherboy.rb', line 37
def forecasts
verify
forecasts = []
doc = makeCall(BASE_URL+"ForecastXML/index.xml?query=#{@location}")
doc.elements.each('forecast/simpleforecast/forecastday') do |forcastday|
this_forecast = Weatherboy::Forecast.new
this_forecast.first_pass(forcastday)
forecasts << this_forecast
end
i = 0
doc.elements.each('forecast/txt_forecast/forecastday') do |forecastday|
forecasts[i].second_pass(forecastday)
i = i + 1
end
forecasts
end
|
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/weatherboy.rb', line 54
def media
verify
media = {:webcams => [], :radar => nil}
doc = makeCall(BASE_URL+"GeoLookupXML/index.xml?query=#{@location}")
doc.elements.each('location/webcams/cam') do |wc|
media[:webcams] << Weatherboy::Webcam.new(wc)
end
media[:radar] = Weatherboy::Radar.new(doc.elements['location/radar'])
media
end
|