russian_workdays 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +74 -1075
- data/Gemfile +4 -2
- data/README.md +39 -21
- data/Rakefile +5 -3
- data/lib/russian_workdays/collection.rb +34 -0
- data/lib/russian_workdays/collection_preset.rb +8 -0
- data/lib/russian_workdays/dates.yml +333 -1984
- 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/lib/russian_workdays.rb +5 -35
- 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 +16 -4
- 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/lib/russian_workdays.rb
CHANGED
@@ -1,36 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
raise ArgumentError.new('Argument must be Date object') unless date.is_a?(Date)
|
8
|
-
dates[date.year][method].include?(date)
|
9
|
-
end
|
10
|
-
|
11
|
-
define_method("#{method}s") do |year|
|
12
|
-
has_data_for_year?(year)
|
13
|
-
dates[year][method]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def work?(date)
|
18
|
-
raise ArgumentError unless date.is_a?(Date)
|
19
|
-
!holidays(date.year).include?(date) && !shorts(date.year).include?(date)
|
20
|
-
end
|
21
|
-
|
22
|
-
def works(year)
|
23
|
-
has_data_for_year?(year)
|
24
|
-
(Date.new(year, 1, 1)..Date.new(year, 12, 31)).to_a - holidays(year) - shorts(year)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def has_data_for_year?(year)
|
29
|
-
raise ArgumentError.new('Data missing for that year') unless dates.keys.include?(year)
|
30
|
-
end
|
31
|
-
|
32
|
-
def dates
|
33
|
-
@@dates ||= YAML.load_file(File.expand_path('../russian_workdays/dates.yml', __FILE__))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
3
|
+
require_relative "russian_workdays/collection"
|
4
|
+
require_relative "russian_workdays/day"
|
5
|
+
require_relative "russian_workdays/month"
|
6
|
+
require_relative "russian_workdays/year"
|
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.0.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.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- heckfy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04
|
11
|
+
date: 2019-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,10 +68,19 @@ files:
|
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
70
|
- lib/russian_workdays.rb
|
71
|
+
- lib/russian_workdays/collection.rb
|
72
|
+
- lib/russian_workdays/collection_preset.rb
|
71
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
|
72
78
|
- russian_workdays.gemspec
|
73
|
-
- spec/
|
79
|
+
- spec/collection_spec.rb
|
80
|
+
- spec/day_spec.rb
|
81
|
+
- spec/month_spec.rb
|
74
82
|
- spec/spec_helper.rb
|
83
|
+
- spec/year_spec.rb
|
75
84
|
homepage: https://github.com/heckfy/russian_workdays
|
76
85
|
licenses:
|
77
86
|
- MIT
|
@@ -96,5 +105,8 @@ signing_key:
|
|
96
105
|
specification_version: 4
|
97
106
|
summary: Russian workdays
|
98
107
|
test_files:
|
99
|
-
- spec/
|
108
|
+
- spec/collection_spec.rb
|
109
|
+
- spec/day_spec.rb
|
110
|
+
- spec/month_spec.rb
|
100
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
|