work_calendar 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8960c4113c6d74c1cbc16b1d2ea7cb58a4e1ba05a72b0a79ac242f18e04a2764
4
+ data.tar.gz: 020e7536bf84ad209ede89b0da01c868acd96189032b46ebb568eedc059bd98e
5
+ SHA512:
6
+ metadata.gz: e8af312727ff6f04c33c315aa591d0df5b744934ead8f1892cda699f2184f01a3a11fe802eb470222dd8ef24f5ce03aa5834ec4837352c7d44228080632ec9dc
7
+ data.tar.gz: bc5a1d59dffeecc066534298d274611236c3a8f10ae10240a849ffc34c56626c2af1837ac209ff984c9b9f3cdf12a2d76c1d9744c453b3d8fcdd18f8fabbf1e9
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,49 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6.2
6
+ DisplayCopNames: true
7
+ Exclude:
8
+ - "bin/*"
9
+
10
+ Style/DocumentationMethod:
11
+ RequireForNonPublicMethods: false
12
+
13
+ Documentation:
14
+ Enabled: false
15
+
16
+ Metrics/LineLength:
17
+ Max: 100
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: single_quotes
21
+
22
+ Naming/UncommunicativeMethodParamName:
23
+ AllowedNames: [io, id, to, by, on, in, at, ip, db, cv]
24
+
25
+ # Disable metrics cops
26
+
27
+ Metrics/MethodLength:
28
+ Enabled: false
29
+
30
+ Metrics/AbcSize:
31
+ Enabled: false
32
+
33
+ Metrics/BlockLength:
34
+ Enabled: false
35
+
36
+ Metrics/BlockNesting:
37
+ Enabled: false
38
+
39
+ Metrics/ClassLength:
40
+ Enabled: false
41
+
42
+ Metrics/CyclomaticComplexity:
43
+ Enabled: false
44
+
45
+ Metrics/ModuleLength:
46
+ Enabled: false
47
+
48
+ Metrics/PerceivedComplexity:
49
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in work_calendar.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ work_calendar (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.0.0.rc1)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ zeitwerk (~> 2.1, >= 2.1.4)
15
+ ast (2.4.0)
16
+ concurrent-ruby (1.1.5)
17
+ i18n (1.6.0)
18
+ concurrent-ruby (~> 1.0)
19
+ jaro_winkler (1.5.2)
20
+ minitest (5.11.3)
21
+ parallel (1.17.0)
22
+ parser (2.6.3.0)
23
+ ast (~> 2.4.0)
24
+ rainbow (3.0.0)
25
+ rake (10.5.0)
26
+ rubocop (0.71.0)
27
+ jaro_winkler (~> 1.5.1)
28
+ parallel (~> 1.10)
29
+ parser (>= 2.6)
30
+ rainbow (>= 2.2.2, < 4.0)
31
+ ruby-progressbar (~> 1.7)
32
+ unicode-display_width (>= 1.4.0, < 1.7)
33
+ rubocop-performance (1.3.0)
34
+ rubocop (>= 0.68.0)
35
+ ruby-progressbar (1.10.1)
36
+ thread_safe (0.3.6)
37
+ tzinfo (1.2.5)
38
+ thread_safe (~> 0.1)
39
+ unicode-display_width (1.6.0)
40
+ zeitwerk (2.1.9)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ activesupport
47
+ bundler (~> 2.0)
48
+ minitest (~> 5.0)
49
+ rake (~> 10.0)
50
+ rubocop
51
+ rubocop-performance
52
+ work_calendar!
53
+
54
+ BUNDLED WITH
55
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # WorkCalendar
2
+
3
+ Simple yet effective gem for calculating workday `Time` objects.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'work_calendar'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install work_calendar
20
+
21
+ ## Usage
22
+
23
+ Check if specified date is workday. If no `date` parameter was passed it checks current day:
24
+
25
+ ```ruby
26
+ WorkCalendar.workday?(date)
27
+ ```
28
+
29
+ Get next `n`'th workday date relative to specified date; if no `date` parameter was passed, it returns value relative to current day; if no `n` parameter was passed, it defaults to first next workday:
30
+
31
+ ```ruby
32
+ WorkCalendar.next_workday(n, date)
33
+ ```
34
+
35
+ Works the same as `next_workday`, only looking backwards instead:
36
+
37
+ ```ruby
38
+ WorkCalendar.prev_workday(n, date)
39
+ ```
40
+
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'work_calendar'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'work_calendar/version'
4
+ require 'active_support/time'
5
+
6
+ module WorkCalendar
7
+ SPECIAL_DAYS = {
8
+ 2018 => {
9
+ 12 => {
10
+ workdays: [29],
11
+ holidays: [31]
12
+ }
13
+ },
14
+ 2019 => {
15
+ 1 => {
16
+ holidays: [1, 2, 3, 4, 7, 8]
17
+ },
18
+ 3 => {
19
+ holidays: [8]
20
+ },
21
+ 5 => {
22
+ holidays: [1, 2, 3, 9, 10]
23
+ },
24
+ 6 => {
25
+ holidays: [12]
26
+ },
27
+ 11 => {
28
+ holidays: [4]
29
+ }
30
+ },
31
+ 2020 => {
32
+ 1 => {
33
+ holidays: [1, 2, 3, 6, 7, 8]
34
+ },
35
+ 2 => {
36
+ holidays: [24]
37
+ },
38
+ 3 => {
39
+ holidays: [9]
40
+ },
41
+ 5 => {
42
+ holidays: [1, 4, 5, 11]
43
+ },
44
+ 6 => {
45
+ holidays: [12]
46
+ },
47
+ 11 => {
48
+ holidays: [4]
49
+ }
50
+ }
51
+ }.freeze
52
+
53
+ class << self
54
+ def workday?(date = Time.zone.today)
55
+ year_hash = SPECIAL_DAYS[date.year]
56
+ if year_hash
57
+ month_hash = year_hash[date.month]
58
+ if month_hash
59
+ holidays = month_hash[:holidays]
60
+ return false if holidays&.include?(date.day)
61
+
62
+ workdays = month_hash[:workdays]
63
+ return true if workdays&.include?(date.day)
64
+ end
65
+ end
66
+ (1..5).cover?(date.wday)
67
+ end
68
+
69
+ def next_workday(num = 1, date = Time.zone.today)
70
+ num.times { date = _next_workday(date) }
71
+ date
72
+ end
73
+
74
+ def prev_workday(date = Time.zone.today)
75
+ prev_date = date - 1.day
76
+ prev_date -= 1.day until workday? prev_date
77
+ prev_date
78
+ end
79
+
80
+ private
81
+
82
+ def _next_workday(date)
83
+ next_date = date + 1.day
84
+ next_date += 1.day until workday? next_date
85
+ next_date
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkCalendar
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'work_calendar/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'work_calendar'
9
+ spec.version = WorkCalendar::VERSION
10
+ spec.authors = ['Sergey Tomashevsky']
11
+ spec.email = ['sergey.tomashevsky@toughbyte.com']
12
+
13
+ spec.summary = 'Workday calculator'
14
+ spec.description = 'Simple yet effective gem for calculating workday Time objects.'
15
+ spec.homepage = 'https://github.com/toughbyte/work_calendar'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/toughbyte/work_calendar'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'activesupport', '~>6.0'
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'minitest', '~> 5.0'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rubocop', '~>0.71'
35
+ spec.add_development_dependency 'rubocop-performance', '~>1.3.0'
36
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: work_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Tomashevsky
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.71'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.71'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.0
97
+ description: Simple yet effective gem for calculating workday Time objects.
98
+ email:
99
+ - sergey.tomashevsky@toughbyte.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/work_calendar.rb
115
+ - lib/work_calendar/version.rb
116
+ - work_calendar.gemspec
117
+ homepage: https://github.com/toughbyte/work_calendar
118
+ licenses:
119
+ - MIT
120
+ metadata:
121
+ homepage_uri: https://github.com/toughbyte/work_calendar
122
+ source_code_uri: https://github.com/toughbyte/work_calendar
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.0.4
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Workday calculator
142
+ test_files: []