Class: OpenWeatherMap::WeatherConditions

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

Overview

Represents the weather conditions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ WeatherConditions

Create a new WeatherConditions object.

Parameters:

  • data (Hash)

    all the received data



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

#cloudsFloat (readonly)

Returns Clouds percentage.

Returns:

  • (Float)

    Clouds percentage



132
133
134
# File 'lib/openweathermap/classes.rb', line 132

def clouds
  @clouds
end

#descriptionString (readonly)

Returns Details of weather conditions.

Returns:

  • (String)

    Details of weather conditions



85
86
87
# File 'lib/openweathermap/classes.rb', line 85

def description
  @description
end

#emojiString (readonly)

Returns Conditions illustrated by an emoji.

Returns:

  • (String)

    Conditions illustrated by an emoji



95
96
97
# File 'lib/openweathermap/classes.rb', line 95

def emoji
  @emoji
end

#humidityFloat (readonly)

Returns Humidity percentage.

Returns:

  • (Float)

    Humidity percentage



120
121
122
# File 'lib/openweathermap/classes.rb', line 120

def humidity
  @humidity
end

#iconString (readonly)

Returns URL to conditions icon illustration.

Returns:

  • (String)

    URL to conditions icon illustration



90
91
92
# File 'lib/openweathermap/classes.rb', line 90

def icon
  @icon
end

#mainString (readonly)

Returns Main weather conditions at the moment.

Returns:

  • (String)

    Main weather conditions at the moment



80
81
82
# File 'lib/openweathermap/classes.rb', line 80

def main
  @main
end

#pressureFloat (readonly)

Returns Atmospheric pressure in hPa.

Returns:

  • (Float)

    Atmospheric pressure in hPa



115
116
117
# File 'lib/openweathermap/classes.rb', line 115

def pressure
  @pressure
end

#rainHash? (readonly)

Can be nil if there is no rain

Returns:

  • (Hash, nil)

    Rain volume. Keys : (symbols)

    • one_hour : Rain volume for the last 1 hour (mm)

    • three_hours : Rain volume for the last 3 hours (mm)



140
141
142
# File 'lib/openweathermap/classes.rb', line 140

def rain
  @rain
end

#snowHash? (readonly)

Can be nil if there is no snow

Returns:

  • (Hash, nil)

    Snow volume. Keys : (symbols)

    • one_hour : Snow volume for the last 1 hour (mm)

    • three_hours : Snow volume for the last 3 hours (mm)



148
149
150
# File 'lib/openweathermap/classes.rb', line 148

def snow
  @snow
end

#temp_maxFloat (readonly)

Returns Maximum temperature at the moment (for large areas).

Returns:

  • (Float)

    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_minFloat (readonly)

Returns Minimum temperature at the moment (for large areas).

Returns:

  • (Float)

    Minimum temperature at the moment (for large areas)



105
106
107
# File 'lib/openweathermap/classes.rb', line 105

def temp_min
  @temp_min
end

#temperatureFloat (readonly)

Returns Temperature.

Returns:

  • (Float)

    Temperature



100
101
102
# File 'lib/openweathermap/classes.rb', line 100

def temperature
  @temperature
end

#timeTime (readonly)

Returns time of the condition.

Returns:

  • (Time)

    time of the condition



75
76
77
# File 'lib/openweathermap/classes.rb', line 75

def time
  @time
end

#windHash (readonly)

Returns Wind data. Keys : (symbols)

  • speed : Wind speed (m/s or miles/hour)

  • direction : Wind direction (meteorological degrees).

Returns:

  • (Hash)

    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