Will It Rain?

"Will It Rain?" uses forecast_io to determine whether or not it will rain (precipitate, more specifically) at a particular location today. This gem was created primarily to isolate logic from a larger project. I hope it helps you in your weather-related Ruby application.

How does it work?

Different data points are collected from the current day. For each data point, the probability of precipitation is considered. If any data point exceeds the threshold, it is considered a "rain day."


Add the following to your Gemfile and install:

gem 'will_it_rain'

You will first need to signup on forecast.io and get an API key. You can set the key as a FORECAST_IO_API_KEY environment variable; alternatively you can set the API key in the following way:

require 'forecast_io'
ForecastIO.api_key = your_api_key


Find out if there is a chance of rain today:

WillItRain.at_location?(latitude, longitude) # returns boolean

The above checks for rain-chances greater than 10% by default. Here is how you can check if chance of rain today is greater than 25%:

WillItRain.at_location?(latitude, longitude, 25)

Get likelihood of precipitation along with percentage:

WillItRain.with_chances(latitude, longitude) # returns {it_will_rain: boolean, chances: percentage_string}
WillItRain.with_chances(latitude, longitude, 5) # compare with a value other than 10%

Get readable summaries of daily data points where precipitation probability exceeds 10%:

WillItRain.get_summaries(latitude, longitude) # returns array of readable summaries
WillItRain.get_summaries(latitude, longitude, 25) # adjust default threshold