russian_workdays 2.6.0 → 2.7.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.
@@ -1,24 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("lib", __dir__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require_relative 'lib/russian_workdays/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "russian_workdays"
8
- spec.version = "2.6.0"
9
- spec.authors = ["heckfy"]
10
- spec.email = ["heckfyoz@gmail.com"]
11
- spec.summary = "Russian workdays"
12
- spec.description = "Производственный календарь РФ"
13
- spec.homepage = "https://github.com/heckfy/russian_workdays"
14
- spec.license = "MIT"
8
+ spec.name = 'russian_workdays'
9
+ spec.version = RussianWorkdays::VERSION
10
+ spec.authors = ['heckfy']
11
+ spec.email = ['heckfyoz@gmail.com']
12
+ spec.summary = 'Russian workdays'
13
+ spec.description = 'Производственный календарь РФ'
14
+ spec.homepage = 'https://github.com/heckfy/russian_workdays'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = '>= 2.6.0'
15
17
 
16
18
  spec.files = `git ls-files -z`.split("\x0")
17
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
20
22
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency 'bundler', '~> 2.4'
24
+ spec.add_development_dependency 'rake', '~> 13.2'
25
+ spec.add_development_dependency 'rspec', '~> 3.1'
26
+ spec.add_development_dependency 'rubocop', '~> 1.71.1'
24
27
  end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RussianWorkdays::Collection do
6
+ subject(:instance_of_collection) { described_class.new(range) }
7
+
8
+ let(:year) { 2014 }
9
+ let(:month) { 2 }
10
+ let(:range) { (Date.new(year, month, 20)..Date.new(year, month, -1)) }
11
+
12
+ describe '#initialize' do
13
+ context 'when missing data for that year' do
14
+ let(:year) { 1990 }
15
+
16
+ it 'raise MissingYearError' do
17
+ expect { instance_of_collection }
18
+ .to raise_error(RussianWorkdays::MissingYearError, /Data missing for that year: 1990/)
19
+ end
20
+ end
21
+
22
+ context 'when range is not Array or Range object' do
23
+ let(:range) { 0 }
24
+
25
+ it 'raise ArgumentError' do
26
+ expect { instance_of_collection }
27
+ .to raise_error(ArgumentError, /Must be a Array or Range object/)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#holidays' do
33
+ let(:expected_array) do
34
+ [22, 23].map { |day| Date.new(year, month, day) }
35
+ end
36
+
37
+ it 'array of holidays Date' do
38
+ expect(instance_of_collection.holidays).to eq(expected_array)
39
+ end
40
+ end
41
+
42
+ describe '#preholidays' do
43
+ let(:expected_array) do
44
+ [Date.new(year, month, 24)]
45
+ end
46
+
47
+ it 'array of preholidays Date' do
48
+ expect(instance_of_collection.preholidays).to eq(expected_array)
49
+ end
50
+ end
51
+
52
+ describe '#works' do
53
+ let(:expected_array) do
54
+ [20, 21, 24, 25, 26, 27, 28].map do |day|
55
+ Date.new(year, month, day)
56
+ end
57
+ end
58
+
59
+ it 'array of works Date' do
60
+ expect(instance_of_collection.works).to eq(expected_array)
61
+ end
62
+ end
63
+
64
+ describe '#work_hours_count' do
65
+ context 'when work_hours_per_week is not one of: 24, 36, 40' do
66
+ it 'raise ArgumentError' do
67
+ expect { instance_of_collection.work_hours_count(10) }
68
+ .to raise_error(ArgumentError, /Unknown work hours count. Must be one of: 24, 36, 40/)
69
+ end
70
+ end
71
+
72
+ context 'when week have 24 work hours' do
73
+ it { expect(instance_of_collection.work_hours_count(24)).to eq(32.6) }
74
+ end
75
+
76
+ context 'when week have 36 work hours' do
77
+ it { expect(instance_of_collection.work_hours_count(36)).to eq(49.4) }
78
+ end
79
+
80
+ context 'when week have 40 work hours' do
81
+ it { expect(instance_of_collection.work_hours_count).to eq(55) }
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'date'
5
+
6
+ describe RussianWorkdays::Day do
7
+ subject(:work?) { described_class.new(date).work? }
8
+
9
+ let(:work_date) { Date.new(2014, 5, 5) }
10
+ let(:preholiday_date) { Date.new(2014, 2, 24) }
11
+ let(:holiday_date) { Date.new(2014, 5, 1) }
12
+
13
+ describe '#initialize' do
14
+ context 'when date is not Date object' do
15
+ let(:date) { 'string' }
16
+
17
+ it 'raise ArgumentError' do
18
+ expect { described_class.new(date) }.to raise_error(ArgumentError, /Must be a Date object/)
19
+ end
20
+ end
21
+
22
+ context 'when missing data for that year' do
23
+ let(:date) { Date.new(1990, 1, 1) }
24
+
25
+ it 'raise MissingYearError' do
26
+ expect { described_class.new(date) }
27
+ .to raise_error(RussianWorkdays::MissingYearError, /Data missing for that year: 1990/)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#work?' do
33
+ context 'when date is work day' do
34
+ let(:date) { work_date }
35
+
36
+ it 'return true' do
37
+ is_expected.to eq(true)
38
+ end
39
+ end
40
+
41
+ context 'when date is preholiday' do
42
+ let(:date) { preholiday_date }
43
+
44
+ it 'return true' do
45
+ is_expected.to eq(true)
46
+ end
47
+ end
48
+
49
+ context 'when date is holiday' do
50
+ let(:date) { holiday_date }
51
+
52
+ it 'return false' do
53
+ is_expected.to eq(false)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#preholiday?' do
59
+ context 'when date is work day' do
60
+ let(:date) { work_date }
61
+
62
+ it 'return true' do
63
+ expect(RussianWorkdays::Day.new(date).preholiday?).to eq(false)
64
+ end
65
+ end
66
+
67
+ context 'when date is preholiday' do
68
+ let(:date) { preholiday_date }
69
+
70
+ it 'return true' do
71
+ expect(RussianWorkdays::Day.new(date).preholiday?).to eq(true)
72
+ end
73
+ end
74
+
75
+ context 'when date is holiday' do
76
+ let(:date) { holiday_date }
77
+
78
+ it 'return false' do
79
+ expect(RussianWorkdays::Day.new(date).preholiday?).to eq(false)
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#holiday?' do
85
+ context 'when date is work day' do
86
+ let(:date) { work_date }
87
+
88
+ it 'return true' do
89
+ expect(RussianWorkdays::Day.new(date).holiday?).to eq(false)
90
+ end
91
+ end
92
+
93
+ context 'when date is preholiday' do
94
+ let(:date) { preholiday_date }
95
+
96
+ it 'return true' do
97
+ expect(RussianWorkdays::Day.new(date).holiday?).to eq(false)
98
+ end
99
+ end
100
+
101
+ context 'when date is holiday' do
102
+ let(:date) { holiday_date }
103
+
104
+ it 'return false' do
105
+ expect(RussianWorkdays::Day.new(date).holiday?).to eq(true)
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#type' do
111
+ context 'when date is work day' do
112
+ let(:date) { work_date }
113
+
114
+ it 'return :work' do
115
+ expect(RussianWorkdays::Day.new(date).type).to eq(:work)
116
+ end
117
+ end
118
+
119
+ context 'when date is preholiday' do
120
+ let(:date) { preholiday_date }
121
+
122
+ it 'return :preholiday' do
123
+ expect(RussianWorkdays::Day.new(date).type).to eq(:preholiday)
124
+ end
125
+ end
126
+
127
+ context 'when date is holiday' do
128
+ let(:date) { holiday_date }
129
+
130
+ it 'return :holiday' do
131
+ expect(RussianWorkdays::Day.new(date).type).to eq(:holiday)
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RussianWorkdays::Month do
6
+ subject(:instance_of_month) { described_class.new(year, month) }
7
+
8
+ let(:year) { 2014 }
9
+ let(:month) { 2 }
10
+
11
+ describe '#initialize' do
12
+ context 'when missing data for that year' do
13
+ let(:year) { 1990 }
14
+
15
+ it 'raise MissingYearError' do
16
+ expect { instance_of_month }
17
+ .to raise_error(RussianWorkdays::MissingYearError, /Data missing for that year: 1990/)
18
+ end
19
+ end
20
+
21
+ context 'when month is not in 1..12' do
22
+ let(:month) { 0 }
23
+
24
+ it 'raise ArgumentError' do
25
+ expect { instance_of_month }
26
+ .to raise_error(ArgumentError, /Must be a number between 1 and 12/)
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#holidays' do
32
+ let(:expected_array) do
33
+ [1, 2, 8, 9, 15, 16, 22, 23].map { |day| Date.new(year, month, day) }
34
+ end
35
+
36
+ it 'array of holidays Date' do
37
+ expect(instance_of_month.holidays).to eq(expected_array)
38
+ end
39
+ end
40
+
41
+ describe '#preholidays' do
42
+ let(:expected_array) do
43
+ [Date.new(year, month, 24)]
44
+ end
45
+
46
+ it 'array of preholidays Date' do
47
+ expect(instance_of_month.preholidays).to eq(expected_array)
48
+ end
49
+ end
50
+
51
+ describe '#works' do
52
+ let(:expected_array) do
53
+ [3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28].map do |day|
54
+ Date.new(year, month, day)
55
+ end
56
+ end
57
+
58
+ it 'array of works Date' do
59
+ expect(instance_of_month.works).to eq(expected_array)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RussianWorkdays::Year do
6
+ subject(:instance_of_year) { described_class.new(year) }
7
+
8
+ let(:year) { 2014 }
9
+
10
+ describe '#initialize' do
11
+ context 'when missing data for that year' do
12
+ let(:year) { 1990 }
13
+
14
+ it 'raise MissingYearError' do
15
+ expect { instance_of_year }
16
+ .to raise_error(RussianWorkdays::MissingYearError, /Data missing for that year: 1990/)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#holidays' do
22
+ let(:expected_array) do
23
+ (1..12).flat_map { |month| RussianWorkdays::Month.new(year, month).holidays }
24
+ end
25
+
26
+ it 'array of holidays Date' do
27
+ expect(instance_of_year.holidays).to eq(expected_array)
28
+ end
29
+ end
30
+
31
+ describe '#preholidays' do
32
+ let(:expected_array) do
33
+ (1..12).flat_map { |month| RussianWorkdays::Month.new(year, month).preholidays }
34
+ end
35
+
36
+ it 'array of preholidays Date' do
37
+ expect(instance_of_year.preholidays).to eq(expected_array)
38
+ end
39
+ end
40
+
41
+ describe '#works' do
42
+ let(:expected_array) do
43
+ (1..12).flat_map { |month| RussianWorkdays::Month.new(year, month).works }
44
+ end
45
+
46
+ it 'array of works Date' do
47
+ expect(instance_of_year.works).to eq(expected_array)
48
+ end
49
+ end
50
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/setup"
3
+ require 'bundler/setup'
4
4
  Bundler.setup
5
5
 
6
- require "russian_workdays"
6
+ require 'russian_workdays'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: russian_workdays
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - heckfy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-26 00:00:00.000000000 Z
11
+ date: 2025-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,76 +16,94 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '2.4'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '2.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '13.2'
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: '0'
40
+ version: '13.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 1.71.1
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 1.71.1
55
69
  description: Производственный календарь РФ
56
70
  email:
57
71
  - heckfyoz@gmail.com
58
- executables: []
72
+ executables:
73
+ - console
74
+ - setup
59
75
  extensions: []
60
76
  extra_rdoc_files: []
61
77
  files:
62
- - ".codeclimate.yml"
63
78
  - ".gitignore"
64
79
  - ".rubocop.yml"
65
- - ".travis.yml"
80
+ - CHANGELOG.md
66
81
  - Gemfile
67
82
  - LICENSE.txt
68
83
  - README.md
69
84
  - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/dates.yml
70
88
  - lib/russian_workdays.rb
71
89
  - lib/russian_workdays/collection.rb
72
90
  - lib/russian_workdays/collection_preset.rb
73
- - lib/russian_workdays/dates.yml
74
91
  - lib/russian_workdays/day.rb
92
+ - lib/russian_workdays/missing_year_error.rb
75
93
  - lib/russian_workdays/month.rb
76
94
  - lib/russian_workdays/version.rb
77
95
  - lib/russian_workdays/year.rb
78
96
  - russian_workdays.gemspec
79
- - spec/collection_spec.rb
80
- - spec/day_spec.rb
81
- - spec/month_spec.rb
97
+ - spec/lib/collection_spec.rb
98
+ - spec/lib/day_spec.rb
99
+ - spec/lib/month_spec.rb
100
+ - spec/lib/year_spec.rb
82
101
  - spec/spec_helper.rb
83
- - spec/year_spec.rb
84
102
  homepage: https://github.com/heckfy/russian_workdays
85
103
  licenses:
86
104
  - MIT
87
105
  metadata: {}
88
- post_install_message:
106
+ post_install_message:
89
107
  rdoc_options: []
90
108
  require_paths:
91
109
  - lib
@@ -93,20 +111,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
111
  requirements:
94
112
  - - ">="
95
113
  - !ruby/object:Gem::Version
96
- version: '0'
114
+ version: 2.6.0
97
115
  required_rubygems_version: !ruby/object:Gem::Requirement
98
116
  requirements:
99
117
  - - ">="
100
118
  - !ruby/object:Gem::Version
101
119
  version: '0'
102
120
  requirements: []
103
- rubygems_version: 3.1.4
104
- signing_key:
121
+ rubygems_version: 3.4.10
122
+ signing_key:
105
123
  specification_version: 4
106
124
  summary: Russian workdays
107
125
  test_files:
108
- - spec/collection_spec.rb
109
- - spec/day_spec.rb
110
- - spec/month_spec.rb
126
+ - spec/lib/collection_spec.rb
127
+ - spec/lib/day_spec.rb
128
+ - spec/lib/month_spec.rb
129
+ - spec/lib/year_spec.rb
111
130
  - spec/spec_helper.rb
112
- - spec/year_spec.rb
data/.codeclimate.yml DELETED
@@ -1,16 +0,0 @@
1
- ---
2
- engines:
3
- duplication:
4
- enabled: true
5
- config:
6
- languages:
7
- - ruby
8
- fixme:
9
- enabled: true
10
- rubocop:
11
- enabled: true
12
- ratings:
13
- paths:
14
- - "**.rb"
15
- exclude_paths:
16
- - spec/
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe RussianWorkdays::Collection do
6
- before(:all) do
7
- @collection = RussianWorkdays::Collection.new((Date.new(2014, 1, 1)..Date.new(2014, 12, -1)))
8
- @holidays = %w[2014-01-01 2014-03-22 2014-07-12 2014-09-06 2014-10-26 2014-12-28]
9
- @preholidays = %w[2014-02-24 2014-03-07 2014-04-30 2014-05-08 2014-06-11 2014-12-31]
10
- @works = %w[2014-01-09 2014-02-03 2014-05-27 2014-07-22 2014-11-11 2014-12-30]
11
- end
12
-
13
- it "should return the right preholiday days" do
14
- preholidays = @collection.preholidays.map(&:to_s)
15
- expect(preholidays).to eq(@preholidays)
16
- end
17
-
18
- it "should return the right holydays" do
19
- holidays = @collection.holidays.map(&:to_s)
20
- expect(holidays).to include(*@holidays)
21
- end
22
-
23
- it "should return the right preholiday works" do
24
- works = @collection.works.map(&:to_s)
25
- expect(works).to include(*@works)
26
- end
27
- end
data/spec/day_spec.rb DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "date"
5
-
6
- describe RussianWorkdays::Year do
7
- before(:all) do
8
- @year = RussianWorkdays::Year.new(2014)
9
- @holidays = %w[2014-05-01 2014-05-02 2014-05-03 2014-05-04]
10
- @preholidays = %w[2014-02-24 2014-03-07 2014-04-30 2014-05-08 2014-06-11 2014-12-31]
11
- @works = %w[2014-05-05 2014-05-06 2014-05-06]
12
- end
13
-
14
- it "should return true if date is preholiday day" do
15
- @preholidays.each do |date|
16
- expect(RussianWorkdays::Day.new(Date.parse(date)).preholiday?).to eq(true)
17
- end
18
- end
19
-
20
- it "should return true if date is holiday day" do
21
- @holidays.each do |date|
22
- expect(RussianWorkdays::Day.new(Date.parse(date)).holiday?).to eq(true)
23
- end
24
- end
25
-
26
- it "should return true if date is work day" do
27
- @works.each do |date|
28
- expect(RussianWorkdays::Day.new(Date.parse(date)).work?).to eq(true)
29
- end
30
- end
31
- end
data/spec/month_spec.rb DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe RussianWorkdays::Month do
6
- before(:all) do
7
- @month = RussianWorkdays::Month.new(2014, 5)
8
- @holidays = %w[2014-05-01 2014-05-02 2014-05-03 2014-05-04]
9
- @preholidays = %w[2014-05-08]
10
- @works = %w[2014-05-05 2014-05-06 2014-05-06]
11
- end
12
-
13
- it "should return the right preholiday days" do
14
- preholidays = @month.preholidays.map(&:to_s)
15
- expect(preholidays).to eq(@preholidays)
16
- end
17
-
18
- it "should return the right holydays" do
19
- holidays = @month.holidays.map(&:to_s)
20
- expect(holidays).to include(*@holidays)
21
- end
22
-
23
- it "should return the right preholiday works" do
24
- works = @month.works.map(&:to_s)
25
- expect(works).to include(*@works)
26
- end
27
- end
data/spec/year_spec.rb DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe RussianWorkdays::Year do
6
- before(:all) do
7
- @year = RussianWorkdays::Year.new(2014)
8
- @holidays = %w[2014-05-01 2014-05-02 2014-05-03 2014-05-04]
9
- @preholidays = %w[2014-02-24 2014-03-07 2014-04-30 2014-05-08 2014-06-11 2014-12-31]
10
- @works = %w[2014-05-05 2014-05-06 2014-05-06]
11
- end
12
-
13
- it "should return the right preholiday days" do
14
- preholidays = @year.preholidays.map(&:to_s)
15
- expect(preholidays).to eq(@preholidays)
16
- end
17
-
18
- it "should return the right holydays" do
19
- holidays = @year.holidays.map(&:to_s)
20
- expect(holidays).to include(*@holidays)
21
- end
22
-
23
- it "should return the right preholiday works" do
24
- works = @year.works.map(&:to_s)
25
- expect(works).to include(*@works)
26
- end
27
- end