Class: YahooWeather::Response
- Inherits:
-
Object
- Object
- YahooWeather::Response
- Defined in:
- lib/yahoo-weather.rb
Overview
Describes the weather conditions for a particular requested location.
Constant Summary collapse
- @@REGEXP_IMAGE =
regular expression used to pull the weather image icon from full description text.
Regexp.new(/img src="([^"]+)"/)
Instance Attribute Summary collapse
-
#astronomy ⇒ Object
readonly
a YahooWeather::Astronomy object detailing the sunrise and sunset information for the requested location.
-
#atmosphere ⇒ Object
readonly
a YahooWeather::Atmosphere object detailing the atmosphere information of the requested location.
-
#condition ⇒ Object
readonly
a YahooWeather::Condition object detailing the current conditions of the requested location.
-
#description ⇒ Object
readonly
the raw HTML generated by the Yahoo! Weather service summarizing current weather conditions for the requested location.
-
#forecasts ⇒ Object
readonly
a list of YahooWeather::Forecast objects detailing the high-level forecasted weather conditions for upcoming days.
-
#image_url ⇒ Object
readonly
a link to the Yahoo! Weather image icon representing the current weather conditions visually.
-
#latitude ⇒ Object
readonly
the latitude of the location for which weather is detailed.
-
#location ⇒ Object
readonly
a YahooWeather::Location object detailing the precise geographical names to which the requested location was mapped.
-
#longitude ⇒ Object
readonly
the longitude of the location for which weather is detailed.
-
#page_url ⇒ Object
readonly
a link to the Yahoo! Weather page with full detailed information on the requested location’s current weather conditions.
-
#request_location ⇒ Object
readonly
the location string initially requested of the service.
-
#request_url ⇒ Object
readonly
the url with which the Yahoo! Weather service was accessed to build the response.
-
#title ⇒ Object
readonly
the prose descriptive title of the weather information.
-
#units ⇒ Object
readonly
a YahooWeather::Units object detailing the units corresponding to the information detailed in the response.
-
#wind ⇒ Object
readonly
a YahooWeather::Wind object detailing the wind information at the requested location.
Instance Method Summary collapse
-
#initialize(request_location, request_url, payload) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(request_location, request_url, payload) ⇒ Response
Returns a new instance of Response.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/yahoo-weather.rb', line 232 def initialize (request_location, request_url, payload) @request_location = request_location @request_url = request_url #puts payload['rss']['channel'] root = payload['rss']['channel'] #puts root.to_yaml @astronomy = YahooWeather::Astronomy.new root['astronomy'] @location = YahooWeather::Location.new root['location'] @units = YahooWeather::Units.new root['units'] @wind = YahooWeather::Wind.new root['wind'] @atmosphere = YahooWeather::Atmosphere.new root['atmosphere'] item = root['item'] @condition = YahooWeather::Condition.new item['condition'] @forecasts = [] item['forecast'].each { |forecast| @forecasts << YahooWeather::Forecast.new(forecast) } @latitude = item['lat'].to_f @longitude = item['long'].to_f @page_url = item['link'] @title = item['title'] @description = item['description'] match_data = @@REGEXP_IMAGE.match(description) @image_url = (match_data) ? match_data[1] : nil end |
Instance Attribute Details
#astronomy ⇒ Object (readonly)
a YahooWeather::Astronomy object detailing the sunrise and sunset information for the requested location.
175 176 177 |
# File 'lib/yahoo-weather.rb', line 175 def astronomy @astronomy end |
#atmosphere ⇒ Object (readonly)
a YahooWeather::Atmosphere object detailing the atmosphere information of the requested location.
191 192 193 |
# File 'lib/yahoo-weather.rb', line 191 def atmosphere @atmosphere end |
#condition ⇒ Object (readonly)
a YahooWeather::Condition object detailing the current conditions of the requested location.
195 196 197 |
# File 'lib/yahoo-weather.rb', line 195 def condition @condition end |
#description ⇒ Object (readonly)
the raw HTML generated by the Yahoo! Weather service summarizing current weather conditions for the requested location.
203 204 205 |
# File 'lib/yahoo-weather.rb', line 203 def description @description end |
#forecasts ⇒ Object (readonly)
a list of YahooWeather::Forecast objects detailing the high-level forecasted weather conditions for upcoming days.
199 200 201 |
# File 'lib/yahoo-weather.rb', line 199 def forecasts @forecasts end |
#image_url ⇒ Object (readonly)
a link to the Yahoo! Weather image icon representing the current weather conditions visually.
207 208 209 |
# File 'lib/yahoo-weather.rb', line 207 def image_url @image_url end |
#latitude ⇒ Object (readonly)
the latitude of the location for which weather is detailed.
210 211 212 |
# File 'lib/yahoo-weather.rb', line 210 def latitude @latitude end |
#location ⇒ Object (readonly)
a YahooWeather::Location object detailing the precise geographical names to which the requested location was mapped.
179 180 181 |
# File 'lib/yahoo-weather.rb', line 179 def location @location end |
#longitude ⇒ Object (readonly)
the longitude of the location for which weather is detailed.
213 214 215 |
# File 'lib/yahoo-weather.rb', line 213 def longitude @longitude end |
#page_url ⇒ Object (readonly)
a link to the Yahoo! Weather page with full detailed information on the requested location’s current weather conditions.
217 218 219 |
# File 'lib/yahoo-weather.rb', line 217 def page_url @page_url end |
#request_location ⇒ Object (readonly)
the location string initially requested of the service.
220 221 222 |
# File 'lib/yahoo-weather.rb', line 220 def request_location @request_location end |
#request_url ⇒ Object (readonly)
the url with which the Yahoo! Weather service was accessed to build the response.
223 224 225 |
# File 'lib/yahoo-weather.rb', line 223 def request_url @request_url end |
#title ⇒ Object (readonly)
the prose descriptive title of the weather information.
226 227 228 |
# File 'lib/yahoo-weather.rb', line 226 def title @title end |
#units ⇒ Object (readonly)
a YahooWeather::Units object detailing the units corresponding to the information detailed in the response.
183 184 185 |
# File 'lib/yahoo-weather.rb', line 183 def units @units end |
#wind ⇒ Object (readonly)
a YahooWeather::Wind object detailing the wind information at the requested location.
187 188 189 |
# File 'lib/yahoo-weather.rb', line 187 def wind @wind end |