Module: Weather::Planner
- Included in:
- Weatheruby
- Defined in:
- lib/weather/planner.rb
Instance Method Summary collapse
-
#chance_of_cloudy(start_date, end_date, location) ⇒ Integer
Gets the chance of cloudy conditions within the date range.
-
#chance_of_fog(start_date, end_date, location) ⇒ Integer
Gets the chance of fog within the date range.
-
#chance_of_freezing(start_date, end_date, location) ⇒ Integer
Gets the chance of temperatures below 0 C/32 F within the date range.
-
#chance_of_groundsnow(start_date, end_date, location) ⇒ Integer
Gets the chance of snow on the ground within the date range.
-
#chance_of_hail(start_date, end_date, location) ⇒ Integer
Gets the chance of hail within the date range.
-
#chance_of_heat(start_date, end_date, location) ⇒ Integer
Gets the chance of temperatures above 32.2 C/90 F within the date range.
-
#chance_of_high_wind(start_date, end_date, location) ⇒ Integer
Gets the chance of high winds within the date range.
-
#chance_of_humid(start_date, end_date, location) ⇒ Integer
Gets the chance of humidity within the date range.
-
#chance_of_not_freezing(start_date, end_date, location) ⇒ Integer
Gets the chance of temperatures above 0 C/32 F within the date range.
-
#chance_of_partlycloudy(start_date, end_date, location) ⇒ Integer
Gets the chance of partially cloudy conditions within the date range.
-
#chance_of_precipitation(start_date, end_date, location) ⇒ Integer
Gets the chance of precipitation within the date range.
-
#chance_of_rain(start_date, end_date, location) ⇒ Integer
Gets the chance of rain within the date range.
-
#chance_of_snow(start_date, end_date, location) ⇒ Integer
Gets the chance of snow within the date range.
-
#chance_of_sultry(start_date, end_date, location) ⇒ Integer
Gets chance of sultry within the date range.
-
#chance_of_sunny(start_date, end_date, location) ⇒ Integer
Gets the chance of sunshine within the date range.
-
#chance_of_thunderstorms(start_date, end_date, location) ⇒ Integer
Gets the chance of thunderstorms within the date range.
-
#chance_of_tornado(start_date, end_date, location) ⇒ Integer
Gets the chance of a tornado within the date range.
-
#chance_of_warmth(start_date, end_date, location) ⇒ Integer
Gets the chance of a temperature of 15.5 C/60 F within the date range.
-
#get_chance_of(subject, start_date, end_date, location) ⇒ Integer
private
Gets the chance of any given string key in the chance_of hash returned by #get_planner_response.
-
#get_dewpoints(start_date, end_date, location) ⇒ Hash<Symbol, Hash<Symbol, Hash<Symbol, Integer>>>, String
Gets the dewpoint highs and lows for the date range.
-
#get_planner_response(start_date, end_date, location) ⇒ Hash
private
Gets the full planner API response.
-
#get_precipitation(start_date, end_date, location) ⇒ Hash<Symbol, Hash<Symbol, Integer>>, String
Gets the precipitation amounts (not chance) for the date range.
-
#get_temperatures(start_date, end_date, location) ⇒ Hash<Symbol, Hash<Symbol, Hash<Symbol, Integer>>>
Gets the highs and lows for the date range.
Instance Method Details
#chance_of_cloudy(start_date, end_date, location) ⇒ Integer
Gets the chance of cloudy conditions within the date range.
97 98 99 |
# File 'lib/weather/planner.rb', line 97 def chance_of_cloudy(start_date, end_date, location) get_chance_of('chanceofcloudyday', start_date, end_date, location) end |
#chance_of_fog(start_date, end_date, location) ⇒ Integer
Gets the chance of fog within the date range.
90 91 92 |
# File 'lib/weather/planner.rb', line 90 def chance_of_fog(start_date, end_date, location) get_chance_of('chanceoffogday', start_date, end_date, location) end |
#chance_of_freezing(start_date, end_date, location) ⇒ Integer
Gets the chance of temperatures below 0 C/32 F within the date range.
27 28 29 |
# File 'lib/weather/planner.rb', line 27 def chance_of_freezing(start_date, end_date, location) get_chance_of('tempbelowfreezing', start_date, end_date, location) end |
#chance_of_groundsnow(start_date, end_date, location) ⇒ Integer
Gets the chance of snow on the ground within the date range.
48 49 50 |
# File 'lib/weather/planner.rb', line 48 def chance_of_groundsnow(start_date, end_date, location) get_chance_of('chanceofsnowonground', start_date, end_date, location) end |
#chance_of_hail(start_date, end_date, location) ⇒ Integer
Gets the chance of hail within the date range.
13 14 15 |
# File 'lib/weather/planner.rb', line 13 def chance_of_hail(start_date, end_date, location) get_chance_of('chanceofhailday', start_date, end_date, location) end |
#chance_of_heat(start_date, end_date, location) ⇒ Integer
Gets the chance of temperatures above 32.2 C/90 F within the date range.
62 63 64 |
# File 'lib/weather/planner.rb', line 62 def chance_of_heat(start_date, end_date, location) get_chance_of('tempoverninety', start_date, end_date, location) end |
#chance_of_high_wind(start_date, end_date, location) ⇒ Integer
Gets the chance of high winds within the date range.
118 119 120 |
# File 'lib/weather/planner.rb', line 118 def chance_of_high_wind(start_date, end_date, location) get_chance_of('chanceofwindyday', start_date, end_date, location) end |
#chance_of_humid(start_date, end_date, location) ⇒ Integer
Gets the chance of humidity within the date range.
83 84 85 |
# File 'lib/weather/planner.rb', line 83 def chance_of_humid(start_date, end_date, location) get_chance_of('chanceofhumidday', start_date, end_date, location) end |
#chance_of_not_freezing(start_date, end_date, location) ⇒ Integer
Gets the chance of temperatures above 0 C/32 F within the date range.
20 21 22 |
# File 'lib/weather/planner.rb', line 20 def chance_of_not_freezing(start_date, end_date, location) get_chance_of('tempoverfreezing', start_date, end_date, location) end |
#chance_of_partlycloudy(start_date, end_date, location) ⇒ Integer
Gets the chance of partially cloudy conditions within the date range.
111 112 113 |
# File 'lib/weather/planner.rb', line 111 def chance_of_partlycloudy(start_date, end_date, location) get_chance_of('chanceofpartlycloudyday', start_date, end_date, location) end |
#chance_of_precipitation(start_date, end_date, location) ⇒ Integer
Gets the chance of precipitation within the date range.
76 77 78 |
# File 'lib/weather/planner.rb', line 76 def chance_of_precipitation(start_date, end_date, location) get_chance_of('chanceofprecip', start_date, end_date, location) end |
#chance_of_rain(start_date, end_date, location) ⇒ Integer
Gets the chance of rain within the date range.
69 70 71 |
# File 'lib/weather/planner.rb', line 69 def chance_of_rain(start_date, end_date, location) get_chance_of('chanceofrainday', start_date, end_date, location) end |
#chance_of_snow(start_date, end_date, location) ⇒ Integer
Gets the chance of snow within the date range.
6 7 8 |
# File 'lib/weather/planner.rb', line 6 def chance_of_snow(start_date, end_date, location) get_chance_of('chanceofsnowday', start_date, end_date, location) end |
#chance_of_sultry(start_date, end_date, location) ⇒ Integer
Gets chance of sultry within the date range.
34 35 36 |
# File 'lib/weather/planner.rb', line 34 def chance_of_sultry(start_date, end_date, location) get_chance_of('chanceofsultryday', start_date, end_date, location) end |
#chance_of_sunny(start_date, end_date, location) ⇒ Integer
Gets the chance of sunshine within the date range.
104 105 106 |
# File 'lib/weather/planner.rb', line 104 def chance_of_sunny(start_date, end_date, location) get_chance_of('chanceofsunnycloudyday', start_date, end_date, location) end |
#chance_of_thunderstorms(start_date, end_date, location) ⇒ Integer
Gets the chance of thunderstorms within the date range.
55 56 57 |
# File 'lib/weather/planner.rb', line 55 def chance_of_thunderstorms(start_date, end_date, location) get_chance_of('chanceofthunderday', start_date, end_date, location) end |
#chance_of_tornado(start_date, end_date, location) ⇒ Integer
Gets the chance of a tornado within the date range.
41 42 43 |
# File 'lib/weather/planner.rb', line 41 def chance_of_tornado(start_date, end_date, location) get_chance_of('chanceoftornadoday', start_date, end_date, location) end |
#chance_of_warmth(start_date, end_date, location) ⇒ Integer
Gets the chance of a temperature of 15.5 C/60 F within the date range.
125 126 127 |
# File 'lib/weather/planner.rb', line 125 def chance_of_warmth(start_date, end_date, location) get_chance_of('tempoversixty', start_date, end_date, location) end |
#get_chance_of(subject, start_date, end_date, location) ⇒ Integer (private)
Gets the chance of any given string key in the chance_of hash returned by #get_planner_response.
255 256 257 258 259 |
# File 'lib/weather/planner.rb', line 255 def get_chance_of(subject, start_date, end_date, location) response = get_planner_response(start_date, end_date, location) response['trip']['chance_of'][subject]['percentage'].to_i end |
#get_dewpoints(start_date, end_date, location) ⇒ Hash<Symbol, Hash<Symbol, Hash<Symbol, Integer>>>, String
Raise an error instead of returning a String.
Gets the dewpoint highs and lows for the date range.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/weather/planner.rb', line 135 def get_dewpoints(start_date, end_date, location) response = get_planner_response(start_date, end_date, location) return response['response']['error'] unless response['response']['error'].nil? highs = response['trip']['dewpoint_high'] lows = response['trip']['dewpoint_low'] { high: { imperial: { minimum: highs['min']['F'].to_i, maximum: highs['max']['F'].to_i, average: highs['avg']['F'].to_i }, metric: { minimum: highs['min']['C'].to_i, maximum: highs['max']['C'].to_i, average: highs['avg']['C'].to_i } }, low: { imperial: { minimum: lows['min']['F'].to_i, maximum: lows['max']['F'].to_i, average: lows['avg']['F'].to_i }, metric: { minimum: lows['min']['C'].to_i, maximum: lows['max']['C'].to_i, average: lows['avg']['C'].to_i } } } end |
#get_planner_response(start_date, end_date, location) ⇒ Hash (private)
Gets the full planner API response.
244 245 246 247 248 |
# File 'lib/weather/planner.rb', line 244 def get_planner_response(start_date, end_date, location) start = start_date.strftime('%m%d') final = end_date.strftime('%m%d') get("planner_#{start}#{final}", location) end |
#get_precipitation(start_date, end_date, location) ⇒ Hash<Symbol, Hash<Symbol, Integer>>, String
Raise an error instead of returning a String.
Gets the precipitation amounts (not chance) for the date range.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/weather/planner.rb', line 175 def get_precipitation(start_date, end_date, location) response = get_planner_response(start_date, end_date, location) return response['response']['error'] unless response['response']['error'].nil? min = response['trip']['precip']['min'] avg = response['trip']['precip']['avg'] max = response['trip']['precip']['max'] { minimum: { inch: min['in'].to_i, centimeter: min['cm'].to_i }, maximum: { inch: max['in'].to_i, centimeter: max['cm'].to_i }, average: { inch: avg['in'].to_i, centimeter: avg['cm'].to_i } } end |
#get_temperatures(start_date, end_date, location) ⇒ Hash<Symbol, Hash<Symbol, Hash<Symbol, Integer>>>
Gets the highs and lows for the date range.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/weather/planner.rb', line 203 def get_temperatures(start_date, end_date, location) response = get_planner_response(start_date, end_date, location) highs = response['trip']['temp_high'] lows = response['trip']['temp_low'] { high: { imperial: { minimum: highs['min']['F'].to_i, maximum: highs['max']['F'].to_i, average: highs['avg']['F'].to_i }, metric: { minimum: highs['min']['C'].to_i, maximum: highs['max']['C'].to_i, average: highs['avg']['C'].to_i } }, low: { imperial: { minimum: lows['min']['F'].to_i, maximum: lows['max']['F'].to_i, average: lows['avg']['F'].to_i }, metric: { minimum: lows['min']['C'].to_i, maximum: lows['max']['C'].to_i, average: lows['avg']['C'].to_i } } } end |