darksky-api 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a0d324adb3f3ca70e81b924293c2ddfe13074c2f9678d4ca02dbfcc9fa505f2
4
- data.tar.gz: 9a6a530b42eb6b4f5a296f18e921911803399d494d796e2a01a0c47b79670d59
3
+ metadata.gz: e6d016e9642f5018a07312d3caa96e4d49f43a63a8de2415b9a5aa2128cbf9f2
4
+ data.tar.gz: d68c72019164491f10fc8a708e57c6700003a59eabedeb1d51eae01ca66b82ca
5
5
  SHA512:
6
- metadata.gz: e83781a530fd0aec046da02ea3ba14a7161c9048861d9a9729a1e3c74f9a8520f1aa7a6a8b7997e79f1e10fc1954b4a66ce75725da814a75f4599f3e98a50e2c
7
- data.tar.gz: 1fb64f1a6fa35ce39c5f51fc9fbd0effeb6272e9270d9faed379922ab8d3aa788e0afc49a079503c7d63c6404e9f62a9cf597a0652cc03c6234b31104a03e80c
6
+ metadata.gz: 8461aaf0495eb088df3c6af3b5ef36bb9052cd7218a64045dcc741f7d4f8eb432bf943efeb5d1384fbeebfdfd366e32ac1338720f06907bd4986ccefefdb83a1
7
+ data.tar.gz: bf40943663be48d5bd9af37ac90d11cbcf0e99c60e72d53cb996c1f1b90b72e1635551ea961c4c972b553033c156a3f43b9f4cac39e781079ab6e1d51f952fb1
@@ -22,3 +22,9 @@ Metrics/LineLength:
22
22
 
23
23
  Metrics/ClassLength:
24
24
  Max: 200
25
+
26
+ Metrics/PerceivedComplexity:
27
+ Max: 15
28
+
29
+ Metrics/CyclomaticComplexity:
30
+ Max: 15
data/Gemfile CHANGED
@@ -4,7 +4,3 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in darksky_api.gemspec
6
6
  gemspec
7
-
8
- # dependencies
9
- gem 'json', '~> 2.1'
10
- gem 'rest-client', '~> 2.0'
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- darksky-api (0.1.1)
4
+ darksky-api (0.1.4)
5
5
  json (~> 2.1)
