russian_workdays 1.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +16 -0
- data/.rubocop.yml +155 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -2
- data/README.md +42 -21
- data/Rakefile +5 -3
- data/lib/russian_workdays.rb +5 -35
- data/lib/russian_workdays/collection.rb +34 -0
- data/lib/russian_workdays/collection_preset.rb +8 -0
- data/lib/russian_workdays/dates.yml +403 -1732
- data/lib/russian_workdays/day.rb +39 -0
- data/lib/russian_workdays/month.rb +12 -0
- data/lib/russian_workdays/version.rb +5 -0
- data/lib/russian_workdays/year.rb +11 -0
- data/russian_workdays.gemspec +15 -14
- data/spec/collection_spec.rb +27 -0
- data/spec/day_spec.rb +31 -0
- data/spec/month_spec.rb +27 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/year_spec.rb +27 -0
- metadata +24 -10
- data/spec/russian_workdays_spec.rb +0 -39
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module RussianWorkdays
|
6
|
+
DATES = YAML.load_file(File.join(__dir__, "dates.yml")).freeze
|
7
|
+
|
8
|
+
class Day
|
9
|
+
def initialize(date)
|
10
|
+
@date = date
|
11
|
+
raise ArgumentError, "Must be a Date object" unless @date.is_a?(::Date)
|
12
|
+
raise ArgumentError, "Data missing for that year" unless DATES.key?(@date.year)
|
13
|
+
end
|
14
|
+
|
15
|
+
def holiday?
|
16
|
+
!preholiday? && (weekend? || DATES[@date.year][:holidays].include?(@date))
|
17
|
+
end
|
18
|
+
|
19
|
+
def preholiday?
|
20
|
+
DATES[@date.year][:preholidays].include?(@date)
|
21
|
+
end
|
22
|
+
|
23
|
+
def work?
|
24
|
+
!holiday?
|
25
|
+
end
|
26
|
+
|
27
|
+
def type
|
28
|
+
return :holiday if holiday?
|
29
|
+
return :preholiday if preholiday?
|
30
|
+
return :work if work?
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def weekend?
|
36
|
+
@date.sunday? || @date.saturday?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "collection_preset"
|
4
|
+
|
5
|
+
module RussianWorkdays
|
6
|
+
class Month < CollectionPreset
|
7
|
+
def initialize(year = Date.today.year, month = 1)
|
8
|
+
raise ArgumentError, "Must be a number between 1 and 12" unless (1..12).include?(month)
|
9
|
+
@dates = Collection.new(Date.new(year, month, 1)..Date.new(year, month, -1))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "collection_preset"
|
4
|
+
|
5
|
+
module RussianWorkdays
|
6
|
+
class Year < CollectionPreset
|
7
|
+
def initialize(year = Date.today.year)
|
8
|
+
@dates = Collection.new(Date.new(year, 1, 1)..Date.new(year, 12, -1))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/russian_workdays.gemspec
CHANGED
@@ -1,23 +1,24 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
|
5
6
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
7
|
-
spec.version =
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
-
spec.summary =
|
11
|
-
spec.description =
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
7
|
+
spec.name = "russian_workdays"
|
8
|
+
spec.version = "2.4.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"
|
14
15
|
|
15
16
|
spec.files = `git ls-files -z`.split("\x0")
|
16
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ["lib"]
|
19
20
|
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
23
24
|
end
|
@@ -0,0 +1,27 @@
|
|
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
ADDED
@@ -0,0 +1,31 @@
|
|
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
ADDED
@@ -0,0 +1,27 @@
|
|
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/spec_helper.rb
CHANGED
data/spec/year_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
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:
|
4
|
+
version: 2.4.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:
|
11
|
+
date: 2020-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,28 +52,40 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: Производственный календарь РФ
|
56
56
|
email:
|
57
57
|
- heckfyoz@gmail.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".codeclimate.yml"
|
62
63
|
- ".gitignore"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".travis.yml"
|
63
66
|
- Gemfile
|
64
67
|
- LICENSE.txt
|
65
68
|
- README.md
|
66
69
|
- Rakefile
|
67
70
|
- lib/russian_workdays.rb
|
71
|
+
- lib/russian_workdays/collection.rb
|
72
|
+
- lib/russian_workdays/collection_preset.rb
|
68
73
|
- lib/russian_workdays/dates.yml
|
74
|
+
- lib/russian_workdays/day.rb
|
75
|
+
- lib/russian_workdays/month.rb
|
76
|
+
- lib/russian_workdays/version.rb
|
77
|
+
- lib/russian_workdays/year.rb
|
69
78
|
- russian_workdays.gemspec
|
70
|
-
- spec/
|
79
|
+
- spec/collection_spec.rb
|
80
|
+
- spec/day_spec.rb
|
81
|
+
- spec/month_spec.rb
|
71
82
|
- spec/spec_helper.rb
|
83
|
+
- spec/year_spec.rb
|
72
84
|
homepage: https://github.com/heckfy/russian_workdays
|
73
85
|
licenses:
|
74
86
|
- MIT
|
75
87
|
metadata: {}
|
76
|
-
post_install_message:
|
88
|
+
post_install_message:
|
77
89
|
rdoc_options: []
|
78
90
|
require_paths:
|
79
91
|
- lib
|
@@ -88,11 +100,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
100
|
- !ruby/object:Gem::Version
|
89
101
|
version: '0'
|
90
102
|
requirements: []
|
91
|
-
|
92
|
-
|
93
|
-
signing_key:
|
103
|
+
rubygems_version: 3.1.2
|
104
|
+
signing_key:
|
94
105
|
specification_version: 4
|
95
106
|
summary: Russian workdays
|
96
107
|
test_files:
|
97
|
-
- spec/
|
108
|
+
- spec/collection_spec.rb
|
109
|
+
- spec/day_spec.rb
|
110
|
+
- spec/month_spec.rb
|
98
111
|
- spec/spec_helper.rb
|
112
|
+
- spec/year_spec.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RussianWorkdays do
|
4
|
-
before(:all) do
|
5
|
-
@shorts = %w(2014-02-24 2014-03-07 2014-04-30 2014-05-08 2014-06-11 2014-12-31)
|
6
|
-
@holidays = %w(2014-01-01 2014-03-22 2014-07-12 2014-09-06 2014-10-26 2014-12-28)
|
7
|
-
@works = %w(2014-01-09 2014-02-03 2014-05-27 2014-07-22 2014-11-11 2014-12-30)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should return the right short days' do
|
11
|
-
expect(RussianWorkdays.shorts(2014).map(&:to_s)).to eq(@shorts)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should return the right holydays' do
|
15
|
-
expect(RussianWorkdays.holidays(2014).map(&:to_s)).to include(*@holidays)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should return the right short works' do
|
19
|
-
expect(RussianWorkdays.works(2014).map(&:to_s)).to include(*@works)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should return true if date is short day' do
|
23
|
-
@shorts.each do |date|
|
24
|
-
expect(RussianWorkdays.short?(Date.parse(date))).to eq(true)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should return true if date is holiday day' do
|
29
|
-
@holidays.each do |date|
|
30
|
-
expect(RussianWorkdays.holiday?(Date.parse(date))).to eq(true)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should return true if date is work day' do
|
35
|
-
@works.each do |date|
|
36
|
-
expect(RussianWorkdays.work?(Date.parse(date))).to eq(true)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|