Class: WeatherApi::TodaysWeather

Inherits:
Object
  • Object
show all
Defined in:
lib/current_weather/todays_weather.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#conditionObject

Returns the value of attribute condition.



5
6
7
# File 'lib/current_weather/todays_weather.rb', line 5

def condition
  @condition
end

#humidityObject

Returns the value of attribute humidity.



5
6
7
# File 'lib/current_weather/todays_weather.rb', line 5

def humidity
  @humidity
end

#iconObject

Returns the value of attribute icon.



5
6
7
# File 'lib/current_weather/todays_weather.rb', line 5

def icon
  @icon
end

#temperatureObject

Returns the value of attribute temperature.



5
6
7
# File 'lib/current_weather/todays_weather.rb', line 5

def temperature
  @temperature
end

#wind_conditionObject

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

.clientObject



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