Class: WeatherApi::TodaysWeather
- Inherits:
-
Object
- Object
- WeatherApi::TodaysWeather
- Defined in:
- lib/current_weather/todays_weather.rb
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#humidity ⇒ Object
Returns the value of attribute humidity.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
-
#wind_condition ⇒ Object
Returns the value of attribute wind_condition.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ TodaysWeather
constructor
A new instance of TodaysWeather.
Constructor Details
#initialize(attributes) ⇒ TodaysWeather
Returns a new instance of TodaysWeather.
7 8 9 10 11 12 13 |
# File 'lib/current_weather/todays_weather.rb', line 7 def initialize(attributes) self.condition = attributes['condition'].first self.temperature = attributes['temp_f'].first self.humidity = attributes['humidity'].first self.icon = "www.google.com" + attributes['icon'].first self.wind_condition = attributes['wind_condition'].first end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
5 6 7 |
# File 'lib/current_weather/todays_weather.rb', line 5 def condition @condition end |
#humidity ⇒ Object
Returns the value of attribute humidity.
5 6 7 |
# File 'lib/current_weather/todays_weather.rb', line 5 def humidity @humidity end |
#icon ⇒ Object
Returns the value of attribute icon.
5 6 7 |
# File 'lib/current_weather/todays_weather.rb', line 5 def icon @icon end |
#temperature ⇒ Object
Returns the value of attribute temperature.
5 6 7 |
# File 'lib/current_weather/todays_weather.rb', line 5 def temperature @temperature end |
#wind_condition ⇒ Object
Returns the value of attribute wind_condition.
5 6 7 |
# File 'lib/current_weather/todays_weather.rb', line 5 def wind_condition @wind_condition end |
Class Method Details
.client ⇒ Object
15 16 17 |
# File 'lib/current_weather/todays_weather.rb', line 15 def self.client WeatherApi::Client.new end |
.find(location) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/current_weather/todays_weather.rb', line 23 def self.find(location) attributes_hash = Hash.new response = parse(client.get_weather(location)) response.css('current_conditions').each do |stat| stat.children.each do |key| attributes_hash[key.name] = key.values { |value| value } end end TodaysWeather.new(attributes_hash) end |
.parse(xml_package) ⇒ Object
19 20 21 |
# File 'lib/current_weather/todays_weather.rb', line 19 def self.parse(xml_package) Nokogiri::HTML(xml_package) end |