Class: Yweather::Response
- Inherits:
-
Object
- Object
- Yweather::Response
- Defined in:
- lib/yweather/response.rb
Instance Attribute Summary collapse
-
#astronomy ⇒ Object
Returns the value of attribute astronomy.
-
#atmosphere ⇒ Object
Returns the value of attribute atmosphere.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#description ⇒ Object
Returns the value of attribute description.
-
#forecasts ⇒ Object
Returns the value of attribute forecasts.
-
#image ⇒ Object
Returns the value of attribute image.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#location ⇒ Object
Returns the value of attribute location.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#page_url ⇒ Object
Returns the value of attribute page_url.
-
#request_location ⇒ Object
Returns the value of attribute request_location.
-
#request_url ⇒ Object
Returns the value of attribute request_url.
-
#title ⇒ Object
Returns the value of attribute title.
-
#units ⇒ Object
Returns the value of attribute units.
-
#wind ⇒ Object
Returns the value of attribute wind.
Instance Method Summary collapse
- #atmospheric_conditions(options = {}) ⇒ Object
-
#initialize(woeid, zipcode, url, hash) ⇒ Response
constructor
A new instance of Response.
- #wind_conditions(options = {}) ⇒ Object
Constructor Details
#initialize(woeid, zipcode, url, hash) ⇒ Response
Returns a new instance of Response.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yweather/response.rb', line 20 def initialize(woeid, zipcode, url, hash) if hash[:rss][:channel][:title] =~ /Error/ item = hash[:rss][:channel][:item] raise YweatherException, "#{hash[:rss][:channel][:title]} :: #{item[:title]} :: #{item[:description]}" return end @astronomy = Astronomy.new(hash[:rss][:channel][:astronomy]) @atmosphere = Atmosphere.new(hash[:rss][:channel][:atmosphere]) @location = Location.new(hash[:rss][:channel][:location]) @wind = Wind.new(hash[:rss][:channel][:wind]) @units = Units.new(hash[:rss][:channel][:units]) @image = Image.new(hash[:rss][:channel][:image]) item = hash[:rss][:channel][:item] @condition = Condition.new(item[:condition]) @forecasts = [] item[:forecast].each do |forecast| @forecasts << Forecast.new(forecast) end @latitude = item[:lat] @longitude = item[:long] @page_url = item[:link] @title = item[:title] @description = item[:description] end |
Instance Attribute Details
#astronomy ⇒ Object
Returns the value of attribute astronomy.
4 5 6 |
# File 'lib/yweather/response.rb', line 4 def astronomy @astronomy end |
#atmosphere ⇒ Object
Returns the value of attribute atmosphere.
5 6 7 |
# File 'lib/yweather/response.rb', line 5 def atmosphere @atmosphere end |
#condition ⇒ Object
Returns the value of attribute condition.
6 7 8 |
# File 'lib/yweather/response.rb', line 6 def condition @condition end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/yweather/response.rb', line 7 def description @description end |
#forecasts ⇒ Object
Returns the value of attribute forecasts.
8 9 10 |
# File 'lib/yweather/response.rb', line 8 def forecasts @forecasts end |
#image ⇒ Object
Returns the value of attribute image.
9 10 11 |
# File 'lib/yweather/response.rb', line 9 def image @image end |
#latitude ⇒ Object
Returns the value of attribute latitude.
10 11 12 |
# File 'lib/yweather/response.rb', line 10 def latitude @latitude end |
#location ⇒ Object
Returns the value of attribute location.
11 12 13 |
# File 'lib/yweather/response.rb', line 11 def location @location end |
#longitude ⇒ Object
Returns the value of attribute longitude.
12 13 14 |
# File 'lib/yweather/response.rb', line 12 def longitude @longitude end |
#page_url ⇒ Object
Returns the value of attribute page_url.
13 14 15 |
# File 'lib/yweather/response.rb', line 13 def page_url @page_url end |
#request_location ⇒ Object
Returns the value of attribute request_location.
14 15 16 |
# File 'lib/yweather/response.rb', line 14 def request_location @request_location end |
#request_url ⇒ Object
Returns the value of attribute request_url.
15 16 17 |
# File 'lib/yweather/response.rb', line 15 def request_url @request_url end |
#title ⇒ Object
Returns the value of attribute title.
16 17 18 |
# File 'lib/yweather/response.rb', line 16 def title @title end |
#units ⇒ Object
Returns the value of attribute units.
17 18 19 |
# File 'lib/yweather/response.rb', line 17 def units @units end |
#wind ⇒ Object
Returns the value of attribute wind.
18 19 20 |
# File 'lib/yweather/response.rb', line 18 def wind @wind end |
Instance Method Details
#atmospheric_conditions(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/yweather/response.rb', line 47 def atmospheric_conditions( = {}) pressure = (@atmosphere. == "steady") ? "#{@atmosphere.} at #{@atmosphere.pressure}#{@units.pressure}" : "#{@atmosphere.pressure}#{@units.pressure} and #{@atmosphere.}" h = ::HashWithIndifferentAccess.new({ :humidity => "#{@atmosphere.humidity}%", :visibility => "#{@atmosphere.visibility} #{@units.distance}", :pressure => "#{pressure}" }) return_content(h, [:format]) end |
#wind_conditions(options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/yweather/response.rb', line 61 def wind_conditions( = {}) # chill: wind chill in degrees (integer) # direction: wind direction, in degrees (integer) # speed: wind speed, in the units specified in the speed attribute of the yweather:units element (mph or kph). (integer) h = ::HashWithIndifferentAccess.new({ :chill => "#{@wind.chill}°", :direction => "#{@wind.direction}°", :speed => "#{@wind.speed} #{@units.speed}" }) return_content(h, [:format]) end |