myweatherforecast 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af86dccf7ea42e5895c5507c83438800e40e7a52
4
- data.tar.gz: d7a8f68980b40d89cfdd3ee6fef3cc22ffffa368
3
+ metadata.gz: 76f62520a708432f5a5b3c2c9304b5efedc2972e
4
+ data.tar.gz: e760fc1785af1ad2649f94759413070d7ef5b8df
5
5
  SHA512:
6
- metadata.gz: 2e9e424e01d72a035fe73e5eeec4d56ab7f3dea40a33a634482c9d9c609002a8d92196564daba2d91bec5a35067ec66aa3eebe61c8f7ace0b03ea29853828640
7
- data.tar.gz: e446c90dfc272c3ffb487dddb9a886155ede21040d19ceaf15c0f1c442fc2bde40e238f06b2a0238127db78c2bd4ca616d1a7c7ec13857a20464cf5f9afdf60f
6
+ metadata.gz: e48099ceacb8f5c1ea1dfd19183be6773813042cb2608d6b49a3d1ba166c09aa70cecda2406194d4e043bb8ab542ba34f3c90d473144b3222e5fe0b83c6053d0
7
+ data.tar.gz: 86ce36fa0b4d34195eb00ea918d708b75d7a2210ecfdbd2e243e998839e885f1fef8b18f8736839c50f52df0c411667e68fd3129b5f6280a4c65a432bb7e864b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -2,9 +2,11 @@
2
2
 
3
3
  # file: myweatherforecast.rb
4
4
 
5
+ require 'json'
5
6
  require 'time'
6
7
  require 'geocoder'
7
8
  require 'forecast_io'
9
+ require 'open-uri'
8
10
 
9
11
 
10
12
 
@@ -13,18 +15,27 @@ require 'forecast_io'
13
15
 
14
16
  class MyWeatherForecast
15
17
 
16
- def initialize(*location, api_key: nil, units: :auto)
18
+ def initialize(*location, api_key: nil, units: :auto, timeout: 3)
17
19
 
18
20
  lat, lon = if location.length > 1 then
19
21
 
20
22
  location
21
23
 
22
- else
24
+ elsif location.any?
23
25
 
24
26
  results = Geocoder.search(location.first)
25
27
  return puts 'location not found' unless results.any?
26
28
  results[0].coordinates
27
29
 
30
+ else
31
+
32
+ h = JSON.parse open('http://jsonip.com/').read
33
+ Geocoder.configure(timeout: timeout)
34
+ results = Geocoder.search(h['ip'])
35
+ return puts 'could not determine location from IP address' unless \
36
+ results.any?
37
+ results[0].coordinates
38
+
28
39
  end
29
40
 
30
41
  ForecastIO.api_key = api_key
@@ -112,11 +123,42 @@ class MyWeatherForecast
112
123
  DaysAhead.new(@forecast, @tlabel, index: i)
113
124
  end
114
125
 
126
+ end
127
+
128
+ class OutlookDay < Day
129
+
130
+ def initialize(day, tlabel)
131
+ @x = day
132
+ @tlabel = tlabel
133
+ end
134
+
135
+ def at()
136
+ end
137
+
138
+ def to_s
139
+ "min: %d%s max: %d%s, %s" % [@x.tempmin, @tlabel, \
140
+ @x.tempmax, @tlabel, @x.summary]
141
+ end
142
+
143
+ def temperature()
144
+ end
145
+
146
+ def tempmin
147
+ "%s°" % @x.temperatureMin.round
148
+ end
149
+
150
+ def tempmax
151
+ "%s°" % @x.temperatureMax.round
152
+ end
153
+
154
+
115
155
  end
116
156
 
117
157
  def today()
118
158
  Day.new(@forecast, @tlabel)
119
159
  end
160
+
161
+ alias now today
120
162
 
121
163
  def tomorrow()
122
164
 
@@ -128,5 +170,38 @@ class MyWeatherForecast
128
170
  i += 1 until Time.at(@forecast['hourly']['data'][i]['time']).hour == 12
129
171
  DaysAhead.new(@forecast, @tlabel, index: i)
130
172
  end
173
+
174
+ def monday() day :monday end
175
+ def tuesday() day :tuesday end
176
+ def wednesday() day :wednesday end
177
+ def thursday() day :thursday end
178
+ def friday() day :friday end
179
+ def saturday() day :saturday end
180
+ def sunday() day :sunday end
181
+
182
+ alias sat saturday
183
+ alias sun sunday
184
+ alias mon monday
185
+ alias tue tuesday
186
+ alias wed wednesday
187
+ alias thu thursday
188
+ alias fri friday
189
+
190
+ private
191
+
192
+ def day(name)
193
+
194
+ name = (name.to_s + '?').to_sym
195
+ len = @forecast['hourly']['data'].length
196
+ i = 0
197
+ i += 1 until Time.at(@forecast['hourly']['data'][i]['time']).\
198
+ method(name).call or i >= len - 1
199
+ return DaysAhead.new(@forecast, @tlabel, index: i) unless i == len - 1
200
+
201
+ d = 0
202
+ d += 1 until Time.at(@forecast['daily']['data'][d].time).method(name).call
203
+ Time.at(@forecast['daily']['data'][d].time)
204
+ OutlookDay.new(@forecast['daily']['data'][d], @tlabel)
205
+ end
131
206
 
132
- end
207
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myweatherforecast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file