Module: Weather::Planner

Included in:
Weatheruby
Defined in:
lib/weather/planner.rb

Instance Method Summary collapse

Instance Method Details

#chance_of_cloudy(start_date, end_date, location) ⇒ Integer

Gets the chance of cloudy conditions within the date range.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.



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.

Parameters:

  • subject (String)

    The chance_of hash’s key.

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Integer)

    The chance of the subject happening.

Since:

  • 0.5.0



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

TODO:

Raise an error instead of returning a String.

Gets the dewpoint highs and lows for the date range.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Hash<Symbol, Hash<Symbol, Hash<Symbol, Integer>>>)

    Highs and lows minimum, average, and maximum for both metric and imperial systems.

  • (String)

    The error if possible.



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.

Parameters:

  • start_date (DateTime)

    The date to start at. Only month and day actually matter.

  • end_date (DateTime)

    The date to end at. Only month and day actually matter.

  • location (String)

    The location to get the planner data for.

Returns:

  • (Hash)

    Parsed JSON response

Since:

  • 0.5.0



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

TODO:

Raise an error instead of returning a String.

Gets the precipitation amounts (not chance) for the date range.

Returns:

  • (Hash<Symbol, Hash<Symbol, Integer>>)

    Minimum, maximum, and average precipitation quantities for the location in both inches and centimeters.

  • (String)

    The error if possible.

See Also:



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.

Returns:

  • (Hash<Symbol, Hash<Symbol, Hash<Symbol, Integer>>>)

    Highs and lows minimum, average, and maximum for both metric and imperial systems.

See Also:



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