spok 2.0.1 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 153ba620fe617dfbf11f0bee61b1b44c778bc63a47ec1b36ccd049b93c9c108f
4
- data.tar.gz: 66bc9d95d5661f9e51085df266a7be1a177ee1002037bc2e85667d3cc7598c29
3
+ metadata.gz: 8203f05d9317b3b0e4e0043d7ed4894f97d56d10d990df315ddfeb4dc9c458ef
4
+ data.tar.gz: 60d008280404cc98f1682df8ab7338e6c16ed7c50ec1529fe8211a166e098a6a
5
5
  SHA512:
6
- metadata.gz: d2ce9269c7ac0e3a7957acbc6723aa843ddddb524f5917f21ef15afc66eb949a000b8a0662fdd42b7640531e2dff47cb07958765ec746e154f9f24a06a919343
7
- data.tar.gz: 86f46c75c1f1a9ee1f98e6dbcdfc31902b028cfd828cde516506f9e7189ea8aaa4d2f1ca8c3a45031f509dd7bf17b098eb0f8ad2257c74273386debb7917e04a
6
+ metadata.gz: 1a71ef39e9b0092271ecd301968039700b0bf7600b873360cc33a445d2ff252fcebc3a50293ebcf988f4331a0d7f76ecdbba449ce3edab41fc6a8ae656cf0997
7
+ data.tar.gz: b398c9efc2c68a675e2773b586a0652b46f0037b6e0bcd9820bf47958c525fee9aee704b14fbca4b7e6226f3017d5d3199209a381574501aafca5e5205abcad1
@@ -3,7 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
- ## [2.0.0] - 2019-10-24
6
+ ## [2.1.0] - 2020-04-13
7
+
8
+ * Replace the access of `Spok::Workday` by `Spok` interface.
9
+
10
+ All methods before accessed by `Spok::Workday` module now is accessible by `Spok` interface.
11
+
12
+ ```ruby
13
+ Spok.restday?
14
+ Spok.workday?
15
+ Spok.weekend?
16
+ Spok.holiday?
17
+ Spok.last_workday
18
+ Spok.next_workday
19
+ ```
20
+
21
+ You can still use the `Spok::Workday` interface but it will warn you about the deprecation. We are planning to drop the support of `Spok::Workday` by the end of 2020.
22
+
23
+ ## [2.0.1] - 2019-10-24
7
24
 
8
25
  * Relax `activesupport` dependency to include the `6.x` series
9
26
 
@@ -1,39 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spok (2.0.0)
5
- activesupport (~> 5.1)
4
+ spok (2.0.1)
5
+ activesupport (>= 5.1, < 7.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.2.3)
10
+ activesupport (6.0.2.2)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 0.7, < 2)
13
13
  minitest (~> 5.1)
14
14
  tzinfo (~> 1.1)
15
- concurrent-ruby (1.1.5)
15
+ zeitwerk (~> 2.2)
16
+ concurrent-ruby (1.1.6)
16
17
  diff-lcs (1.3)
17
- i18n (1.7.0)
18
+ i18n (1.8.2)
18
19
  concurrent-ruby (~> 1.0)
19
- minitest (5.12.2)
20
- rake (12.3.2)
21
- rspec (3.8.0)
22
- rspec-core (~> 3.8.0)
23
- rspec-expectations (~> 3.8.0)
24
- rspec-mocks (~> 3.8.0)
25
- rspec-core (3.8.0)
26
- rspec-support (~> 3.8.0)
27
- rspec-expectations (3.8.3)
20
+ minitest (5.14.0)
21
+ rake (13.0.1)
22
+ rspec (3.9.0)
23
+ rspec-core (~> 3.9.0)
24
+ rspec-expectations (~> 3.9.0)
25
+ rspec-mocks (~> 3.9.0)
26
+ rspec-core (3.9.1)
27
+ rspec-support (~> 3.9.1)
28
+ rspec-expectations (3.9.1)
28
29
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.8.0)
30
- rspec-mocks (3.8.0)
30
+ rspec-support (~> 3.9.0)
31
+ rspec-mocks (3.9.1)
31
32
  diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.8.0)
