Class: OpenWeatherMap::Forecast
- Inherits:
-
Object
- Object
- OpenWeatherMap::Forecast
- Defined in:
- lib/openweathermap/forecast.rb
Overview
Represents the forecast for a specific location
Instance Attribute Summary collapse
-
#city ⇒ OpenWeatherMap::City
readonly
Requested city’s data.
-
#forecast ⇒ Array<OpenWeatherMap::WeatherConditions>
readonly
Forecast for many days and hours.
Instance Method Summary collapse
-
#initialize(data) ⇒ Forecast
constructor
Create a new Forecast object.
Constructor Details
#initialize(data) ⇒ Forecast
Create a new Forecast object
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
#city ⇒ OpenWeatherMap::City (readonly)
Returns Requested city’s data.
13 14 15 |
# File 'lib/openweathermap/forecast.rb', line 13 def city @city end |
#forecast ⇒ Array<OpenWeatherMap::WeatherConditions> (readonly)
Returns Forecast for many days and hours.
18 19 20 |
# File 'lib/openweathermap/forecast.rb', line 18 def forecast @forecast end |