weatheruby 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/lib/weather/actions.rb +161 -2
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4bc5408dc72cef114956f54043208d345fe2c91
4
- data.tar.gz: 48a16aefd779d173f68164dd9b342e746988e9a4
3
+ metadata.gz: 093f7d9f2737698be51c4686072424b28245aadc
4
+ data.tar.gz: 814d49c28ade652024e010a4d6230c0e37b765ab
5
5
  SHA512:
6
- metadata.gz: ee9e13401e525b4f375c1c720c502318aa46382b328f0b64729cef3a120542539212b43f47ffcee4a721d84defdfb7673642b24fcae206e1fa42dbbc8ad4ce32
7
- data.tar.gz: bbe710d088da26c738f6cb2a38ac902899fdbf2c06a3ace9570fa4c4a1b8a6560671d13e5196184956d5b2877259562c463c90039e6f83befd205d5ac6ea2ff6
6
+ metadata.gz: 61355f4a8b3691b51bf9b5a44ade57d1bd11b2c611fe0faae0db22ba521ff38c7815123684370a42cd3b8495ae8d65de5985935d5e6b56e21a09a64ad089eb90
7
+ data.tar.gz: d10b898728d47b70f35b337c85bef4f9eaa236e45a88491289ce10e8b726bb58dd1d9c69b1d67e914064398dbd00085c886cea249e1a15d63311bfc8f3ebc303
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
  # Changelog
2
2
  ## Version 0
3
+ ### Version 0.2.0
4
+ * New complex_forecast_10day and simple_forecast_20day.
5
+ * New complex_forecast and simple_forecast methods. It's funny, complex_forecast uses the simpleforecast stuff from the API.
6
+ * New hurricane_data method.
7
+ * New record_low and record_high methods.
8
+
3
9
  ### Version 0.1.0
4
10
  * Intial version. Includes #conditions, #moon_phase, and #alerts.
@@ -2,7 +2,7 @@ module Weather
2
2
  module Actions
3
3
  # Gets alert information for a location.
4
4
  # @param location [String] The place to get the alert data for.
5
- # @return [Hash/Nil] Nil if there are no alerts, or a hash of arrays
5
+ # @return [Hash/Nil] Nil if there are no alerts, or a hash of hashes
6
6
  # containing relevant data if not. Each array in the hash contains
7
7
  # information for a different alert.
8
8
  def alerts(location)
@@ -41,7 +41,7 @@ module Weather
41
41
  ret
42
42
  end
43
43
 
44
- # Gets weahter conditions for the location.
44
+ # Gets weather conditions for the location.
45
45
  # @param location [String] The place to get the weather report for.
46
46
  # @return [Hash] A hash containing strings of relevant weather information.
47
47
  def conditions(location)
@@ -77,5 +77,164 @@ module Weather
77
77
  ret
78
78
  end
79
79
 