33
- rspec-support (3.8.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-support (3.9.2)
34
35
  thread_safe (0.3.6)
35
- tzinfo (1.2.5)
36
+ tzinfo (1.2.7)
36
37
  thread_safe (~> 0.1)
38
+ zeitwerk (2.3.0)
37
39
 
38
40
  PLATFORMS
39
41
  ruby
@@ -45,4 +47,4 @@ DEPENDENCIES
45
47
  spok!
46
48
 
47
49
  BUNDLED WITH
48
- 1.17.3
50
+ 2.1.4
data/README.md CHANGED
@@ -25,17 +25,20 @@ Or install it yourself as:
25
25
 
26
26
  ### Dealing with workdays
27
27
 
28
- You can use the `Spok::Workday` module to check if a date is either a restday or a workday:
28
+ You can use the Spok to check if a date is either a rest day or a workday:
29
29
 
30
30
  ```ruby
31
31
  require 'spok'
32
32
 
33
- Spok::Workday.workday?(Date.new(2012, 12, 24))
33
+ Spok.restday?(Date.new(2012, 12, 24))
34
+ # => false
35
+
36
+ Spok.workday?(Date.new(2012, 12, 24))
34
37
  # => true
35
38
  ```
36
39
 
37
40
  Spok also supports different calendars for checking if a date is a workday or a
38
- restday
41
+ restday.
39
42
 
40
43
  ```ruby
41
44
  require 'spok'
@@ -117,6 +117,96 @@ class Spok
117
117
  (@start_date..@end_date).to_a.delete_if{ |date| Workday.restday?(date, calendar: calendar) }
118
118
  end
119
119
 
120
+ # Public: Checks if a given day is a restday.
121
+ #
122
+ # date - The Date to be checked.
123
+ # calendar - Symbol informing in which calendar the date will be checked
124
+ # (default: :brazil).
125
+ #
126
+ # Examples
127
+ #
128
+ # Spok.restday?(Date.new(2012, 8, 6))
129
+ # # => false
130
+ #
131
+ # Returns a boolean.
132
+ def self.restday?(date, calendar: Spok.default_calendar)
133
+ Workday.restday?(date, calendar: calendar)
134
+ end
135
+
136
+ # Public: Checks if a given day is a workday.
137
+ #
138
+ # date - The Date to be checked.
139
+ # calendar - Symbol informing in which calendar the date will be checked
140
+ # (default: :brazil).
141
+ #
142
+ # Examples
143
+ #
144
+ # Spok.workday?(Date.new(2012, 8, 6))
145
+ # # => true
146
+ #
147
+ # Returns a boolean.
148
+ def self.workday?(date, calendar: Spok.default_calendar)
149
+ Workday.workday?(date, calendar: calendar)
150
+ end
151
+
152
+ # Public: Checks if a given Date is on a weekend.
153
+ #
154
+ # date - The Date to be checked.
155
+ #
156
+ # Examples
157
+ #
158
+ # Spok.weekend?(Date.new(2012, 8, 6))
159
+ # # => false
160
+ #
161
+ # Returns a boolean.
162
+ def self.weekend?(date)
163
+ Workday.weekend?(date)
164
+ end
165
+
166
+ # Public: Checks if a given Date is on a holiday.
167
+ #
168
+ # date - The Date to be checked.
169
+ # calendar - Symbol informing in which calendar the date will be checked
170
+ # (default: :brazil).
171
+ #
172
+ # Examples
173
+ #
174
+ # Spok.holiday?(Date.new(2012, 5, 1))
175
+ # # => true
176
+ #
177
+ # Returns a boolean.
178
+ def self.holiday?(date, calendar: Spok.default_calendar)
179
+ Workday.holiday?(date, calendar: calendar)
180
+ end
181
+
182
+ # Public: Returns the last workday until the informed date.
183
+ # It returns the informed date in case it is a workday.
184
+ #
185
+ # date - End Date to check for workdays.
186
+ # calendar - Symbol informing in which calendar the date will be checked
187
+ # (default: :brazil).
188
+ #
189
+ # Examples
190
+ # Spok.last_workday(Date.new(2012, 10, 21))
191
+ # # => #<Date: 2012-10-19 ((2456220j,0s,0n),+0s,2299161j)>
192
+ def self.last_workday(date, calendar: Spok.default_calendar)
193
+ Workday.last_workday(date, calendar: calendar)
194
+ end
195
+
196
+ # Public: Returns the next workday starting from the informed date.
197
+ # It returns the informed date in case it is a workday.
198
+ #
199
+ # date - Start Date to check for workdays.
200
+ # calendar - Symbol informing in which calendar the date will be checked
201
+ # (default: :brazil).
202
+ #
203
+ # Examples
204
+ # Spok.next_workday(Date.new(2012, 10, 21))
205
+ # # => #<Date: 2012-10-19 ((2456220j,0s,0n),+0s,2299161j)>
206
+ def self.next_workday(date, calendar: Spok.default_calendar)
207
+ Workday.next_workday(date, calendar: calendar)
208
+ end
209
+
120
210
  # Public: Returns a Spok containing the same dates in a different calendar.
121
211
  #
122
212
  # calendar - Symbol informing calendar for new Spok (default: :brazil).
@@ -1,3 +1,3 @@
1
1
  class Spok
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
@@ -1,12 +1,13 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
+ require 'spok'
3
4
 
4
5
  class Spok
5
- # Public: Various methods useful for checking for restdays and workdays.
6
+ # Internal: Various methods useful for checking for restdays and workdays.
6
7
  # All methods are module methods and should be called on the Spok::Workday
7
8
  # module.
8
9
  module Workday
9
- # Public: Hash containing all weekdays.
10
+ # Internal: Hash containing all weekdays.
10
11
  WEEKDAYS = {
11
12
  sunday: 0,
12
13
  monday: 1,
@@ -17,7 +18,7 @@ class Spok
17
18
  saturday: 6
18
19
  }.freeze
19
20
 
20
- # Public: Checks if a given day is a restday.
21
+ # Internal: Checks if a given day is a restday.
21
22
  #
22
23
  # date - The Date to be checked.
23
24
  # calendar - Symbol informing in which calendar the date will be checked
@@ -33,7 +34,7 @@ class Spok
33
34
  self.weekend?(date) || self.holiday?(date, calendar: calendar)
34
35
  end
35
36
 
36
- # Public: Checks if a given day is a workday.
37
+ # Internal: Checks if a given day is a workday.
37
38
  #
38
39
  # date - The Date to be checked.
39
40
  # calendar - Symbol informing in which calendar the date will be checked
@@ -49,7 +50,7 @@ class Spok
49
50
  !restday?(date, calendar: calendar)
50
51
  end
51
52
 
52
- # Public: Checks if a given Date is on a weekend.
53
+ # Internal: Checks if a given Date is on a weekend.
53
54
  #
54
55
  # date - The Date to be checked.
55
56
  #
@@ -65,7 +66,7 @@ class Spok
65
66
  [WEEKDAYS[:saturday], WEEKDAYS[:sunday]].include? weekday
66
67
  end
67
68
 
68
- # Public: Checks if a given Date is on a holiday.
69
+ # Internal: Checks if a given Date is on a holiday.
69
70
  #
70
71
  # date - The Date to be checked.
71
72
  # calendar - Symbol informing in which calendar the date will be checked
@@ -82,7 +83,7 @@ class Spok
82
83
  dates.include?(date.to_date)
83
84
  end
84
85
 
85
- # Public: Returns the last workday until the informed date.
86
+ # Internal: Returns the last workday until the informed date.
86
87
  # It returns the informed date in case it is a workday.
87
88
  #
88
89
  # date - End Date to check for workdays.
@@ -98,7 +99,7 @@ class Spok
98
99
  last_workday((date - 1.day), calendar: calendar)
99
100
  end
100
101
 
101
- # Public: Returns the next workday starting from the informed date.
102
+ # Internal: Returns the next workday starting from the informed date.
102
103
  # It returns the informed date in case it is a workday.
103
104
  #
104
105
  # date - Start Date to check for workdays.
@@ -113,5 +114,16 @@ class Spok
113
114
 
114
115
  next_workday((date + 1.day), calendar: calendar)
115
116
  end
117
+
118
+ class << self
119
+ extend Gem::Deprecate
120
+
121
+ deprecate :restday?, 'Spok.restday?', 2020, 12
122
+ deprecate :workday?, 'Spok.workday?', 2020, 12
123
+ deprecate :weekend?, 'Spok.weekend?', 2020, 12
124
+ deprecate :holiday?, 'Spok.holiday?', 2020, 12
125
+ deprecate :last_workday, 'Spok.last_workday', 2020, 12
126
+ deprecate :next_workday, 'Spok.next_workday', 2020, 12
127
+ end
116
128
  end
117
129
  end
Binary file
@@ -216,4 +216,64 @@ describe Spok do
216
216
  expect(default_calendar_was).to eq(:brazil)
217
217
  end
218
218
  end
219
+
220
+ describe '#restday?' do
221
+ it 'calls for the restday implementation' do
222
+ date = Date.new(2020, 4, 9)
223
+
224
+ expect(Spok::Workday).to receive(:restday?).with(date, calendar: :brazil).and_call_original
225
+
226
+ Spok.restday?(date)
227
+ end
228
+ end
229
+
230
+ describe '.workday?' do
231
+ it 'calls for the workday implementation' do
232
+ date = Date.new(2020, 4, 9)
233
+
234
+ expect(Spok::Workday).to receive(:workday?).with(date, calendar: :brazil).and_call_original
235
+
236
+ Spok.workday?(date)
237
+ end
238
+ end
239
+
240
+ describe '.weekend?' do
241
+ it 'calls for the weekend implementation' do
242
+ date = Date.new(2020, 4, 9)
243
+
244
+ expect(Spok::Workday).to receive(:weekend?).with(date).and_call_original
245
+
246
+ Spok.weekend?(date)
247
+ end
248
+ end
249
+
250
+ describe '.holiday?' do
251
+ it 'calls for the holiday implementation' do
252
+ date = Date.new(2020, 4, 9)
253
+
254
+ expect(Spok::Workday).to receive(:holiday?).with(date, calendar: :brazil).and_call_original
255
+
256
+ Spok.holiday?(date)
257
+ end
258
+ end
259
+
260
+ describe '.last_workday' do
261
+ it 'calls for the last workday implementation' do
262
+ date = Date.new(2020, 4, 9)
263
+
264
+ expect(Spok::Workday).to receive(:last_workday).with(date, calendar: :brazil).and_call_original
265
+
266
+ Spok.last_workday(date)
267
+ end
268
+ end
269
+
270
+ describe '.next_workday' do
271
+ it 'calls for the next workday implementation' do
272
+ date = Date.new(2020, 4, 9)
273
+
274
+ expect(Spok::Workday).to receive(:next_workday).with(date, calendar: :brazil).and_call_original
275
+
276
+ Spok.next_workday(date)
277
+ end
278
+ end
219
279
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spok
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnetis Staff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-24 00:00:00.000000000 Z
11
+ date: 2020-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,7 +116,7 @@ files:
116
116
  - lib/spok/config/vietnam.yml
117
117
  - lib/spok/version.rb
118
118
  - lib/spok/workday.rb
119
- - pkg/spok-2.0.0.gem
119
+ - pkg/spok-2.1.0.gem
120
120
  - spec/fixtures/custom-calendar.yml
121
121
  - spec/lib/spok/calendars_spec.rb
122
122
  - spec/lib/spok/workday_spec.rb
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.0.4
145
+ rubygems_version: 3.0.3
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: A gem to work with periods of dates
Binary file