Module: Weather::Actions
- Included in:
- Weatheruby
- Defined in:
- lib/weather/actions.rb
Instance Method Summary collapse
-
#alerts(location) ⇒ Array<Hash<Symbol, String>>
Gets alert information for a location.
-
#complex_forecast(location) ⇒ Hash
Gets more complicated forecast information for the location.
-
#complex_forecast_10day(location) ⇒ Hash
Exactly the same as #complex_forecast, except that it gets the data for 10 days.
-
#conditions(location) ⇒ Hash<Symbol, Object>
Gets weather conditions for the location.
-
#hurricane_data ⇒ Hash<String, Hash<Symbol, String/Integer>>
Gets data for currently-happening storms around the world.
-
#moon_phase(location) ⇒ Hash<Symbol, Integer>
Gets the current moon phase of the location.
-
#record_high(location) ⇒ Hash<Symbol, Integer>
Gets the record high for the location.
-
#record_low(location) ⇒ Hash<Symbol, Integer>
Gets the record low for the location.
-
#simple_forecast(location) ⇒ Hash
Gets the basic forecast information for the location.
-
#simple_forecast_10day(location) ⇒ Hash
Exactly the same as #simple_forecast, except that it gets the data for 10 days.
-
#sun_info(location) ⇒ Hash<Symbol, Hash<Symbol, Integer>>
Gets sunrise and sunset information for the current day at the current location.
Instance Method Details
#alerts(location) ⇒ Array<Hash<Symbol, String>>
Gets alert information for a location.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/weather/actions.rb', line 15 def alerts(location) response = get('alerts', location) ret = [] count = 0 response['alerts'].each do |a| ret[count] = { type: a['type'], description: a['description'], date: Time.parse(a['date']), expires: Time.parse(a['expires']), message: a['message'] } count += 1 end ret end |
#complex_forecast(location) ⇒ Hash
Gets more complicated forecast information for the location. Only gets the forecast for the next three days.
230 231 232 233 234 |
# File 'lib/weather/actions.rb', line 230 def complex_forecast(location) response = get('forecast', location) parse_complex_forecast(response) end |
#complex_forecast_10day(location) ⇒ Hash
Exactly the same as #complex_forecast, except that it gets the data for 10 days.
248 249 250 251 252 |
# File 'lib/weather/actions.rb', line 248 def complex_forecast_10day(location) response = get('forecast10day', location) parse_complex_forecast(response) end |
#conditions(location) ⇒ Hash<Symbol, Object>
Gets weather conditions for the location.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/weather/actions.rb', line 95 def conditions(location) response = get('conditions', location) current_observation = response['current_observation'] display_location = current_observation['display_location'] ret = { full_name: display_location['full'], city_name: display_location['city'], state_abbreviation: display_location['state'], state_name: display_location['state_name'], country: display_location['country'], zip_code: display_location['zip'].to_i, updated: current_observation['observation_time'], weather: current_observation['weather'], formatted_temperature: current_observation['temperature_string'], temperature_f: current_observation['temp_f'], temperature_c: current_observation['temp_c'], humidity: current_observation['relative_humidity'], formatted_wind: current_observation['wind_string'], wind_direction: current_observation['wind_dir'], wind_degrees: current_observation['wind_degrees'], wind_speed: current_observation['wind_mph'], wind_gust_speed: current_observation['wind_gust_mph'].to_i, formatted_feelslike: current_observation['feelslike_string'], feelslike_f: current_observation['feelslike_f'].to_i, feelslike_c: current_observation['feelslike_c'].to_i } ret[:humidity] = ret[:humidity].sub('%', '').to_i ret end |
#hurricane_data ⇒ Hash<String, Hash<Symbol, String/Integer>>
Gets data for currently-happening storms around the world.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/weather/actions.rb', line 183 def hurricane_data begin response = get('currenthurricane', 'view') rescue Weatheruby::WeatherError => e # For some reason the API always errors with this when getting current hurricane data. fail e unless e..start_with?('querynotfound') response = e.full_response end p response ret = {} response['currenthurricane'].each do |h| ret[h['stormInfo']['stormName_Nice']] = { name: h['stormInfo']['stormName'], number: h['stormInfo']['stormNumber'], category: h['Current']['Category'], time: Time.parse(h['Current']['Time']['pretty']), wind_speed_mph: h['Current']['WindSpeed']['Mph'], wind_speed_kts: h['Current']['WindSpeed']['Kts'], wind_speed_kph: h['Current']['WindSpeed']['Kph'], gust_speed_mph: h['Current']['WindGust']['Mph'], gust_speed_kts: h['Current']['WindGust']['Kts'], gust_speed_kph: h['Current']['WindGust']['Kph'] } end ret end |
#moon_phase(location) ⇒ Hash<Symbol, Integer>
Gets the current moon phase of the location.
39 40 41 42 43 44 45 |
# File 'lib/weather/actions.rb', line 39 def moon_phase(location) response = get('astronomy', location) { age: response['moon_phase']['ageOfMoon'].to_i, illumination: response['moon_phase']['percentIlluminated'].to_i } end |
#record_high(location) ⇒ Hash<Symbol, Integer>
Gets the record high for the location.
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/weather/actions.rb', line 157 def record_high(location) response = get('almanac', location) { average_high_f: response['almanac']['temp_high']['normal']['F'].to_i, average_high_c: response['almanac']['temp_high']['normal']['C'].to_i, record_year: response['almanac']['temp_high']['recordyear'].to_i, record_high_f: response['almanac']['temp_high']['record']['F'].to_i, record_high_c: response['almanac']['temp_high']['record']['C'].to_i } end |
#record_low(location) ⇒ Hash<Symbol, Integer>
Gets the record low for the location.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/weather/actions.rb', line 137 def record_low(location) response = get('almanac', location) { average_low_f: response['almanac']['temp_low']['normal']['F'].to_i, average_low_c: response['almanac']['temp_low']['normal']['C'].to_i, record_year: response['almanac']['temp_low']['recordyear'].to_i, record_low_f: response['almanac']['temp_low']['record']['F'].to_i, record_low_c: response['almanac']['temp_low']['record']['C'].to_i } end |
#simple_forecast(location) ⇒ Hash
Gets the basic forecast information for the location. Only gets data
for the next 3 days.
219 220 221 222 223 |
# File 'lib/weather/actions.rb', line 219 def simple_forecast(location) response = get('forecast', location) parse_simple_forecast(response) end |
#simple_forecast_10day(location) ⇒ Hash
Exactly the same as #simple_forecast, except that it gets the data for 10 days.
239 240 241 242 243 |
# File 'lib/weather/actions.rb', line 239 def simple_forecast_10day(location) response = get('forecast10day', location) parse_simple_forecast(response) end |
#sun_info(location) ⇒ Hash<Symbol, Hash<Symbol, Integer>>
Gets sunrise and sunset information for the current day at the current location.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/weather/actions.rb', line 52 def sun_info(location) response = get('astronomy', location) { rise: { hour: response['moon_phase']['sunrise']['hour'].to_i, minute: response['moon_phase']['sunrise']['minute'].to_i }, set: { hour: response['moon_phase']['sunset']['hour'].to_i, minute: response['moon_phase']['sunset']['minute'].to_i } } end |