module WeatherJudge

Calculates score for 4 different weather aspects: sky cover, chance of rain, wind, and temperature

Constants

VERSION

Public Class Methods

run(latitude, longitude) click to toggle source

Retrieves WeatherData object for today's forecast given latitude and longitude.

# File lib/weather_judge.rb, line 12
def run(latitude, longitude)
  validate_coordinates(latitude, longitude)

  ForecastIO.api_key = WeatherJudge.forecast_io_api_key
  forecast = ForecastIO.forecast(latitude, longitude, params: { exclude: 'hourly,minutely,alerts,flags'})

  if forecast.nil?
    raise StandardError.new("Unable to obtain forecast! Check your network connectivity and API key")
  end

  @forecast_today = forecast.daily.data.first

  WeatherData.new(@forecast_today)
end

Private Class Methods

validate_coordinates(latitude, longitude) click to toggle source
# File lib/weather_judge.rb, line 29
def validate_coordinates(latitude, longitude)
  unless latitude >= -90 && latitude <= 90 && longitude >= -180 && longitude <= 180
    raise ArgumentError.new("Invalid coordinates!")
  end
end