80
+ # Gets the record low for the location.
81
+ # @param location [String] The place to get the record low for.
82
+ # @return [Hash] A hash containing a few integers of data.
83
+ def record_low(location)
84
+ response = get('almanac', location)
85
+
86
+ ret = {
87
+ :average_low_f => response['almanac']['temp_low']['normal']['F'].to_i,
88
+ :average_low_c => response['almanac']['temp_low']['normal']['C'].to_i,
89
+ :record_year => response['almanac']['temp_low']['recordyear'].to_i,
90
+ :record_low_f => response['almanac']['temp_low']['record']['F'].to_i,
91
+ :record_low_c => response['almanac']['temp_low']['record']['C'].to_i
92
+ }
93
+
94
+ ret
95
+ end
96
+
97
+ # Gets the record high for the location.
98
+ # @param location [String] The place to get the record high for.
99
+ # @return [Hash] A hash containing a few integers of data.
100
+ def record_high(location)
101
+ response = get('almanac', location)
102
+
103
+ ret = {
104
+ :average_high_f => response['almanac']['temp_high']['normal']['F'].to_i,
105
+ :average_high_c => response['almanac']['temp_high']['normal']['C'].to_i,
106
+ :record_year => response['almanac']['temp_high']['recordyear'].to_i,
107
+ :record_high_f => response['almanac']['temp_high']['record']['F'].to_i,
108
+ :record_high_c => response['almanac']['temp_high']['record']['C'].to_i
109
+ }
110
+
111
+ ret
112
+ end
113
+
114
+ # Gets data for currently-happening hurricanes around the world.
115
+ # @return [Hash] A hash containing hashes of data. Each sub-hash is named
116
+ # as the "nice" name for the hurricane (example: Hurricane Daniel).
117
+ def hurricane_data
118
+ response = get('currenthurricane', 'view')
119
+
120
+ ret = {}
121
+ response['currenthurricane'].each do |h|
122
+ ret[h['stormInfo']['stormName_Nice']] = {
123
+ :name => h['stormInfo']['stormName'],
124
+ :number => h['stormInfo']['stormNumber'],
125
+ :category => h['Current']['Category'],
126
+ :time => h['Current']['Time']['pretty'],
127
+ :wind_speed_mph => h['Current']['WindSpeed']['Mph'],
128
+ :wind_speed_kts => h['Current']['WindSpeed']['Kts'],
129
+ :wind_speed_kph => h['Current']['WindSpeed']['Kph'],
130
+ :gust_speed_mph => h['Current']['WindGust']['Mph'],
131
+ :gust_speed_kts => h['Current']['WindGust']['Kts'],
132
+ :gust_speed_kph => h['Current']['WindGust']['Kph'],
133
+ }
134
+ end
135
+
136
+ ret
137
+ end
138
+
139
+ # Gets the basic forecast information for the location.
140
+ # @param location [String] The place to get the forecast for.
141
+ # @return [Hash] A hash containing hashes of information. Sub-hashes are
142
+ # named as their "period", or the day in relation to the current day.
143
+ # For example: 0 is today, 1 is tomorrow, etc. It does not organize itself
144
+ # by weekday. That is what the weekday_name key is for.
145
+ def simple_forecast(location)
146
+ response = get('forecast', location)
147
+
148
+ return parse_simple_forecast(response)
149
+ end
150
+
151
+ # Gets more complicated forecast information for the location. Only gets
152
+ # the forecast for the next three days.
153
+ # @param location [String] The place to get the forecast for.
154
+ # @return [Hash] A hash containing hashes of information. Sub-hashes are
155
+ # named as their "period", or the day in relation to the current day.
156
+ # For example: 0 is today, 1 is tomorrow, etc. It does not organize itself
157
+ # by weekday. Unlike simple_forecast, you do not get very many strings in
158
+ # this method.
159
+ def complex_forecast(location)
160
+ response = get('forecast', location)
161
+
162
+ return parse_complex_forecast(response)
163
+ end
164
+
165
+ # Exactly the same as #simple_forecast, except that it gets the data for
166
+ # 20 days.
167
+ def simple_forecast_20day(location)
168
+ response = get('forecast10day', location)
169
+
170
+ return parse_simple_forecast(response)
171
+ end
172
+
173
+ # Exactly the same as #complex_forecast, except that it gets the data for
174
+ # 10 days.
175
+ def complex_forecast_10day(location)
176
+ response = get('forecast10day', location)
177
+
178
+ return parse_complex_forecast(response)
179
+ end
180
+
181
+ private
182
+ # Parses the simple forecast information.
183
+ def parse_simple_forecast(response)
184
+ ret = {}
185
+
186
+ response['forecast']['txt_forecast']['forecastday'].each do |f|
187
+ ret[f['period']] = {
188
+ :weekday_name => f['title'],
189
+ :text => f['fcttext'],
190
+ :text_metric => f['fcttext_metric']
191
+ }
192
+ end
193
+
194
+ ret
195
+ end
196
+
197
+ # Parses the complex forecast information.
198
+ def parse_complex_forecast(response)
199
+ ret = {}
200
+
201
+ response['forecast']['simpleforecast']['forecastday'].each do |f|
202
+ ret[f['period'] - 1] = {
203
+ :high_f => f['high']['fahrenheit'].to_i,
204
+ :high_c => f['high']['celsius'].to_i,
205
+ :low_f => f['low']['fahrenheit'].to_i,
206
+ :low_c => f['low']['celsius'].to_i,
207
+ :conditions => f['conditions'].to_i,
208
+ :snow => {
209
+ :snow_total_in => f['snow_allday']['in'],
210
+ :snow_total_cm => f['snow_allday']['cm'],
211
+ :snow_night_in => f['snow_night']['in'],
212
+ :snow_night_cm => f['snow_night']['cm'],
213
+ :snow_day_in => f['snow_day']['in'],
214
+ :snow_day_cm => f['snow_day']['cm']
215
+ },
216
+ :quantative_precipitation => {
217
+ :qpf_total_in => f['qpf_allday']['in'],
218
+ :qpf_total_cm => f['qpf_allday']['cm'],
219
+ :qpf_night_in => f['qpf_night']['in'],
220
+ :qpf_night_cm => f['qpf_night']['cm'],
221
+ :qpf_day_in => f['qpf_day']['in'],
222
+ :qpf_day_cm => f['qpf_day']['cm']
223
+ },
224
+ :wind => {
225
+ :average_mph => f['avewind']['mph'],
226
+ :average_kph => f['avewind']['kph'],
227
+ :average_dir => f['avewind']['dir'],
228
+ :average_temp => f['avewind']['degrees'],
229
+ :max_mph => f['maxwind']['mph'],
230
+ :max_kph => f['maxwind']['kph'],
231
+ :max_dir => f['maxwind']['dir'],
232
+ :max_temp => f['maxwind']['degrees']
233
+ }
234
+ }
235
+ end
236
+
237
+ ret
238
+ end
80
239
  end
81
240
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weatheruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster