class OpenWeatherLite::WeatherResponse

Wrapper class to hold the json response from api endpoint

includes methods that interact on the response

Attributes

weather[RW]

Public Class Methods

new(weather) click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 7
def initialize(weather)
  @weather = JSON.parse(weather, symbolize_names: true)
end

Public Instance Methods

clouds() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 42
def clouds
  return 0 if weather[:clouds].nil?
  weather[:clouds][:all]
end
cloudy?() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 38
def cloudy?
  !weather[:clouds].nil? && weather[:clouds][:all] > 0
end
coords() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 11
def coords
  {
    latitude: weather[:coord][:lat],
    longitude: weather[:coord][:lon]
  }
end
humidity() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 26
def humidity
  weather[:main][:humidity]
end
pressure() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 22
def pressure
  weather[:main][:pressure]
end
rain() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 51
def rain
  return 0 unless rainy?
  weather[:rain][:'3h']
end
rainy?() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 47
def rainy?
  !weather[:rain].nil? && weather[:rain][:'3h'] > 0
end
snow() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 60
def snow
  return 0 unless snowy?
  weather[:snow][:'3h']
end
snowy?() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 56
def snowy?
  !weather[:snow].nil? && weather[:snow][:'3h'] > 0
end
sunrise() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 65
def sunrise
  weather[:sys][:sunrise]
end
sunset() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 69
def sunset
  weather[:sys][:sunset]
end
temperature() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 18
def temperature
  weather[:main][:temp]
end
temperature_range() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 30
def temperature_range
  [weather[:main][:temp_min], weather[:main][:temp_max]]
end
wind() click to toggle source
# File lib/open_weather_lite/weather_response.rb, line 34
def wind
  weather[:wind]
end