increments-schedule 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 501eab35a37755a0835d33c702bc318210c03cba
4
- data.tar.gz: e3b4f292a2330768e3b339f351b158120e024ec1
3
+ metadata.gz: 9b8c9a536348bdcdb4ba014247949c1d75702d32
4
+ data.tar.gz: 897a83acff15520acd8894a84ad9f59b87b04c78
5
5
  SHA512:
6
- metadata.gz: f3c1f0c47e3dbae0b1274b99135cc9483e2c032feafc39cf6edac3e9b23f38999eb553c85992c8dbab880fe4fa332c38dea45418898a782939de5d129772b2c7
7
- data.tar.gz: 1e2a41b3290928493cc03a35cedbaa4d7e044c44da87e3c7b06f8217a9e8e63ca0ceaaeb5b81848e4c7d46c229fc739210375f89ba26f2a1e546cd23125eb9c3
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
- $ bundle
19
+ ```bash
20
+ $ bundle
21
+ ```
20
22
 
21
23
  Or install it yourself as:
22
24
 
23
- $ gem install increments-schedule
24
-
25
- ## Usage
25
+ ```bash
26
+ $ gem install increments-schedule
27
+ ```
26
28
 
27
- * `Increments::Schedule.each_super_hanakin`
28
- * `Increments::Schedule.each_pay_day`
29
- * `Increments::Schedule.each_remote_work_day`
30
- * `Increments::Schedule.each_normal_remote_work_day`
31
- * `Increments::Schedule.each_special_remote_work_day`
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
+ [![Gem Version](http://img.shields.io/gem/v/increments-schedule.svg?style=flat)](http://badge.fury.io/rb/increments-schedule)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/increments/increments-schedule.svg?style=flat)](https://gemnasium.com/increments/increments-schedule)
3
+ [![Build Status](https://travis-ci.org/increments/increments-schedule.svg?branch=master&style=flat)](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
- task ci: [:spec, :rubocop]
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)
@@ -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) && date.friday?
9
+ date.friday? && pay_day?(date)
28
10
  end
29
11
 
30
12
  def pay_day?(date)
31
- return !rest_day?(date) if date.day == 25
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? && !rest_day?(date)
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)
@@ -1,5 +1,5 @@
1
1
  module Increments
2
2
  module Schedule
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
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.3.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-24 00:00:00.000000000 Z
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