bank_working_day 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +15 -4
- data/lib/bank_working_day.rb +33 -31
- data/lib/bank_working_day/holidays.rb +5 -5
- data/lib/bank_working_day/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 198c72aa0c902950552cea5e56d6d974d4f55069a9d9fd07511b2a738b57696f
|
4
|
+
data.tar.gz: bee25bdfb99a06d14dfda6604c4e95f5168ed1676076eba556b27278169ee14d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed9ef77540eac413412d5b08dee56207412482aaef5566759b5d90a5d1ac2ad3ff158a15977c93b22a2ca66a4fe67f5d74d7226dc03873304cf5e807b34694c
|
7
|
+
data.tar.gz: 7eb6f64aea27aaac359246691cdef1f52b38b4f122578b32d6d0c4f10a266043f7485d38d2bdd5a830ccb631c344a254eac6f17eaeb580a569b4e869a24cd87e
|
data/README.md
CHANGED
@@ -21,22 +21,34 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
#### 初期化
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
bank_working_day = BankWorkingDay::Base.new()
|
28
|
+
```
|
29
|
+
|
30
|
+
祝日の情報をオーバーライドしたい場合はYAMLファイルのパスを渡す
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
bank_working_day = BankWorkingDay::Base.new('/path/to/holidays.yml')
|
34
|
+
```
|
35
|
+
|
24
36
|
#### 銀行における月の最終営業日を返す
|
25
37
|
|
26
38
|
```ruby
|
27
|
-
|
39
|
+
bank_working_day.end_of_month_without_holiday(date)
|
28
40
|
```
|
29
41
|
|
30
42
|
#### x営業日前の日付を返す
|
31
43
|
|
32
44
|
```ruby
|
33
|
-
|
45
|
+
bank_working_day.working_day_before(date: date, offset: offset)
|
34
46
|
```
|
35
47
|
|
36
48
|
#### 休日か確認する
|
37
49
|
|
38
50
|
```ruby
|
39
|
-
|
51
|
+
bank_working_day.holiday?(date)
|
40
52
|
```
|
41
53
|
|
42
54
|
## Development
|
@@ -53,4 +65,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
53
65
|
## License
|
54
66
|
|
55
67
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
56
|
-
|
data/lib/bank_working_day.rb
CHANGED
@@ -6,49 +6,51 @@ require 'bank_working_day/holidays'
|
|
6
6
|
module BankWorkingDay
|
7
7
|
class InvalidArgumentError < StandardError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
class Base
|
10
|
+
attr_accessor :holidays
|
11
|
+
|
12
|
+
def initialize(holidays_yml_path='../../../holidays.yml')
|
13
|
+
@holidays ||= Holidays.new(holidays_yml_path)
|
13
14
|
end
|
14
|
-
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def end_of_month_without_holiday(date)
|
17
|
+
date.end_of_month.day.downto(1) do |last_day|
|
18
|
+
last_day = Date.new(date.year, date.month, last_day)
|
19
|
+
return last_day unless holiday?(last_day)
|
20
|
+
end
|
20
21
|
end
|
21
22
|
|
22
|
-
date
|
23
|
-
|
23
|
+
def working_day_before(date: , offset: )
|
24
|
+
offset.times do |i|
|
25
|
+
date -= 1
|
26
|
+
date -= 1 while holiday?(date)
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
offset.times do |i|
|
27
|
-
date += 1
|
28
|
-
date += 1 while holiday?(date)
|
29
|
+
date
|
29
30
|
end
|
30
31
|
|
31
|
-
date
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def working_day_after(date: , offset: )
|
33
|
+
offset.times do |i|
|
34
|
+
date += 1
|
35
|
+
date += 1 while holiday?(date)
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
while holiday?(date)
|
39
|
-
date += 1
|
38
|
+
date
|
40
39
|
end
|
41
40
|
|
42
|
-
|
43
|
-
|
41
|
+
def deduction_date(year: , month: , day: 27)
|
42
|
+
raise InvalidArgumentError if year.to_i.zero? || month.to_i.zero?
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
date = Date.new(year.to_i, month.to_i, day.to_i)
|
45
|
+
while holiday?(date)
|
46
|
+
date += 1
|
47
|
+
end
|
48
48
|
|
49
|
-
|
49
|
+
date
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
def holiday?(date)
|
53
|
+
holidays.holiday?(date)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
@@ -14,9 +14,9 @@ module BankWorkingDay
|
|
14
14
|
|
15
15
|
HOLIDAY_WDAYS = [0, 6].freeze
|
16
16
|
|
17
|
-
def initialize
|
18
|
-
@holidays = set_holiday(
|
19
|
-
@bank_holidays = set_holiday('bank_holidays.yml')
|
17
|
+
def initialize(holidays_yml_path)
|
18
|
+
@holidays = set_holiday(holidays_yml_path)
|
19
|
+
@bank_holidays = set_holiday('../../../bank_holidays.yml')
|
20
20
|
end
|
21
21
|
|
22
22
|
def holiday?(date)
|
@@ -25,8 +25,8 @@ module BankWorkingDay
|
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
def set_holiday(
|
29
|
-
yaml = YAML.load_file(File.expand_path(
|
28
|
+
def set_holiday(path)
|
29
|
+
yaml = YAML.load_file(File.expand_path(path, __FILE__))
|
30
30
|
yaml.each_with_object({}) do |(key, value), hash|
|
31
31
|
hash[key] = Holiday.new(key, value)
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank_working_day
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morioka Shuhei
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.7.6
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: 銀行の口座振替日、振込日をよしなに取得してくれるgem
|