Class: OpenWeatherMap::Forecast

Inherits:
Object
  • Object
show all
Defined in:
lib/openweathermap/forecast.rb

Overview

Represents the forecast for a specific location

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Forecast

Create a new Forecast object

Parameters:

  • data (Hash)

    mixed data from the request



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/openweathermap/forecast.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['city']['name'], data['city']['coord']['lon'], data['city']['coord']['lat'], data['city']['country'])
  @forecast = []
  data['list'].each do |element|
    forecast << OpenWeatherMap::WeatherConditions.new(element)
  end
end

Instance Attribute Details

#cityOpenWeatherMap::City (readonly)

Returns Requested city’s data.

Returns:



13
14
15
# File 'lib/openweathermap/forecast.rb', line 13

def city
  @city
end

#forecastArray<OpenWeatherMap::WeatherConditions> (readonly)

Returns Forecast for many days and hours.

Returns:



18
19
20
# File 'lib/openweathermap/forecast.rb', line 18

def forecast
  @forecast
end