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.



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)



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

def clouds
  @clouds
end

#descriptionString (readonly)



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

def description
  @description
end

#emojiString (readonly)



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

def emoji
  @emoji
end

#humidityFloat (readonly)



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

def humidity
  @humidity
end

#iconString (readonly)



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

def icon
  @icon
end

#mainString (readonly)



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

def main
  @main
end

#pressureFloat (readonly)



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

def pressure
  @pressure
end

#rainHash? (readonly)

Can be nil if there is no rain



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

def rain
  @rain
end

#snowHash? (readonly)

Can be nil if there is no snow



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

def snow
  @snow
end

#temp_maxFloat (readonly)



110
111
112
# File 'lib/openweathermap/classes.rb', line 110

def temp_max
  @temp_max
end

#temp_minFloat (readonly)



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

def temp_min
  @temp_min
end

#temperatureFloat (readonly)



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

def temperature
  @temperature
end

#timeTime (readonly)



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

def time
  @time
end

#windHash (readonly)



127
128
129
# File 'lib/openweathermap/classes.rb', line 127

def wind
  @wind
end