increments-schedule 0.3.0 → 0.4.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 +4 -4
- data/README.md +33 -9
- data/README.md.erb +67 -0
- data/Rakefile +34 -1
- data/lib/increments/schedule.rb +25 -25
- data/lib/increments/schedule/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b8c9a536348bdcdb4ba014247949c1d75702d32
|
4
|
+
data.tar.gz: 897a83acff15520acd8894a84ad9f59b87b04c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a264fc1c3822c9c9576eef0be7bff725965fdd5ab7614de7238c30a12f079e5e92d91f453920f5dfe8065ac43b0e7312ccce6e8cf66b8ac27937626f30f805fd
|
7
|
+
data.tar.gz: a40ad96539b574c50eae7ed418bb4b2e9a0410583ccf22b46ea64df02c86ecd687840953113e95b756a8ba66a99e8742beb35f54227b6fcb47b9deb85df02d07
|
data/README.md
CHANGED
@@ -16,19 +16,43 @@ gem 'increments-schedule'
|
|
16
16
|
|
17
17
|
And then execute:
|
18
18
|
|
19
|
-
|
19
|
+
```bash
|
20
|
+
$ bundle
|
21
|
+
```
|
20
22
|
|
21
23
|
Or install it yourself as:
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
```bash
|
26
|
+
$ gem install increments-schedule
|
27
|
+
```
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
* `Increments::Schedule.
|
29
|
+
## APIs
|
30
|
+
|
31
|
+
### Predicate Methods
|
32
|
+
|
33
|
+
* `Increments::Schedule.super_hanakin?(date)`
|
34
|
+
* `Increments::Schedule.pay_day?(date)`
|
35
|
+
* `Increments::Schedule.work_day?(date)`
|
36
|
+
* `Increments::Schedule.office_work_day?(date)`
|
37
|
+
* `Increments::Schedule.remote_work_day?(date)`
|
38
|
+
* `Increments::Schedule.normal_remote_work_day?(date)`
|
39
|
+
* `Increments::Schedule.special_remote_work_day?(date)`
|
40
|
+
* `Increments::Schedule.rest_day?(date)`
|
41
|
+
* `Increments::Schedule.weekend?(date)`
|
42
|
+
* `Increments::Schedule.holiday?(date)`
|
43
|
+
|
44
|
+
### Enumeration Methods
|
45
|
+
|
46
|
+
* `Increments::Schedule.each_super_hanakin(max_date = Date.today + 365)`
|
47
|
+
* `Increments::Schedule.each_pay_day(max_date = Date.today + 365)`
|
48
|
+
* `Increments::Schedule.each_work_day(max_date = Date.today + 365)`
|
49
|
+
* `Increments::Schedule.each_office_work_day(max_date = Date.today + 365)`
|
50
|
+
* `Increments::Schedule.each_remote_work_day(max_date = Date.today + 365)`
|
51
|
+
* `Increments::Schedule.each_normal_remote_work_day(max_date = Date.today + 365)`
|
52
|
+
* `Increments::Schedule.each_special_remote_work_day(max_date = Date.today + 365)`
|
53
|
+
* `Increments::Schedule.each_rest_day(max_date = Date.today + 365)`
|
54
|
+
* `Increments::Schedule.each_weekend(max_date = Date.today + 365)`
|
55
|
+
* `Increments::Schedule.each_holiday(max_date = Date.today + 365)`
|
32
56
|
|
33
57
|
## Development
|
34
58
|
|
data/README.md.erb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
[](http://badge.fury.io/rb/increments-schedule)
|
2
|
+
[](https://gemnasium.com/increments/increments-schedule)
|
3
|
+
[](https://travis-ci.org/increments/increments-schedule)
|
4
|
+
|
5
|
+
# Increments::Schedule
|
6
|
+
|
7
|
+
Find out our special remote days and eagerly wait for them!
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'increments-schedule'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ gem install increments-schedule
|
27
|
+
```
|
28
|
+
|
29
|
+
## APIs
|
30
|
+
|
31
|
+
### Predicate Methods
|
32
|
+
|
33
|
+
<%=
|
34
|
+
methods = Increments::Schedule.public_instance_methods.select do |method|
|
35
|
+
method.to_s.end_with?('?')
|
36
|
+
end
|
37
|
+
|
38
|
+
methods.map do |method|
|
39
|
+
"* `Increments::Schedule.#{method}(date)`"
|
40
|
+
end.join("\n")
|
41
|
+
%>
|
42
|
+
|
43
|
+
### Enumeration Methods
|
44
|
+
|
45
|
+
<%=
|
46
|
+
methods = Increments::Schedule.public_instance_methods.select do |method|
|
47
|
+
method.to_s.start_with?('each_')
|
48
|
+
end
|
49
|
+
|
50
|
+
methods.map do |method|
|
51
|
+
"* `Increments::Schedule.#{method}(max_date = Date.today + 365)`"
|
52
|
+
end.join("\n")
|
53
|
+
%>
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it ( https://github.com/[my-github-username]/increments-schedule/fork )
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
@@ -8,4 +8,37 @@ end
|
|
8
8
|
|
9
9
|
RuboCop::RakeTask.new
|
10
10
|
|
11
|
-
|
11
|
+
desc 'Generate README.md from README.md.erb'
|
12
|
+
task :readme do
|
13
|
+
puts 'Generating README.md...'
|
14
|
+
File.write('README.md', generate_readme)
|
15
|
+
puts 'Done.'
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :readme do
|
19
|
+
task :validate do
|
20
|
+
puts 'Validating README.md...'
|
21
|
+
|
22
|
+
unless File.read('README.md') == generate_readme
|
23
|
+
fail <<-END.gsub(/^\s+\|/, '').chomp
|
24
|
+
|README.md and README.md.erb are out of sync!
|
25
|
+
|If you need to modify the content of README.md:
|
26
|
+
| * Edit README.md.erb.
|
27
|
+
| * Run `bundle exec rake readme`.
|
28
|
+
| * Commit both files.
|
29
|
+
END
|
30
|
+
end
|
31
|
+
|
32
|
+
puts 'Done.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_readme
|
37
|
+
require 'erb'
|
38
|
+
require 'increments/schedule'
|
39
|
+
readme = File.read('README.md.erb')
|
40
|
+
erb = ERB.new(readme, nil, '-')
|
41
|
+
erb.result(binding)
|
42
|
+
end
|
43
|
+
|
44
|
+
task ci: %w(spec rubocop readme:validate)
|
data/lib/increments/schedule.rb
CHANGED
@@ -5,30 +5,12 @@ module Increments
|
|
5
5
|
module Schedule
|
6
6
|
extend self # rubocop:disable ModuleFunction
|
7
7
|
|
8
|
-
[
|
9
|
-
[:each_super_hanakin, :super_hanakin?],
|
10
|
-
[:each_pay_day, :pay_day?],
|
11
|
-
[:each_remote_work_day, :remote_work_day?],
|
12
|
-
[:each_normal_remote_work_day, :normal_remote_work_day?],
|
13
|
-
[:each_special_remote_work_day, :special_remote_work_day?]
|
14
|
-
].each do |enumeration_method, predicate_method|
|
15
|
-
define_method(enumeration_method) do |max_date = nil, &block|
|
16
|
-
return to_enum(__method__, max_date) unless block
|
17
|
-
|
18
|
-
max_date ||= Date.today + 365
|
19
|
-
|
20
|
-
Date.today.upto(max_date) do |date|
|
21
|
-
block.call(date) if send(predicate_method, date)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
8
|
def super_hanakin?(date)
|
27
|
-
pay_day?(date)
|
9
|
+
date.friday? && pay_day?(date)
|
28
10
|
end
|
29
11
|
|
30
12
|
def pay_day?(date)
|
31
|
-
return
|
13
|
+
return work_day?(date) if date.day == 25
|
32
14
|
next_basic_pay_day = Date.new(date.year, date.month, 25)
|
33
15
|
next_basic_pay_day = next_basic_pay_day.next_month if date > next_basic_pay_day
|
34
16
|
date.next_day.upto(next_basic_pay_day).all? do |date_until_basic_pay_day|
|
@@ -36,12 +18,20 @@ module Increments
|
|
36
18
|
end
|
37
19
|
end
|
38
20
|
|
21
|
+
def work_day?(date)
|
22
|
+
!rest_day?(date)
|
23
|
+
end
|
24
|
+
|
25
|
+
def office_work_day?(date)
|
26
|
+
work_day?(date) && !remote_work_day?(date)
|
27
|
+
end
|
28
|
+
|
39
29
|
def remote_work_day?(date)
|
40
30
|
normal_remote_work_day?(date) || special_remote_work_day?(date)
|
41
31
|
end
|
42
32
|
|
43
33
|
def normal_remote_work_day?(date)
|
44
|
-
date.monday? &&
|
34
|
+
date.monday? && work_day?(date)
|
45
35
|
end
|
46
36
|
|
47
37
|
def special_remote_work_day?(date)
|
@@ -49,10 +39,6 @@ module Increments
|
|
49
39
|
!normal_office_work_day?(date - 1) && !normal_office_work_day?(date + 1)
|
50
40
|
end
|
51
41
|
|
52
|
-
def office_work_day?(date)
|
53
|
-
!rest_day?(date) && !remote_work_day?(date)
|
54
|
-
end
|
55
|
-
|
56
42
|
def rest_day?(date)
|
57
43
|
weekend?(date) || holiday?(date)
|
58
44
|
end
|
@@ -65,6 +51,20 @@ module Increments
|
|
65
51
|
HolidayJapan.check(date)
|
66
52
|
end
|
67
53
|
|
54
|
+
public_instance_methods.select { |name| name.to_s.end_with?('?') }.each do |predicate_method|
|
55
|
+
enumeration_method = 'each_' + predicate_method.to_s.sub(/\?\z/, '')
|
56
|
+
|
57
|
+
define_method(enumeration_method) do |max_date = nil, &block|
|
58
|
+
return to_enum(__method__, max_date) unless block
|
59
|
+
|
60
|
+
max_date ||= Date.today + 365
|
61
|
+
|
62
|
+
Date.today.upto(max_date) do |date|
|
63
|
+
block.call(date) if send(predicate_method, date)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
68
|
private
|
69
69
|
|
70
70
|
def normal_office_work_day?(date)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: increments-schedule
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: holiday_japan
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- Gemfile
|
53
53
|
- LICENSE.txt
|
54
54
|
- README.md
|
55
|
+
- README.md.erb
|
55
56
|
- Rakefile
|
56
57
|
- bin/console
|
57
58
|
- bin/setup
|