Class: OpenWeatherMap::WeatherConditions
- Inherits:
-
Object
- Object
- OpenWeatherMap::WeatherConditions
- Defined in:
- lib/openweathermap/classes.rb
Overview
Represents the weather conditions
Instance Attribute Summary collapse
-
#clouds ⇒ Float
readonly
Clouds percentage.
-
#description ⇒ String
readonly
Details of weather conditions.
-
#emoji ⇒ String
readonly
Conditions illustrated by an emoji.
-
#humidity ⇒ Float
readonly
Humidity percentage.
-
#icon ⇒ String
readonly
URL to conditions icon illustration.
-
#main ⇒ String
readonly
Main weather conditions at the moment.
-
#pressure ⇒ Float
readonly
Atmospheric pressure in hPa.
-
#rain ⇒ Hash?
readonly
Can be nil if there is no rain.
-
#snow ⇒ Hash?
readonly
Can be nil if there is no snow.
-
#temp_max ⇒ Float
readonly
Maximum temperature at the moment (for large areas).
-
#temp_min ⇒ Float
readonly
Minimum temperature at the moment (for large areas).
-
#temperature ⇒ Float
readonly
Temperature.
-
#time ⇒ Time
readonly
Time of the condition.
-
#wind ⇒ Hash
readonly
Wind data.
Instance Method Summary collapse
-
#initialize(data) ⇒ WeatherConditions
constructor
Create a new WeatherConditions object.
Constructor Details
#initialize(data) ⇒ WeatherConditions
Create a new WeatherConditions object.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/openweathermap/classes.rb', line 155 def initialize(data) @time = Time.at(data['dt']) @main = data['weather'][0]['main'] @description = data['weather'][0]['description'] @icon = "https://openweathermap.org/img/w/#{data['weather'][0]['icon']}.png" @emoji = OpenWeatherMap::Constants::CONDITION_CODE[data['weather'][0]['icon'].tr('n', 'd')] @temperature = data['main']['temp'] @temp_min = data['main']['temp_min'].to_f @temp_max = data['main']['temp_max'].to_f @pressure = data['main']['pressure'].to_f @humidity = data['main']['humidity'].to_f @wind = { speed: data['wind']['speed'], direction: data['wind']['deg'] } @clouds = data['clouds']['all'].to_f @rain = data['rain'].nil? ? nil : { one_hour: data['rain']['1h'], three_hours: data['rain']['3h'] } @snow = data['snow'].nil? ? nil : { one_hour: data['snow']['1h'], three_hours: data['snow']['3h'] } end |
Instance Attribute Details
#clouds ⇒ Float (readonly)
Returns Clouds percentage.
132 133 134 |
# File 'lib/openweathermap/classes.rb', line 132 def clouds @clouds end |
#description ⇒ String (readonly)
Returns Details of weather conditions.
85 86 87 |
# File 'lib/openweathermap/classes.rb', line 85 def description @description end |
#emoji ⇒ String (readonly)
Returns Conditions illustrated by an emoji.
95 96 97 |
# File 'lib/openweathermap/classes.rb', line 95 def emoji @emoji end |
#humidity ⇒ Float (readonly)
Returns Humidity percentage.
120 121 122 |
# File 'lib/openweathermap/classes.rb', line 120 def humidity @humidity end |
#icon ⇒ String (readonly)
Returns URL to conditions icon illustration.
90 91 92 |
# File 'lib/openweathermap/classes.rb', line 90 def icon @icon end |
#main ⇒ String (readonly)
Returns Main weather conditions at the moment.
80 81 82 |
# File 'lib/openweathermap/classes.rb', line 80 def main @main end |
#pressure ⇒ Float (readonly)
Returns Atmospheric pressure in hPa.
115 116 117 |
# File 'lib/openweathermap/classes.rb', line 115 def pressure @pressure end |
#rain ⇒ Hash? (readonly)
Can be nil if there is no rain
140 141 142 |
# File 'lib/openweathermap/classes.rb', line 140 def rain @rain end |
#snow ⇒ Hash? (readonly)
Can be nil if there is no snow
148 149 150 |
# File 'lib/openweathermap/classes.rb', line 148 def snow @snow end |
#temp_max ⇒ Float (readonly)
Returns Maximum temperature at the moment (for large areas).
110 111 112 |
# File 'lib/openweathermap/classes.rb', line 110 def temp_max @temp_max end |
#temp_min ⇒ Float (readonly)
Returns Minimum temperature at the moment (for large areas).
105 106 107 |
# File 'lib/openweathermap/classes.rb', line 105 def temp_min @temp_min end |
#temperature ⇒ Float (readonly)
Returns Temperature.
100 101 102 |
# File 'lib/openweathermap/classes.rb', line 100 def temperature @temperature end |
#time ⇒ Time (readonly)
Returns time of the condition.
75 76 77 |
# File 'lib/openweathermap/classes.rb', line 75 def time @time end |
#wind ⇒ Hash (readonly)
Returns Wind data. Keys : (symbols)
-
speed : Wind speed (m/s or miles/hour)
-
direction : Wind direction (meteorological degrees).
127 128 129 |
# File 'lib/openweathermap/classes.rb', line 127 def wind @wind end |