Class: YahooWeather::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo-weather/response.rb

Overview

Describes the weather conditions for a particular requested location.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_location, request_url, doc) ⇒ Response

Returns a new instance of Response.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/yahoo-weather/response.rb', line 58

def initialize (request_location, request_url, doc)
  # save off the request params
  @request_location = request_location
  @request_url = request_url

  # parse the nokogiri xml document to gather response data
  root = doc.xpath('/rss/channel').first

  @astronomy = YahooWeather::Astronomy.new(root.xpath('yweather:astronomy').first)
  @location = YahooWeather::Location.new(root.xpath('yweather:location').first)
  @units = YahooWeather::Units.new(root.xpath('yweather:units').first)
  @wind = YahooWeather::Wind.new(root.xpath('yweather:wind').first)
  @atmosphere = YahooWeather::Atmosphere.new(root.xpath('yweather:atmosphere').first)
  @image = YahooWeather::Image.new(root.xpath('image').first)

  item = root.xpath('item').first
  @condition = YahooWeather::Condition.
    new(item.xpath('yweather:condition').first)
  @forecasts = []
  item.xpath('yweather:forecast').each { |forecast| 
    @forecasts << YahooWeather::Forecast.new(forecast) }
  @latitude = item.xpath('geo:lat').first.content.to_f
  @longitude = item.xpath('geo:long').first.content.to_f
  @page_url = item.xpath('link').first.content
  @title = item.xpath('title').first.content
  @description = item.xpath('description').first.content
end

Instance Attribute Details

#astronomyObject (readonly)

a YahooWeather::Astronomy object detailing the sunrise and sunset information for the requested location.



5
6
7
# File 'lib/yahoo-weather/response.rb', line 5

def astronomy
  @astronomy
end

#atmosphereObject (readonly)

a YahooWeather::Atmosphere object detailing the atmosphere information of the requested location.



21
22
23
# File 'lib/yahoo-weather/response.rb', line 21

def atmosphere
  @atmosphere
end

#conditionObject (readonly)

a YahooWeather::Condition object detailing the current conditions of the requested location.



25
26
27
# File 'lib/yahoo-weather/response.rb', line 25

def condition
  @condition
end

#descriptionObject (readonly)

the raw HTML generated by the Yahoo! Weather service summarizing current weather conditions for the requested location.



33
34
35
# File 'lib/yahoo-weather/response.rb', line 33

def description
  @description
end

#forecastsObject (readonly)

a list of YahooWeather::Forecast objects detailing the high-level forecasted weather conditions for upcoming days.



29
30
31
# File 'lib/yahoo-weather/response.rb', line 29

def forecasts
  @forecasts
end

#imageObject (readonly)

a YahooWeather::Image record describing an image icon representing the current weather.



37
38
39
# File 'lib/yahoo-weather/response.rb', line 37

def image
  @image
end

#latitudeObject (readonly)

the latitude of the location for which weather is detailed.



40
41
42
# File 'lib/yahoo-weather/response.rb', line 40

def latitude
  @latitude
end

#locationObject (readonly)

a YahooWeather::Location object detailing the precise geographical names to which the requested location was mapped.



9
10
11
# File 'lib/yahoo-weather/response.rb', line 9

def location
  @location
end

#longitudeObject (readonly)

the longitude of the location for which weather is detailed.



43
44
45
# File 'lib/yahoo-weather/response.rb', line 43

def longitude
  @longitude
end

#page_urlObject (readonly)

a link to the Yahoo! Weather page with full detailed information on the requested location’s current weather conditions.



47
48
49
# File 'lib/yahoo-weather/response.rb', line 47

def page_url
  @page_url
end

#request_locationObject (readonly)

the location string initially requested of the service.



50
51
52
# File 'lib/yahoo-weather/response.rb', line 50

def request_location
  @request_location
end

#request_urlObject (readonly)

the url with which the Yahoo! Weather service was accessed to build the response.



53
54
55
# File 'lib/yahoo-weather/response.rb', line 53

def request_url
  @request_url
end

#titleObject (readonly)

the prose descriptive title of the weather information.



56
57
58
# File 'lib/yahoo-weather/response.rb', line 56

def title
  @title
end

#unitsObject (readonly)

a YahooWeather::Units object detailing the units corresponding to the information detailed in the response.



13
14
15
# File 'lib/yahoo-weather/response.rb', line 13

def units
  @units
end

#windObject (readonly)

a YahooWeather::Wind object detailing the wind information at the requested location.



17
18
19
# File 'lib/yahoo-weather/response.rb', line 17

def wind
  @wind
end