bank_working_day 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'yaml'
3
+
4
+ module BankWorkingDay
5
+ class Holiday
6
+ def initialize(date, name)
7
+ @date = date
8
+ @name = name
9
+ end
10
+ end
11
+
12
+ class Holidays
13
+ attr_accessor :holidays, :bank_holidays
14
+
15
+ HOLIDAY_WDAYS = [0, 6].freeze
16
+
17
+ def initialize
18
+ @holidays = set_holiday('holidays.yml')
19
+ @bank_holidays = set_holiday('bank_holidays.yml')
20
+ end
21
+
22
+ def holiday?(date)
23
+ holidays[date] || bank_holidays[date] || date.wday.in?(HOLIDAY_WDAYS)
24
+ end
25
+
26
+ private
27
+
28
+ def set_holiday(yml)
29
+ yaml = YAML.load_file(File.expand_path("../../../#{yml}", __FILE__))
30
+ yaml.each_with_object({}) do |(key, value), hash|
31
+ hash[key] = Holiday.new(key, value)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module BankWorkingDay
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'bank_working_day/version'
4
+ require 'bank_working_day/holidays'
5
+
6
+ module BankWorkingDay
7
+ def self.end_of_month_without_holiday(date)
8
+ date.end_of_month.day.downto(1) do |last_day|
9
+ last_day = Date.new(date.year, date.month, last_day)
10
+ return last_day unless holidays.holiday?(last_day)
11
+ end
12
+ end
13
+
14
+ def self.working_day_before(date: , offset: )
15
+ offset.times do |i|
16
+ date -= 1
17
+ date -= 1 while holiday?(date)
18
+ end
19
+
20
+ date
21
+ end
22
+
23
+ def self.holiday?(date)
24
+ holidays.holiday?(date)
25
+ end
26
+
27
+ private
28
+
29
+ def self.holidays
30
+ @holidays ||= Holidays.new
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bank_working_day
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Morioka Shuhei
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 銀行の営業日計算を行う
70
+ email:
71
+ - selmertsx@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bank_holidays.yml
85
+ - bank_working_day.gemspec
86
+ - bin/console
87
+ - bin/setup
88
+ - holidays.yml
89
+ - lib/bank_working_day.rb
90
+ - lib/bank_working_day/holidays.rb
91
+ - lib/bank_working_day/version.rb
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: 銀行の口座振替日、振込日をよしなに取得してくれるgem
116
+ test_files: []