6
6
  rest-client (~> 2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ ast (2.3.0)
12
+ docile (1.1.5)
11
13
  domain_name (0.5.20170404)
12
14
  unf (>= 0.0.5, < 1.0.0)
13
15
  http-cookie (1.0.3)
@@ -18,14 +20,33 @@ GEM
18
20
  mime-types-data (3.2016.0521)
19
21
  minitest (5.10.3)
20
22
  netrc (0.11.0)
23
+ parallel (1.12.1)
24
+ parser (2.4.0.2)
25
+ ast (~> 2.3)
26
+ powerpack (0.1.1)
27
+ rainbow (3.0.0)
21
28
  rake (10.5.0)
22
29
  rest-client (2.0.2)
23
30
  http-cookie (>= 1.0.2, < 2.0)
24
31
  mime-types (>= 1.16, < 4.0)
25
32
  netrc (~> 0.8)
33
+ rubocop (0.52.1)
34
+ parallel (~> 1.10)
35
+ parser (>= 2.4.0.2, < 3.0)
36
+ powerpack (~> 0.1)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (~> 1.0, >= 1.0.1)
40
+ ruby-progressbar (1.9.0)
41
+ simplecov (0.15.1)
42
+ docile (~> 1.1.0)
43
+ json (>= 1.8, < 3)
44
+ simplecov-html (~> 0.10.0)
45
+ simplecov-html (0.10.2)
26
46
  unf (0.1.4)
27
47
  unf_ext
28
48
  unf_ext (0.0.7.4)
49
+ unicode-display_width (1.3.0)
29
50
 
30
51
  PLATFORMS
31
52
  ruby
@@ -33,10 +54,10 @@ PLATFORMS
33
54
  DEPENDENCIES
34
55
  bundler (~> 1.16)
35
56
  darksky-api!
36
- json (~> 2.1)
37
57
  minitest (~> 5.0)
38
58
  rake (~> 10.0)
39
- rest-client (~> 2.0)
59
+ rubocop (~> 0.52)
60
+ simplecov (~> 0.15)
40
61
 
41
62
  BUNDLED WITH
42
63
  1.16.0
@@ -25,4 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 1.16'
26
26
  spec.add_development_dependency 'minitest', '~> 5.0'
27
27
  spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.52'
29
+ spec.add_development_dependency 'simplecov', '~> 0.15'
28
30
  end
@@ -1,6 +1,7 @@
1
1
  require 'darksky-api/version'
2
2
  require 'darksky-api/config'
3
3
  require 'darksky-api/location'
4
+ require 'darksky-api/common-methods'
4
5
  require 'darksky-api/current'
5
6
  require 'darksky-api/day'
6
7
 
@@ -0,0 +1,261 @@
1
+ module DarkSky
2
+ class CommonMethods
3
+ # abstract class, should not be instantiated
4
+ # @raise NotImplementedError
5
+ def initialize
6
+ raise NotImplementedError,
7
+ 'This is an abstract class, and should be be instantiated'
8
+ end
9
+
10
+ # @example
11
+ # location = DarkSky::Location.new [45, -90]
12
+ # location.current.apparent_temperature #=> apparent temperature at location
13
+ # @since 0.1.4
14
+ # @return [Numeric] current apparent temperature at location
15
+ def apparent_temperature
16
+ data[:apparentTemperature]
17
+ end
18
+ alias wind_chill apparent_temperature
19
+ alias heat_index apparent_temperature
20
+ alias feels_like apparent_temperature
21
+
22
+ # @example
23
+ # location = DarkSky::Location.new [45, -90]
24
+ # location.current.cloud_cover #=> cloud cover at location
25
+ # @since 0.1.4
26
+ # @return [Numeric] current cloud cover at location
27
+ def cloud_cover
28
+ data[:cloudCover]
29
+ end
30
+
31
+ # @example
32
+ # location = DarkSky::Location.new [45, -90]
33
+ # location.current.dew_point #=> dew point at location
34
+ # @since 0.1.4
35
+ # @return [Numeric] current dew point at location
36
+ def dew_point
37
+ data[:dewPoint]
38
+ end
39
+
40
+ # @example
41
+ # location = DarkSky::Location.new [45, -90]
42
+ # location.current.humidity #=> humidity at location
43
+ # @since 0.1.4
44
+ # @return [Numeric] current humidity at location
45
+ def humidity
46
+ data[:humidity]
47
+ end
48
+
49
+ # @example
50
+ # location = DarkSky::Location.new [45, -90]
51
+ # location.current.icon #=> icon representation
52
+ # @since 0.1.4
53
+ # @return [String] icon representation of current weather at location
54
+ def icon
55
+ data[:icon]
56
+ end
57
+
58
+ # @example
59
+ # location = DarkSky::Location.new [45, -90]
60
+ # location.current.ozone #=> ozone level at location
61
+ # @since 0.1.4
62
+ # @return [Numeric] current ozone level at location
63
+ def ozone
64
+ data[:ozone]
65
+ end
66
+
67
+ # @example
68
+ # location = DarkSky::Location.new [45, -90]
69
+ # location.current.precip_intensity #=> precipitation intensity at location
70
+ # @since 0.1.4
71
+ # @return [Numeric] current precipitation intensity at location
72
+ def precip_intensity
73
+ data[:precipIntensity]
74
+ end
75
+
76
+ # @example
77
+ # location = DarkSky::Locaiton.new [45, -90]
78
+ # location.current.precip_intensity_text #=> text representation of precipitation intensity at location
79
+ # @since 0.1.4
80
+ # @return [String] text representation of precipitation intensity at location
81
+ def precip_intensity_text
82
+ _precip_intensity_text(precip_intensity)
83
+ end
84
+
85
+ # @example
86
+ # location = DarkSky::Location.new [45, -90]
87
+ # location.current.precip_probability #=> precipitation probability at location
88
+ # @since 0.1.4
89
+ # @return [Numeric] current precipitation probability at location
90
+ def precip_probability
91
+ data[:precipProbability]
92
+ end
93
+
94
+ # @example
95
+ # location = DarkSky::Location.new [45, -90]
96
+ # location.current.precip_type #=> precipitation type at location
97
+ # @since 0.1.4
98
+ # @return [String | nil] current precipitation type at location
99
+ def precip_type
100
+ data[:precipType]
101
+ end
102
+
103
+ # @example
104
+ # location = DarkSky::Location.new [45, -90]
105
+ # location.current.pressure #=> barometric pressure at location
106
+ # @since 0.1.4
107
+ # @return [Numeric] current barometric pressure at location
108
+ def pressure
109
+ data[:pressure]
110
+ end
111
+
112
+ # @example
113
+ # location = DarkSky::Location.new [45, -90]
114
+ # location.current.summary #=> summary of weather at location
115
+ # @since 0.1.4
116
+ # @return [String] summary of weather at location
117
+ def summary
118
+ data[:summary]
119
+ end
120
+
121
+ # @example
122
+ # location = DarkSky::Location.new [45, -90]
123
+ # location.current.uv_index #=> UV index at location
124
+ # @since 0.1.4
125
+ # @return [Numeric] current UV index at location
126
+ def uv_index
127
+ data[:uvIndex]
128
+ end
129
+
130
+ # @example
131
+ # location = DarkSky::Location.new [45, -90]
132
+ # location.current.visibility #=> visibility at location
133
+ # @since 0.1.4
134
+ # @return [Numeric] current visibility at location
135
+ def visibility
136
+ data[:visibility]
137
+ end
138
+
139
+ # @example
140
+ # location = DarkSky::Location.new [45, -90]
141
+ # location.current.wind_bearing #=> wind bearing at location
142
+ # @since 0.1.4
143
+ # @return [Numeric] current wind bearing at location
144
+ def wind_bearing
145
+ data[:windBearing]
146
+ end
147
+
148
+ # @example
149
+ # location = DarkSky::Location.new [45, -90]
150
+ # location.current.wind_bearing_text #=> text representation of bearing (N, NW, etc.)
151
+ # @since 0.1.4
152
+ # @return [String] text representation of bearing
153
+ def wind_bearing_text
154
+ _bearing_text(wind_bearing)
155
+ end
156
+
157
+ # @example
158
+ # location = DarkSky::Location.new [45, -90]
159
+ # location.current.wind_gust #=> wind gust at location
160
+ # @since 0.1.4
161
+ # @return [Numeric] current wind gust at location
162
+ def wind_gust
163
+ data[:windGust]
164
+ end
165
+
166
+ # @example
167
+ # location = DarkSky::Location.new [45, -90]
168
+ # location.current.wind_speed #=> wind speed at location
169
+ # @since 0.1.4
170
+ # @return [Numeric] current wind speed at location
171
+ def wind_speed
172
+ data[:windSpeed]
173
+ end
174
+
175
+ # @example
176
+ # location = DarkSky::Location.new [45, -90]
177
+ # location.current.clear?
178
+ # @since 0.1.0
179
+ # @return [Boolean] if icon is 'clear' variant
180
+ def clear?
181
+ %w[clear-day clear-night].include? icon
182
+ end
183
+
184
+ # @example
185
+ # location = DarkSky::Location.new [45, -90]
186
+ # location.current.rainy?
187
+ # @since 0.1.0
188
+ # @return [Boolean] if icon is 'rain'
189
+ def rainy?
190
+ icon == 'rain'
191
+ end
192
+
193
+ # @example
194
+ # location = DarkSky::Location.new [45, -90]
195
+ # location.current.snowy?
196
+ # @since 0.1.0
197
+ # @return [Boolean] if icon is 'snow'
198
+ def snowy?
199
+ icon == 'snow'
200
+ end
201
+
202
+ # @example
203
+ # location = DarkSky::Location.new [45, -90]
204
+ # location.current.sleet?
205
+ # @since 0.1.0
206
+ # @return [Boolean] if icon is 'sleet'
207
+ def sleet?
208
+ icon == 'sleet'
209
+ end
210
+
211
+ # @example
212
+ # location = DarkSky::Location.new [45, -90]
213
+ # location.current.windy?
214
+ # @since 0.1.0
215
+ # @return [Boolean] if icon is 'wind'
216
+ def windy?
217
+ icon == 'wind'
218
+ end
219
+
220
+ # @example
221
+ # location = DarkSky::Location.new [45, -90]
222
+ # location.current.foggy?
223
+ # @since 0.1.0
224
+ # @return [Boolean] if icon is 'fog'
225
+ def foggy?
226
+ icon == 'fog'
227
+ end
228
+
229
+ # @example
230
+ # location = DarkSky::Location.new [45, -90]
231
+ # location.current.cloudy?
232
+ # @since 0.1.0
233
+ # @return [Boolean] if icon is 'cloudy' or variant
234
+ def cloudy?
235
+ %w[cloudy partly-cloudy-day partly-cloudy-night].include? icon
236
+ end
237
+
238
+ private
239
+
240
+ # convert precip intensity to text
241
+ # keep this a separate method for testing purposes
242
+ # @since 0.1.4
243
+ # @return [String] text representation of precipitation intensity
244
+ def _precip_intensity_text(intensity)
245
+ if intensity >= 0.400
246
+ 'heavy'
247
+ elsif intensity >= 0.100
248
+ 'moderate'
249
+ elsif intensity >= 0.017
250
+ 'light'
251
+ elsif intensity >= 0.002
252
+ 'sporadic'
253
+ end
254
+ end
255
+
256
+ def _bearing_text(degree)
257
+ directions = %w[N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW]
258
+ directions[degree / 22.5 + 0.5]
259
+ end
260
+ end
261
+ end
@@ -1,6 +1,6 @@
1
1
  module DarkSky
2
2
  class Location
3
- class Current
3
+ class Current < CommonMethods
4
4
  # automatically called by `Location`
5
5
  # @since 0.1.0
6
6
  # @param [Location] location where to get data from
@@ -8,117 +8,6 @@ module DarkSky
8
8
  @location = location
9
9
  end
10
10
 
11
- # @example
12
- # location = DarkSky::Location.new [45, -90]
13
- # location.current.apparent_temperature #=> apparent temperature at location
14
- # @since 0.1.0
15
- # @return [Numeric] current apparent temperature at location
16
- def apparent_temperature
17
- data[:apparentTemperature]
18
- end
19
- alias wind_chill apparent_temperature
20
- alias heat_index apparent_temperature
21
- alias feels_like apparent_temperature
22
-
23
- # @example
24
- # location = DarkSky::Location.new [45, -90]
25
- # location.current.cloud_cover #=> cloud cover at location
26
- # @since 0.1.0
27
- # @return [Numeric] current cloud cover at location
28
- def cloud_cover
29
- data[:cloudCover]
30
- end
31
-
32
- # @example
33
- # location = DarkSky::Location.new [45, -90]
34
- # location.current.dew_point #=> dew point at location
35
- # @since 0.1.0
36
- # @return [Numeric] current dew point at location
37
- def dew_point
38
- data[:dewPoint]
39
- end
40
-
41
- # @example
42
- # location = DarkSky::Location.new [45, -90]
43
- # location.current.humidity #=> humidity at location
44
- # @since 0.1.0
45
- # @return [Numeric] current humidity at location
46
- def humidity
47
- data[:humidity]
48
- end
49
-
50
- # @example
51
- # location = DarkSky::Location.new [45, -90]
52
- # location.current.icon #=> icon representation
53
- # @since 0.1.0
54
- # @return [String] icon representation of current weather at location
55
- def icon
56
- data[:icon]
57
- end
58
-
59
- # @example
60
- # location = DarkSky::Location.new [45, -90]
61
- # location.current.clear?
62
- # @since 0.1.0
63
- # @return [Boolean] if icon is 'clear' variant
64
- def clear?
65
- %w[clear-day clear-night].include? icon
66
- end
67
-
68
- # @example
69
- # location = DarkSky::Location.new [45, -90]
70
- # location.current.rainy?
71
- # @since 0.1.0
72
- # @return [Boolean] if icon is 'rain'
73
- def rainy?
74
- icon == 'rain'
75
- end
76
-
77
- # @example
78
- # location = DarkSky::Location.new [45, -90]
79
- # location.current.snowy?
80
- # @since 0.1.0
81
- # @return [Boolean] if icon is 'snow'
82
- def snowy?
83
- icon == 'snow'
84
- end
85
-
86
- # @example
87
- # location = DarkSky::Location.new [45, -90]
88
- # location.current.sleet?
89
- # @since 0.1.0
90
- # @return [Boolean] if icon is 'sleet'
91
- def sleet?
92
- icon == 'sleet'
93
- end
94
-
95
- # @example
96
- # location = DarkSky::Location.new [45, -90]
97
- # location.current.windy?
98
- # @since 0.1.0
99
- # @return [Boolean] if icon is 'wind'
100
- def windy?
101
- icon == 'wind'
102
- end
103
-
104
- # @example
105
- # location = DarkSky::Location.new [45, -90]
106
- # location.current.foggy?
107
- # @since 0.1.0
108
- # @return [Boolean] if icon is 'fog'
109
- def foggy?
110
- icon == 'fog'
111
- end
112
-
113
- # @example
114
- # location = DarkSky::Location.new [45, -90]
115
- # location.current.cloudy?
116
- # @since 0.1.0
117
- # @return [Boolean] if icon is 'cloudy' or variant
118
- def cloudy?
119
- %w[cloudy partly-cloudy-day partly-cloudy-night].include? icon
120
- end
121
-
122
11
  # @example
123
12
  # location = DarkSky::Location.new [45, -90]
124
13
  # location.current.nearest_storm_bearing #=> nearest storm bearing at location
@@ -134,8 +23,7 @@ module DarkSky
134
23
  # @since 0.1.0
135
24
  # @return [String] text representation of bearing
136
25
  def nearest_storm_bearing_text
137
- directions = %w[N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW]
138
- directions[nearest_storm_bearing / 22.5 + 0.5]
26
+ _bearing_text(nearest_storm_bearing)
139
27
  end
140
28
 
141
29
  # @example
@@ -147,77 +35,6 @@ module DarkSky
147
35
  data[:nearestStormDistance]
148
36
  end
149
37
 
150
- # @example
151
- # location = DarkSky::Location.new [45, -90]
152
- # location.current.ozone #=> ozone level at location
153
- # @since 0.1.0
154
- # @return [Numeric] current ozone level at location
155
- def ozone
156
- data[:ozone]
157
- end
158
-
159
- # @example
160
- # location = DarkSky::Location.new [45, -90]
161
- # location.current.precip_intensity #=> precipitation intensity at location
162
- # @since 0.1.0
163
- # @return [Numeric] current precipitation intensity at location
164
- def precip_intensity
165
- data[:precipIntensity]
166
- end
167
-
168
- # @example
169
- # location = DarkSky::Locaiton.new [45, -90]
170
- # location.current.precip_intensity_text #=> text representation of precipitation intensity at location
171
- # @since 0.1.0
172
- # @return [String] text representation of precipitation intensity at location
173
- def precip_intensity_text
174
- if precip_intensity >= 0.400
175
- 'heavy'
176
- elsif precip_intensity >= 0.100
177
- 'moderate'
178
- elsif precip_intensity >= 0.017
179
- 'light'
180
- elsif precip_intensity >= 0.002
181
- 'very light'
182
- end
183
- end
184
-
185
- # @example
186
- # location = DarkSky::Location.new [45, -90]
187
- # location.current.precip_probability #=> precipitation probability at location
188
- # @since 0.1.0
189
- # @return [Numeric] current precipitation probability at location
190
- def precip_probability
191
- data[:precipProbability]
192
- end
193
-
194
- # @example
195
- # location = DarkSky::Location.new [45, -90]
196
- # location.current.precip_type #=> precipitation type at location
197
- # @since 0.1.0
198
- # @return [String | nil] current precipitation type at location
199
- def precip_type
200
- data[:precipType]
201
- end
202
-
203
- # @example
204
- # location = DarkSky::Location.new [45, -90]
205
- # location.current.pressure #=> barometric pressure at location
206
- # @since 0.1.0
207
- # @return [Numeric] current barometric pressure at location
208
- def pressure
209
- data[:pressure]
210
- end
211
-
212
- # @example
213
- # location = DarkSky::Location.new [45, -90]
214
- # location.current.summary #=> summary of weather at location
215
- # @since 0.1.0
216
- # @return [String] summary of weather at location
217
- def summary
218
- data[:summary]
219
- end
220
-
221
38
  # @example
222
39
  # location = DarkSky::Location.new [45, -90]
223
40
  # location.current.temperature #=> temperature at location
@@ -227,61 +44,6 @@ module DarkSky
227
44
  data[:temperature]
228
45
  end
229
46
 
230
- # @example
231
- # location = DarkSky::Location.new [45, -90]
232
- # location.current.uv_index #=> UV index at location
233
- # @since 0.1.0
234
- # @return [Numeric] current UV index at location
235
- def uv_index
236
- data[:uvIndex]
237
- end
238
-
239
- # @example
240
- # location = DarkSky::Location.new [45, -90]
241
- # location.current.visibility #=> visibility at location
242
- # @since 0.1.0
243
- # @return [Numeric] current visibility at location
244
- def visibility
245
- data[:visibility]
246
- end
247
-
248
- # @example
249
- # location = DarkSky::Location.new [45, -90]
250
- # location.current.wind_bearing #=> wind bearing at location
251
- # @since 0.1.0
252
- # @return [Numeric] current wind bearing at location
253
- def wind_bearing
254
- data[:windBearing]
255
- end
256
-
257
- # @example
258
- # location = DarkSky::Location.new [45, -90]
259
- # location.current.wind_bearing_text #=> text representation of bearing (N, NW, etc.)
260
- # @since 0.1.0
261
- # @return [String] text representation of bearing
262
- def wind_bearing_text
263
- directions = %w[N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW]
264
- directions[wind_bearing / 22.5 + 0.5]
265
- end
266
-
267
- # @example
268
- # location = DarkSky::Location.new [45, -90]
269
- # location.current.wind_gust #=> wind gust at location
270
- # @since 0.1.0
271
- # @return [Numeric] current wind gust at location
272
- def wind_gust
273
- data[:windGust]
274
- end
275
-
276
- # @example
277
- # location = DarkSky::Location.new [45, -90]
278
- # location.current.wind_speed #=> wind speed at location
279
- # @since 0.1.0
280
- # @return [Numeric] current wind speed at location
281
- def wind_speed
282
- data[:windSpeed]
283
- end
284
-
285
47
  private
286
48
 
287
49
  # helper to avoid typing this many times over
@@ -1,6 +1,6 @@
1
1
  module DarkSky
2
2
  class Location
3
- class Day
3
+ class Day < CommonMethods
4
4
  # automatically called by `Location`
5
5
  # @since 0.1.3
6
6
  # @param [Location] location where to get data from
@@ -59,24 +59,6 @@ module DarkSky
59
59
  end
60
60
  alias low_temperature_time temperature_low_time
61
61
 
62
- # @example
63
- # location = DarkSky::Location.new [45, -90]
64
- # location.today.icon #=> icon representation
65
- # @since 0.1.3
66
- # @return [String] icon representation of weather on day
67
- def icon
68
- data[:icon]
69
- end
70
-
71
- # @example
72
- # location = DarkSky::Location.new [45, -90]
73
- # location.today.summary #=> summary of weather
74
- # @since 0.1.3
75
- # @return [String] summary of weather on day
76
- def summary
77
- data[:summary]
78
- end
79
-
80
62
  # @example
81
63
  # location = DarkSky::Location.new [45, -90]
82
64
  # location.today.sunrise_time #=> sunrise time on day
@@ -113,33 +95,7 @@ module DarkSky
113
95
  # @return [String] textual representation of moon phase
114
96
  def moon_phase_text
115
97
  # separate method for easy unit testing
116
- _moon_phase_text moon_phase
117
- end
118
-
119
- # @example
120
- # location = DarkSky::Location.new [45, -90]
121
- # location.today.precip_intensity #=> precipitation intensity on day
122
- # @since 0.1.3
123
- # @return [Numeric] precipitation intensity on day
124
- def precip_intensity
125
- data[:precipIntensity]
126
- end
127
-
128
- # @example
129
- # location = DarkSky::Locaiton.new [45, -90]
130
- # location.today.precip_intensity_text #=> text representation of precipitation intensity on day
131
- # @since 0.1.3
132
- # @return [String] text representation of precipitation intensity on day
133
- def precip_intensity_text
134
- if precip_intensity >= 0.400
135
- 'heavy'
136
- elsif precip_intensity >= 0.100
137
- 'moderate'
138
- elsif precip_intensity >= 0.017
139
- 'light'
140
- elsif precip_intensity >= 0.002
141
- 'very light'
142
- end
98
+ _moon_phase_text(moon_phase)
143
99
  end
144
100
 
145
101
  # @example
@@ -157,15 +113,7 @@ module DarkSky
157
113
  # @since 0.1.3
158
114
  # @return [String] text representation of maximum precipitation intensity on day
159
115
  def precip_intensity_max_text
160
- if precip_intensity_max >= 0.400
161
- 'heavy'
162
- elsif precip_intensity_max >= 0.100
163
- 'moderate'
164
- elsif precip_intensity_max >= 0.017
165
- 'light'
166
- elsif precip_intensity_max >= 0.002
167
- 'very light'
168
- end
116
+ _precip_intensity_text(precip_intensity_max)
169
117
  end
170
118
 
171
119
  # @example
@@ -177,24 +125,6 @@ module DarkSky
177
125
  Time.at data[:precipIntensityMaxTime] if data[:precipIntensityMaxTime]
178
126
  end
179
127
 
180
- # @example
181
- # location = DarkSky::Location.new [45, -90]
182
- # location.today.precip_probability #=> precipitation probability on day
183
- # @since 0.1.3
184
- # @return [Numeric] precipitation probability
185
- def precip_probability
186
- data[:precipProbability]
187
- end
188
-
189
- # @example
190
- # location = DarkSky::Location.new [45, -90]
191
- # location.today.precip_type #=> precipitation type on day
192
- # @since 0.1.3
193
- # @return [String | nil] current precipitation type on day
194
- def precip_type
195
- data[:precipType]
196
- end
197
-
198
128
  # @example
199
129
  # location = DarkSky::Location.new [45, -90]
200
130
  # location.today.precip_accumulation #=> precipitation accumulation on day
@@ -272,51 +202,6 @@ module DarkSky
272
202
  alias low_wind_chill_time apparent_temperature_low_time
273
203
  alias wind_chill_low_time apparent_temperature_low_time
274
204
 
275
- # @example
276
- # location = DarkSky::Location.new [45, -90]
277
- # location.today.dew_point #=> dew point on day
278
- # @since 0.1.3
279
- # @return [Numeric] dew point on day
280
- def dew_point
281
- data[:dewPoint]
282
- end
283
-
284
- # @example
285
- # location = DarkSky::Location.new [45, -90]
286
- # location.today.humidity #=> humidity on day
287
- # @since 0.1.3
288
- # @return [Numeric] humidity on day
289
- def humidity
290
- data[:humidity]
291
- end
292
-
293
- # @example
294
- # location = DarkSky::Location.new [45, -90]
295
- # location.today.pressure #=> barometric pressue on day
296
- # @since 0.1.3
297
- # @return [Numeric] barometric pressure on day
298
- def pressure
299
- data[:pressure]
300
- end
301
-
302
- # @example
303
- # location = DarkSky::Location.new [45, -90]
304
- # location.today.wind_speed #=> wind speed on day
305
- # @since 0.1.3
306
- # @return [Numeric] wind speed on day
307
- def wind_speed
308
- data[:windSpeed]
309
- end
310
-
311
- # @example
312
- # location = DarkSky::Location.new [45, -90]
313
- # location.today.wind_gust #=> wind gust on day
314
- # @since 0.1.3
315
- # @return [Numeric] wind gust on day
316
- def wind_gust
317
- data[:windGust]
318
- end
319
-
320
205
  # @example
321
206
  # location = DarkSky::Location.new [45, -90]
322
207
  # location.today.wind_gust_time #=> wind gust time on day
@@ -326,33 +211,6 @@ module DarkSky
326
211
  Time.at data[:windGustTime]
327
212
  end
328
213
 
329
- # @example
330
- # location = DarkSky::Location.new [45, -90]
331
- # location.today.wind_bearing #=> wind bearing on day
332
- # @since 0.1.3
333
- # @return [Numeric] wind bearing on day
334
- def wind_bearing
335
- data[:windBearing]
336
- end
337
-
338
- # @example
339
- # location = DarkSky::Location.new [45, -90]
340
- # location.today.cloud_cover #=> cloud cover on day
341
- # @since 0.1.3
342
- # @return [Numeric] cloud cover on day
343
- def cloud_cover
344
- data[:cloudCover]
345
- end
346
-
347
- # @example
348
- # location = DarkSky::Location.new [45, -90]
349
- # location.today.uv_index #=> UV index on day
350
- # @since 0.1.3
351
- # @return [Numeric] UV index on day
352
- def uv_index
353
- data[:uvIndex]
354
- end
355
-
356
214
  # @example
357
215
  # location = DarkSky::Location.new [45, -90]
358
216
  # location.today.uv_index_time #=> max UV index time on day
@@ -362,24 +220,6 @@ module DarkSky
362
220
  Time.at data[:uvIndexTime]
363
221
  end
364
222
 
365
- # @example
366
- # location = DarkSky::Location.new [45, -90]
367
- # location.today.visibility #=> visibility on day
368
- # @since 0.1.3
369
- # @return [Numeric] visibility on day
370
- def visibility
371
- data[:visibility]
372
- end
373
-
374
- # @example
375
- # location = DarkSky::Location.new [45, -90]
376
- # location.today.ozone #=> ozone on day
377
- # @since 0.1.3
378
- # @return [Numeric] ozone on day
379
- def ozone
380
- data[:ozone]
381
- end
382
-
383
223
  private
384
224
 
385
225
  # helper to avoid typing this many times over
@@ -394,7 +234,7 @@ module DarkSky
394
234
  # keep this a separate method for testing purposes
395
235
  # @since 0.1.3
396
236
  # @return [String] text representation of moon phase
397
- def _moon_phase_text(phase) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/LineLength
237
+ def _moon_phase_text(phase)
398
238
  if phase < 0.05
399
239
  'new moon'
400
240
  elsif phase < 0.20
@@ -19,7 +19,7 @@ module DarkSky
19
19
 
20
20
  # @example
21
21
  # location = DarkSky::Location.new [45, -90]
22
- # location.units #=> :si
22
+ # location.units #=> :auto
23
23
  # @since 0.1.2
24
24
  # @return [Symbol] what unit system is being used
25
25
  attr_reader :units
@@ -46,11 +46,13 @@ module DarkSky
46
46
  # @param [Numeric] cache_duration requests within this many seconds will be parsed on existing data
47
47
  # @param [Symbol | String] units what unit system to use
48
48
  # @param [Symbol | String] language what language to return results in
49
+ # @param [Boolean] prefetch immediately perform an API request upon initialization?
49
50
  def initialize(
50
51
  location = [0, 0],
51
52
  cache_duration: 300,
52
53
  units: :auto,
53
- language: :en
54
+ language: :en,
55
+ prefetch: false
54
56
  )
55
57
  # initial value to avoid errors
56
58
  @cache_time = 1
@@ -59,24 +61,22 @@ module DarkSky
59
61
  @location = location
60
62
  @cache_duration = cache_duration # in seconds
61
63
  @language = language.to_sym
64
+ @units = units.to_sym
62
65
 
63
66
  # aliases for some unit systems
64
- units = units.to_sym
65
- if units == :uk
66
- @units == :uk2
67
- elsif units == :canada
68
- @units == :ca
69
- else
70
- @units = units
71
- end
67
+ @units = :uk2 if @units == :uk
68
+ @units = :ca if @units == :canada
72
69
 
73
70
  # initialize classes for namespace
74
71
  @current = Current.new self
72
+
73
+ # perform API request if prefetch is true
74
+ full_data if prefetch
75
75
  end
76
76
 
77
77
  # update cache if necessary and get latest data
78
78
  # @example
79
- # location = DarkSky::Location.new
79
+ # location = DarkSky::Location.new [45, -90]
80
80
  # location.full_data
81
81
  # @since 0.1.0
82
82
  # @return [Hash] raw data (in full) from DarkSky
@@ -1,4 +1,4 @@
1
1
  module DarkSky
2
- # version of this library (follows SemVer)
3
- VERSION = '0.1.3'.freeze
2
+ # version of this library (follows SemVer for versions >= 1.0.0)
3
+ VERSION = '0.1.4'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darksky-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Pratt
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.52'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.52'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.15'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.15'
83
111
  description:
84
112
  email:
85
113
  - the.z.cuber@gmail.com
@@ -99,6 +127,7 @@ files:
99
127
  - bin/setup
100
128
  - darksky-api.gemspec
101
129
  - lib/darksky-api.rb
130
+ - lib/darksky-api/common-methods.rb
102
131
  - lib/darksky-api/config.rb
103
132
  - lib/darksky-api/current.rb
104
133
  - lib/darksky-api/day.rb