myweatherforecast 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/myweatherforecast.rb +27 -13
- metadata +21 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93c3e36f8033e7eabc0485df30f2c3c2dd71aee7
|
4
|
+
data.tar.gz: 80958f8cb9d2474d34688a966fd1e0c0d3626973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f55f4b2838c35cec9e250d302e66085c651f5264203c8ef54e472ecc3b0464c1365c78a73e7e80d3182710941bc789beac0eb93567167c1bf474b9ad7b169d95
|
7
|
+
data.tar.gz: 039dfc0543cd1e003e2a17dff23cf833fd2c5cc768ac1eea845bca6a32263de73a6959258d7703400dd1b7c084751f7b6aa774fc596dd7a5ea30259d2e963ec2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/myweatherforecast.rb
CHANGED
@@ -2,28 +2,40 @@
|
|
2
2
|
|
3
3
|
# file: myweatherforecast.rb
|
4
4
|
|
5
|
-
require 'forecast_io'
|
6
5
|
require 'time'
|
6
|
+
require 'geocoder'
|
7
|
+
require 'forecast_io'
|
8
|
+
|
9
|
+
|
7
10
|
|
8
11
|
# This gem is a wrapper of the forecast_io gem
|
9
12
|
# SI explained: https://en.wikipedia.org/wiki/SI_derived_unit
|
10
13
|
|
11
14
|
class MyWeatherForecast
|
12
15
|
|
13
|
-
def initialize(
|
16
|
+
def initialize(*location, api_key: nil, units: :auto)
|
17
|
+
|
18
|
+
lat, lon = if location.length > 1 then
|
19
|
+
|
20
|
+
location
|
21
|
+
|
22
|
+
else
|
23
|
+
|
24
|
+
results = Geocoder.search(location.first)
|
25
|
+
return puts 'location not found' unless results.any?
|
26
|
+
results[0].coordinates
|
27
|
+
|
28
|
+
end
|
14
29
|
|
15
30
|
ForecastIO.api_key = api_key
|
16
|
-
|
17
|
-
|
18
|
-
if si then
|
19
|
-
params = { units: 'si' }
|
20
|
-
@tlabel = '°C'
|
21
|
-
else
|
22
|
-
params = {}
|
23
|
-
@tlabel = '°F'
|
24
|
-
end
|
25
31
|
|
32
|
+
params = { units: units.to_s }
|
26
33
|
@forecast = ForecastIO.forecast(lat, lon, params: params)
|
34
|
+
|
35
|
+
autounits = @forecast['flags']['units']
|
36
|
+
|
37
|
+
@tlabel = autounits == 'us' ? '°F' : '°C'
|
38
|
+
|
27
39
|
end
|
28
40
|
|
29
41
|
class Day
|
@@ -100,9 +112,11 @@ class MyWeatherForecast
|
|
100
112
|
|
101
113
|
# select tomorrow at midday
|
102
114
|
i = 0
|
115
|
+
|
116
|
+
i += 7 if Time.at(@forecast['hourly']['data'][i]['time']).hour >= 6
|
117
|
+
|
103
118
|
i += 1 until Time.at(@forecast['hourly']['data'][i]['time']).hour == 12
|
104
119
|
DaysAhead.new(@forecast, @tlabel, index: i)
|
105
120
|
end
|
106
121
|
|
107
|
-
end
|
108
|
-
|
122
|
+
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -53,6 +53,26 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 2.0.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: geocoder
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.2'
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.2.11
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '1.2'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.11
|
56
76
|
description:
|
57
77
|
email: james@r0bertson.co.uk
|
58
78
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|