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



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

#cloudsFloat (readonly)

Returns Clouds percentage.

Returns:

  • (Float)

    Clouds percentage



82
83
84
# File 'lib/openweathermap/classes.rb', line 82

def clouds
  @clouds
end

#descriptionString (readonly)

Returns Details of weather conditions.

Returns:

  • (String)

    Details of weather conditions



53
54
55
# File 'lib/openweathermap/classes.rb', line 53

def description
  @description
end

#emojiString (readonly)

Returns Conditions illustrated by an emoji.

Returns:

  • (String)

    Conditions illustrated by an emoji



59
60
61
# File 'lib/openweathermap/classes.rb', line 59

def emoji
  @emoji
end

#humidityFloat (readonly)

Returns Humidity percentage.

Returns:

  • (Float)

    Humidity percentage



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

def humidity
  @humidity
end

#iconString (readonly)

Returns URL to conditions icon illustration.

Returns:

  • (String)

    URL to conditions icon illustration



56
57
58
# File 'lib/openweathermap/classes.rb', line 56

def icon
  @icon
end

#mainString (readonly)

Returns Main weather contitions at the moment.

Returns:

  • (String)

    Main weather contitions at the moment



50
51
52
# File 'lib/openweathermap/classes.rb', line 50

def main
  @main
end

#pressureFloat (readonly)

Returns Atmospheric pressure in hPa.

Returns:

  • (Float)

    Atmospheric pressure in hPa



71
72
73
# File 'lib/openweathermap/classes.rb', line 71

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)



88
89
90
# File 'lib/openweathermap/classes.rb', line 88

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)



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

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)



68
69
70
# File 'lib/openweathermap/classes.rb', line 68

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)



65
66
67
# File 'lib/openweathermap/classes.rb', line 65

def temp_min
  @temp_min
end

#temperatureFloat (readonly)

Returns Temperature.

Returns:

  • (Float)

    Temperature



62
63
64
# File 'lib/openweathermap/classes.rb', line 62

def temperature
  @temperature
end

#timeTime (readonly)

Returns time of the condition.

Returns:

  • (Time)

    time of the condition



47
48
49
# File 'lib/openweathermap/classes.rb', line 47

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)



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

def wind
  @wind
end