russian_workdays 2.6.0 → 2.8.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,11 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "collection_preset"
3
+ require_relative 'missing_year_error'
4
+ require_relative 'collection_preset'
4
5
 
5
6
  module RussianWorkdays
6
7
  class Year < CollectionPreset
8
+ attr_reader :year
9
+
7
10
  def initialize(year = Date.today.year)
8
- @dates = Collection.new(Date.new(year, 1, 1)..Date.new(year, 12, -1))
11
+ raise MissingYearError, year unless DATES.key?(year)
12
+
13
+ @year = year
14
+ end
15
+
16
+ private
17
+
18
+ def range
19
+ Date.new(year, 1, 1)..Date.new(year, 12, -1)
9
20
  end
10
21
  end
11
22
  end
@@ -1,6 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "russian_workdays/collection"
4
- require_relative "russian_workdays/day"
5
- require_relative "russian_workdays/month"
6
- require_relative "russian_workdays/year"
3
+ require 'yaml'
4
+ require 'date'
5
+ require_relative 'russian_workdays/collection'
6
+ require_relative 'russian_workdays/day'
7
+ require_relative 'russian_workdays/month'
8
+ require_relative 'russian_workdays/year'
9
+
10
+ module RussianWorkdays
11
+ YAML_FILE = File.read(File.join(__dir__, 'dates.yml')).freeze
12
+ DATES = YAML.safe_load(YAML_FILE, permitted_classes: [::Date, Symbol]).freeze
13
+
14
+ private_constant :YAML_FILE
15
+ end
@@ -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(:instance_of_day) { described_class.new(date) }
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 { instance_of_day }.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 { instance_of_day }
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
+ expect(instance_of_day.work?).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
+ expect(instance_of_day.work?).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
+ expect(instance_of_day.work?).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(instance_of_day.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(instance_of_day.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(instance_of_day.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(instance_of_day.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(instance_of_day.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(instance_of_day.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(instance_of_day.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(instance_of_day.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(instance_of_day.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,13 @@
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.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - heckfy
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-11-26 00:00:00.000000000 Z
10
+ date: 2025-09-05 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -16,76 +15,93 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.6'
18
+ version: '2.4'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.6'
25
+ version: '2.4'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - ">="
30
+ - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '0'
32
+ version: '13.2'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - ">="
37
+ - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '0'
39
+ version: '13.2'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - ">="
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.1'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rubocop
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
46
59
  - !ruby/object:Gem::Version
47
- version: '0'
60
+ version: 1.71.1
48
61
  type: :development
49
62
  prerelease: false
50
63
  version_requirements: !ruby/object:Gem::Requirement
51
64
  requirements:
52
- - - ">="
65
+ - - "~>"
53
66
  - !ruby/object:Gem::Version
54
- version: '0'
67
+ version: 1.71.1
55
68
  description: Производственный календарь РФ
56
69
  email:
57
70
  - heckfyoz@gmail.com
58
- executables: []
71
+ executables:
72
+ - console
73
+ - setup
59
74
  extensions: []
60
75
  extra_rdoc_files: []
61
76
  files:
62
- - ".codeclimate.yml"
63
77
  - ".gitignore"
64
78
  - ".rubocop.yml"
65
- - ".travis.yml"
79
+ - CHANGELOG.md
66
80
  - Gemfile
67
81
  - LICENSE.txt
68
82
  - README.md
69
83
  - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/dates.yml
70
87
  - lib/russian_workdays.rb
71
88
  - lib/russian_workdays/collection.rb
72
89
  - lib/russian_workdays/collection_preset.rb
73
- - lib/russian_workdays/dates.yml
74
90
  - lib/russian_workdays/day.rb
91
+ - lib/russian_workdays/missing_year_error.rb
75
92
  - lib/russian_workdays/month.rb
76
93
  - lib/russian_workdays/version.rb
77
94
  - lib/russian_workdays/year.rb
78
95
  - russian_workdays.gemspec
79
- - spec/collection_spec.rb
80
- - spec/day_spec.rb
81
- - spec/month_spec.rb
96
+ - spec/lib/collection_spec.rb
97
+ - spec/lib/day_spec.rb
98
+ - spec/lib/month_spec.rb
99
+ - spec/lib/year_spec.rb
82
100
  - spec/spec_helper.rb
83
- - spec/year_spec.rb
84
101
  homepage: https://github.com/heckfy/russian_workdays
85
102
  licenses:
86
103
  - MIT
87
104
  metadata: {}
88
- post_install_message:
89
105
  rdoc_options: []
90
106
  require_paths:
91
107
  - lib
@@ -93,20 +109,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
109
  requirements:
94
110
  - - ">="
95
111
  - !ruby/object:Gem::Version
96
- version: '0'
112
+ version: 2.6.0
97
113
  required_rubygems_version: !ruby/object:Gem::Requirement
98
114
  requirements:
99
115
  - - ">="
100
116
  - !ruby/object:Gem::Version
101
117
  version: '0'
102
118
  requirements: []
103
- rubygems_version: 3.1.4
104
- signing_key:
119
+ rubygems_version: 3.6.2
105
120
  specification_version: 4
106
121
  summary: Russian workdays
107
122
  test_files:
108
- - spec/collection_spec.rb
109
- - spec/day_spec.rb
110
- - spec/month_spec.rb
123
+ - spec/lib/collection_spec.rb
124
+ - spec/lib/day_spec.rb
125
+ - spec/lib/month_spec.rb
126
+ - spec/lib/year_spec.rb
111
127
  - 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