spok 1.1.0 → 2.0.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile.lock +48 -0
- data/README.md +10 -1
- data/lib/spok.rb +19 -4
- data/lib/spok/calendars.rb +47 -0
- data/lib/spok/config/australia.yml +233 -0
- data/lib/spok/config/austria.yml +1120 -0
- data/lib/spok/config/belgium.yml +861 -0
- data/lib/spok/config/bovespa.yml +2 -0
- data/lib/spok/config/{brasil.yml → brazil.yml} +1 -1
- data/lib/spok/config/colombia.yml +499 -0
- data/lib/spok/config/france.yml +522 -0
- data/lib/spok/config/germany.yml +775 -0
- data/lib/spok/config/guatemala.yml +948 -0
- data/lib/spok/config/india.yml +170 -0
- data/lib/spok/config/liechtenstein.yml +1119 -0
- data/lib/spok/config/singapore.yml +145 -0
- data/lib/spok/config/switzerland.yml +346 -0
- data/lib/spok/config/ukraine.yml +301 -0
- data/lib/spok/config/united_states.yml +454 -0
- data/lib/spok/version.rb +1 -1
- data/lib/spok/workday.rb +7 -31
- data/pkg/spok-2.0.0.gem +0 -0
- data/spec/fixtures/custom-calendar.yml +3 -0
- data/spec/lib/spok/calendars_spec.rb +6 -9
- data/spec/lib/spok/workday_spec.rb +17 -3
- data/spec/lib/spok_spec.rb +5 -5
- data/spok.gemspec +1 -1
- metadata +26 -10
- data/pkg/spok-1.0.0.gem +0 -0
data/lib/spok/version.rb
CHANGED
data/lib/spok/workday.rb
CHANGED
@@ -1,36 +1,11 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext'
|
3
|
-
require 'set'
|
4
|
-
require 'yaml'
|
5
3
|
|
6
4
|
class Spok
|
7
5
|
# Public: Various methods useful for checking for restdays and workdays.
|
8
6
|
# All methods are module methods and should be called on the Spok::Workday
|
9
7
|
# module.
|
10
8
|
module Workday
|
11
|
-
# Public: Array of available calendars.
|
12
|
-
|
13
|
-
CALENDARS = %i(
|
14
|
-
brasil
|
15
|
-
bovespa
|
16
|
-
canada
|
17
|
-
costa_rica
|
18
|
-
indonesia
|
19
|
-
mexico
|
20
|
-
netherlands
|
21
|
-
poland
|
22
|
-
portugal
|
23
|
-
spain
|
24
|
-
vietnam
|
25
|
-
)
|
26
|
-
|
27
|
-
# Public: Hash containing all holidays for each available calendar.
|
28
|
-
HOLIDAYS = CALENDARS.map do |calendar|
|
29
|
-
holidays_file = File.open(File.join(File.dirname(__FILE__), "config/#{calendar}.yml"))
|
30
|
-
holidays = YAML.safe_load(holidays_file.read, [Date])
|
31
|
-
[calendar, Set.new(holidays[calendar.to_s])]
|
32
|
-
end.to_h
|
33
|
-
|
34
9
|
# Public: Hash containing all weekdays.
|
35
10
|
WEEKDAYS = {
|
36
11
|
sunday: 0,
|
@@ -46,7 +21,7 @@ class Spok
|
|
46
21
|
#
|
47
22
|
# date - The Date to be checked.
|
48
23
|
# calendar - Symbol informing in which calendar the date will be checked
|
49
|
-
# (default: :
|
24
|
+
# (default: :brazil).
|
50
25
|
#
|
51
26
|
# Examples
|
52
27
|
#
|
@@ -62,7 +37,7 @@ class Spok
|
|
62
37
|
#
|
63
38
|
# date - The Date to be checked.
|
64
39
|
# calendar - Symbol informing in which calendar the date will be checked
|
65
|
-
# (default: :
|
40
|
+
# (default: :brazil).
|
66
41
|
#
|
67
42
|
# Examples
|
68
43
|
#
|
@@ -94,7 +69,7 @@ class Spok
|
|
94
69
|
#
|
95
70
|
# date - The Date to be checked.
|
96
71
|
# calendar - Symbol informing in which calendar the date will be checked
|
97
|
-
# (default: :
|
72
|
+
# (default: :brazil).
|
98
73
|
#
|
99
74
|
# Examples
|
100
75
|
#
|
@@ -103,7 +78,8 @@ class Spok
|
|
103
78
|
#
|
104
79
|
# Returns a boolean.
|
105
80
|
def self.holiday?(date, calendar: Spok.default_calendar)
|
106
|
-
|
81
|
+
dates = Spok::Calendars.get(calendar)
|
82
|
+
dates.include?(date.to_date)
|
107
83
|
end
|
108
84
|
|
109
85
|
# Public: Returns the last workday until the informed date.
|
@@ -111,7 +87,7 @@ class Spok
|
|
111
87
|
#
|
112
88
|
# date - End Date to check for workdays.
|
113
89
|
# calendar - Symbol informing in which calendar to check for workdays
|
114
|
-
# (default: :
|
90
|
+
# (default: :brazil).
|
115
91
|
#
|
116
92
|
# Examples
|
117
93
|
# Spok::Workday.last_workday(Date.new(2012, 10, 21))
|
@@ -127,7 +103,7 @@ class Spok
|
|
127
103
|
#
|
128
104
|
# date - Start Date to check for workdays.
|
129
105
|
# calendar - Symbol informing in which calendar to check for workdays
|
130
|
-
# (default: :
|
106
|
+
# (default: :brazil).
|
131
107
|
#
|
132
108
|
# Examples
|
133
109
|
# Spok::Workday.next_workday(Date.new(2012, 10, 21))
|
data/pkg/spok-2.0.0.gem
ADDED
Binary file
|
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'spok
|
2
|
+
require 'spok'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
file = File.new(File.join(File.dirname(__FILE__), "../../../lib/spok/config/#{calendar}.yml"))
|
8
|
-
last_day = Date.strptime(file.readlines[-1], '- %Y-%m-%d')
|
9
|
-
valid_calendar = last_day - 365 > Date.today
|
4
|
+
describe Spok::Calendars do
|
5
|
+
it 'loads a new calendar' do
|
6
|
+
Spok::Calendars.add(:custom_calendar, File.expand_path('../../fixtures/custom-calendar.yml', __dir__))
|
10
7
|
|
11
|
-
|
12
|
-
|
8
|
+
expect(Spok::Workday.restday?(Date.new(2019, 01, 25), calendar: :custom_calendar)).to eq(true)
|
9
|
+
expect(Spok::Workday.workday?(Date.new(2019, 01, 25), calendar: :custom_calendar)).to eq(false)
|
13
10
|
end
|
14
11
|
end
|
@@ -21,7 +21,7 @@ describe Spok::Workday do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
context 'holidays using
|
24
|
+
context 'holidays using brazil calendar' do
|
25
25
|
it 'is not a workday' do
|
26
26
|
['2012-06-07', '2012-09-07', '2012-10-12',
|
27
27
|
'2012-11-02', '2012-11-15', '2012-12-25'].each do |holiday|
|
@@ -65,6 +65,20 @@ describe Spok::Workday do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
context 'holidays using guatemala calendar' do
|
70
|
+
it 'is not a workday' do
|
71
|
+
['2018-01-01', '2018-06-30', '2018-09-15', '2018-10-20'].each do |holiday|
|
72
|
+
expect(described_class.workday?(Date.parse(holiday), calendar: :guatemala)).to eq(false)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'is a workday' do
|
77
|
+
['2018-01-22', '2018-07-27', '2018-12-20'].each do |holiday|
|
78
|
+
expect(described_class.workday?(Date.parse(holiday), calendar: :guatemala)).to eq(true)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
68
82
|
end
|
69
83
|
|
70
84
|
describe '#restday?' do
|
@@ -158,12 +172,12 @@ describe Spok::Workday do
|
|
158
172
|
|
159
173
|
describe '#holiday?' do
|
160
174
|
it 'returns false when date is not a holiday on the given calendar' do
|
161
|
-
expect(described_class.holiday?(Date.new(2018, 05, 02), calendar: :
|
175
|
+
expect(described_class.holiday?(Date.new(2018, 05, 02), calendar: :brazil)).to eq(false)
|
162
176
|
expect(described_class.holiday?(Date.new(2018, 12, 15), calendar: :bovespa)).to eq(false)
|
163
177
|
end
|
164
178
|
|
165
179
|
it 'returns true when date is a holiday on the given calendar' do
|
166
|
-
expect(described_class.holiday?(Date.new(2018, 05, 01), calendar: :
|
180
|
+
expect(described_class.holiday?(Date.new(2018, 05, 01), calendar: :brazil)).to eq(true)
|
167
181
|
expect(described_class.holiday?(Date.new(2018, 12, 25), calendar: :bovespa)).to eq(true)
|
168
182
|
end
|
169
183
|
end
|
data/spec/lib/spok_spec.rb
CHANGED
@@ -110,12 +110,12 @@ describe Spok do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
context 'when
|
114
|
-
subject { described_class.new(sunday, tuesday).to_calendar(:
|
113
|
+
context 'when brazil is the calendar' do
|
114
|
+
subject { described_class.new(sunday, tuesday).to_calendar(:brazil) }
|
115
115
|
|
116
116
|
context 'and the start date is holiday' do
|
117
117
|
let(:start_date) { Date.new(2013, 9, 6) }
|
118
|
-
let(:sunday) { Date.new(2013, 9, 7) } #
|
118
|
+
let(:sunday) { Date.new(2013, 9, 7) } # brazil holiday
|
119
119
|
let(:tuesday) { Date.new(2013, 9, 10) }
|
120
120
|
it 'returns the last workday as the start date' do
|
121
121
|
expect(subject.start_date).to eq(start_date)
|
@@ -124,7 +124,7 @@ describe Spok do
|
|
124
124
|
|
125
125
|
context 'end date on a bovespa holiday' do
|
126
126
|
let(:sunday) { Date.new(2013, 9, 5) }
|
127
|
-
let(:tuesday) { Date.new(2013, 9, 7) } #
|
127
|
+
let(:tuesday) { Date.new(2013, 9, 7) } # brazil holiday
|
128
128
|
let(:end_date) { Date.new(2013, 9, 6) }
|
129
129
|
it 'returns the last bovespa workday as the end date' do
|
130
130
|
expect(subject.end_date).to eq(end_date)
|
@@ -213,7 +213,7 @@ describe Spok do
|
|
213
213
|
spok = double("spok", :default_calendar => :bovespa)
|
214
214
|
|
215
215
|
expect(default_calendar_was).not_to eq(spok.default_calendar)
|
216
|
-
expect(default_calendar_was).to eq(:
|
216
|
+
expect(default_calendar_was).to eq(:brazil)
|
217
217
|
end
|
218
218
|
end
|
219
219
|
end
|
data/spok.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency 'activesupport', '~> 5.1'
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'bundler'
|
27
27
|
spec.add_development_dependency 'rake'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3'
|
29
29
|
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:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2019-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,24 +78,40 @@ files:
|
|
78
78
|
- CODE_OF_CONDUCT.md
|
79
79
|
- CONTRIBUTING.md
|
80
80
|
- Gemfile
|
81
|
+
- Gemfile.lock
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
84
85
|
- lib/spok.rb
|
86
|
+
- lib/spok/calendars.rb
|
87
|
+
- lib/spok/config/australia.yml
|
88
|
+
- lib/spok/config/austria.yml
|
89
|
+
- lib/spok/config/belgium.yml
|
85
90
|
- lib/spok/config/bovespa.yml
|
86
|
-
- lib/spok/config/
|
91
|
+
- lib/spok/config/brazil.yml
|
87
92
|
- lib/spok/config/canada.yml
|
93
|
+
- lib/spok/config/colombia.yml
|
88
94
|
- lib/spok/config/costa_rica.yml
|
95
|
+
- lib/spok/config/france.yml
|
96
|
+
- lib/spok/config/germany.yml
|
97
|
+
- lib/spok/config/guatemala.yml
|
98
|
+
- lib/spok/config/india.yml
|
89
99
|
- lib/spok/config/indonesia.yml
|
100
|
+
- lib/spok/config/liechtenstein.yml
|
90
101
|
- lib/spok/config/mexico.yml
|
91
102
|
- lib/spok/config/netherlands.yml
|
92
103
|
- lib/spok/config/poland.yml
|
93
104
|
- lib/spok/config/portugal.yml
|
105
|
+
- lib/spok/config/singapore.yml
|
94
106
|
- lib/spok/config/spain.yml
|
107
|
+
- lib/spok/config/switzerland.yml
|
108
|
+
- lib/spok/config/ukraine.yml
|
109
|
+
- lib/spok/config/united_states.yml
|
95
110
|
- lib/spok/config/vietnam.yml
|
96
111
|
- lib/spok/version.rb
|
97
112
|
- lib/spok/workday.rb
|
98
|
-
- pkg/spok-
|
113
|
+
- pkg/spok-2.0.0.gem
|
114
|
+
- spec/fixtures/custom-calendar.yml
|
99
115
|
- spec/lib/spok/calendars_spec.rb
|
100
116
|
- spec/lib/spok/workday_spec.rb
|
101
117
|
- spec/lib/spok_spec.rb
|
@@ -120,12 +136,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
136
|
- !ruby/object:Gem::Version
|
121
137
|
version: '0'
|
122
138
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.7.3
|
139
|
+
rubygems_version: 3.0.4
|
125
140
|
signing_key:
|
126
141
|
specification_version: 4
|
127
142
|
summary: A gem to work with periods of dates
|
128
143
|
test_files:
|
144
|
+
- spec/fixtures/custom-calendar.yml
|
129
145
|
- spec/lib/spok/calendars_spec.rb
|
130
146
|
- spec/lib/spok/workday_spec.rb
|
131
147
|
- spec/lib/spok_spec.rb
|
data/pkg/spok-1.0.0.gem
DELETED
Binary file
|