module OpenWeather::Forecast

Public Instance Methods

forecast_raw(city) click to toggle source
# File lib/OpenWeather/forecast.rb, line 3
def forecast_raw(city)
  city.is_number? ?
      query = {id: city, units: @units_format, mode: @data_format} :
      query = {q: city, units: @units_format, mode: @data_format}
  @city_file.nil? ?
      get('/forecast', query: query) :
      JSON.parse(File.read(@city_file))
end
forecast_tomorrow_max(city) click to toggle source
# File lib/OpenWeather/forecast.rb, line 18
def forecast_tomorrow_max(city)
  forecast = forecast_raw(city)
  tomorrow_list = forecast['list'].select { |weather| weather['dt_txt'].split(" ")[0] == tomorrow  }
  tomorrow_list.max_by { |temp| temp['main']['temp_max'] }['main']['temp_max']
end
forecast_tomorrow_min(city) click to toggle source
# File lib/OpenWeather/forecast.rb, line 12
def forecast_tomorrow_min(city)
  forecast = forecast_raw(city)
  tomorrow_list = forecast['list'].select { |weather| weather['dt_txt'].split(" ")[0] == tomorrow  }
  tomorrow_list.min_by { |temp| temp['main']['temp_min'] }['main']['temp_min']
end
forecast_tomorrow_rain?(city) click to toggle source
# File lib/OpenWeather/forecast.rb, line 24
def forecast_tomorrow_rain?(city)
  forecast = forecast_raw(city)
  tomorrow_list = forecast['list'].select { |weather| weather['dt_txt'].split(" ")[0] == tomorrow  }
  # This selects any period of time during the day where the condition code is between 500 and 599 which
  # corresponds to rainy condition. If the array is empty that means it won't rain so we return the opposite.
  ! tomorrow_list.select { |code| Integer(code['weather'][0]['id']).between?(500, 599) }.empty?
end
forecast_tomorrow_sunny?(city) click to toggle source
# File lib/OpenWeather/forecast.rb, line 32
def forecast_tomorrow_sunny?(city)
  forecast = forecast_raw(city)
  tomorrow_list = forecast['list'].select { |weather| weather['dt_txt'].split(" ")[0] == tomorrow  }
  # This selects any period of time during the day where the condition code is between 500 and 599 which
  # corresponds to rainy condition. If the array is empty that means it won't rain so we return the opposite.
  ! tomorrow_list.select { |code| Integer(code['weather'][0]['id']).between?(800, 801) }.empty?
end