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 contitions 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.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/openweathermap/classes.rb', line 99 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'].sub('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.
82 83 84 |
# File 'lib/openweathermap/classes.rb', line 82 def clouds @clouds end |
#description ⇒ String (readonly)
Returns Details of weather conditions.
53 54 55 |
# File 'lib/openweathermap/classes.rb', line 53 def description @description end |
#emoji ⇒ String (readonly)
Returns Conditions illustrated by an emoji.
59 60 61 |
# File 'lib/openweathermap/classes.rb', line 59 def emoji @emoji end |
#humidity ⇒ Float (readonly)
Returns Humidity percentage.
74 75 76 |
# File 'lib/openweathermap/classes.rb', line 74 def humidity @humidity end |
#icon ⇒ String (readonly)
Returns URL to conditions icon illustration.
56 57 58 |
# File 'lib/openweathermap/classes.rb', line 56 def icon @icon end |
#main ⇒ String (readonly)
Returns Main weather contitions at the moment.
50 51 52 |
# File 'lib/openweathermap/classes.rb', line 50 def main @main end |
#pressure ⇒ Float (readonly)
Returns Atmospheric pressure in hPa.
71 72 73 |
# File 'lib/openweathermap/classes.rb', line 71 def pressure @pressure end |
#rain ⇒ Hash? (readonly)
Can be nil if there is no rain
88 89 90 |
# File 'lib/openweathermap/classes.rb', line 88 def rain @rain end |
#snow ⇒ Hash? (readonly)
Can be nil if there is no snow
94 95 96 |
# File 'lib/openweathermap/classes.rb', line 94 def snow @snow end |
#temp_max ⇒ Float (readonly)
Returns Maximum temperature at the moment (for large areas).
68 69 70 |
# File 'lib/openweathermap/classes.rb', line 68 def temp_max @temp_max end |
#temp_min ⇒ Float (readonly)
Returns Minimum temperature at the moment (for large areas).
65 66 67 |
# File 'lib/openweathermap/classes.rb', line 65 def temp_min @temp_min end |
#temperature ⇒ Float (readonly)
Returns Temperature.
62 63 64 |
# File 'lib/openweathermap/classes.rb', line 62 def temperature @temperature end |
#time ⇒ Time (readonly)
Returns time of the condition.
47 48 49 |
# File 'lib/openweathermap/classes.rb', line 47 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).
79 80 81 |
# File 'lib/openweathermap/classes.rb', line 79 def wind @wind end |