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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 330f89c9ad7fb694db1004204254e8e6d2a4e005
4
- data.tar.gz: 22c7f49cb89ace82a0a322f24f481261f93b4a0b
2
+ SHA256:
3
+ metadata.gz: 198c72aa0c902950552cea5e56d6d974d4f55069a9d9fd07511b2a738b57696f
4
+ data.tar.gz: bee25bdfb99a06d14dfda6604c4e95f5168ed1676076eba556b27278169ee14d
5
5
  SHA512:
6
- metadata.gz: fa02a275e77b1d4984700f4b3c847d6fbcfec9eab6a38e2f2c91c93ca1fa28cea543018d1285f220c9997183342bfb14815c79da8437b6b8e8df4c4942da1227
7
- data.tar.gz: 95c3650c96fbf9c352c6de044cff643b1e1c9321e73ee0ef066f8a740be0a174c827c1b8057b6f277b460a112b2899ddd1d13f714a95feca1f44f0ce124c3ff1
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
- BankWorkingDay.end_of_month_without_holiday(date)
39
+ bank_working_day.end_of_month_without_holiday(date)
28
40
  ```
29
41
 
30
42
  #### x営業日前の日付を返す
31
43
 
32
44
  ```ruby
33
- BankWorkingDay.working_day_before(date: date, offset: offset)
45
+ bank_working_day.working_day_before(date: date, offset: offset)
34
46
  ```
35
47
 
36
48
  #### 休日か確認する
37
49
 
38
50
  ```ruby
39
- BankWorkingDay.holiday?(date)
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
-
@@ -6,49 +6,51 @@ require 'bank_working_day/holidays'
6
6
  module BankWorkingDay
7
7
  class InvalidArgumentError < StandardError; end
8
8
 
9
- def self.end_of_month_without_holiday(date)
10
- date.end_of_month.day.downto(1) do |last_day|
11
- last_day = Date.new(date.year, date.month, last_day)
12
- return last_day unless holidays.holiday?(last_day)
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
- def self.working_day_before(date: , offset: )
17
- offset.times do |i|
18
- date -= 1
19
- date -= 1 while holiday?(date)
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
- end
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
- def self.working_day_after(date: , offset: )
26
- offset.times do |i|
27
- date += 1
28
- date += 1 while holiday?(date)
29
+ date
29
30
  end
30
31
 
31
- date
32
- end
33
-
34
- def self.deduction_date(year: , month: , day: 27)
35
- raise InvalidArgumentError if year.to_i.zero? || month.to_i.zero?
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
- date = Date.new(year.to_i, month.to_i, day.to_i)
38
- while holiday?(date)
39
- date += 1
38
+ date
40
39
  end
41
40
 
42
- date
43
- end
41
+ def deduction_date(year: , month: , day: 27)
42
+ raise InvalidArgumentError if year.to_i.zero? || month.to_i.zero?
44
43
 
45
- def self.holiday?(date)
46
- holidays.holiday?(date)
47
- end
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
- private
49
+ date
50
+ end
50
51
 
51
- def self.holidays
52
- @holidays ||= Holidays.new
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('holidays.yml')
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(yml)
29
- yaml = YAML.load_file(File.expand_path("../../../#{yml}", __FILE__))
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
@@ -1,3 +1,3 @@
1
1
  module BankWorkingDay
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  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.5
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: 2016-04-05 00:00:00.000000000 Z
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.5.1
112
+ rubygems_version: 2.7.6
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: 銀行の口座振替日、振込日をよしなに取得してくれるgem