Class: OpenWeatherMap::CurrentWeather

Inherits:
Object
  • Object
show all
Defined in:
lib/openweathermap/current-weather.rb

Overview

Represents the current weather at a location

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CurrentWeather

Create a new CurrentWeather object

Parameters:

  • data (Hash)

    mixed data from the request



25
26
27
28
29
30
31
32
33
# File 'lib/openweathermap/current-weather.rb', line 25

def initialize(data)
  begin
    data = JSON.parse(data)
  rescue JSON::JSONError => e
    raise OpenWeatherMap::Exceptions::DataError, "error while parsing data : #{e}"
  end
  @city = OpenWeatherMap::City.new(data['name'], data['coord']['lon'], data['coord']['lat'], data['sys']['country'])
  @weather_conditions = OpenWeatherMap::WeatherConditions.new(data)
end

Instance Attribute Details

#cityOpenWeatherMap::City (readonly)

Returns Requested city’s data.

Returns:



18
19
20
# File 'lib/openweathermap/current-weather.rb', line 18

def city
  @city
end

#weather_conditionsOpenWeatherMap::WeatherConditions (readonly)

Returns Conditions at the moment.

Returns:



13
14
15
# File 'lib/openweathermap/current-weather.rb', line 13

def weather_conditions
  @weather_conditions
end