holidays_in_month 0.1.2 → 0.1.3
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 +14 -7
- data/lib/holidays_in_month/version.rb +1 -1
- data/lib/holidays_in_month.rb +26 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32194ceaa55090daa2d8e39a007c60ab825e9302
|
4
|
+
data.tar.gz: 8aa28cdac1d28f10806a16e5c4a2596b05ef09e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e25c93bcb52b84372b577b39d06d72ad9ceb5bee602f78a20a7182779ac0732ee8c501755b6b738147d491d2b8090211c2ba3c12dbe94888cd8735b9198ceb4
|
7
|
+
data.tar.gz: c632be6dc22b691f19a2dd0a78729d626f18ca40d52c814ef46a4799532b472c8363dd31265e6293d00f1d36b8cbefbcabb50a64012c557b57c47392fd66ddc3
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Holidays in Month
|
2
2
|
|
3
|
-
This gem is return holidays(Saturday, Sunday, National)
|
3
|
+
This gem is return holidays(Saturday, Sunday, National) of month in Japan.
|
4
4
|
|
5
5
|
```ruby
|
6
|
-
|
6
|
+
obj.get_in_month(2016, 1)
|
7
7
|
=> ["2016-1-2", "2016-1-3", "2016-1-9", "2016-1-10", "2016-1-16", "2016-1-17",
|
8
8
|
"2016-1-23", "2016-1-24", "2016-1-30", "2016-1-31", {"2016-01-01"=>"元日", "2016-01-11"=>"成人の日"}]
|
9
9
|
```
|
@@ -18,7 +18,7 @@ gem 'holidays_in_month'
|
|
18
18
|
|
19
19
|
And then execute:
|
20
20
|
|
21
|
-
$ bundle
|
21
|
+
$ bundle install
|
22
22
|
|
23
23
|
Or install it yourself as:
|
24
24
|
|
@@ -26,13 +26,20 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
+
Add this line to your application's Model or Controller:
|
30
|
+
|
29
31
|
```ruby
|
30
|
-
Holidays.
|
32
|
+
holidays = JP::Holidays.new
|
33
|
+
holidays.get_in_month(year, month)
|
34
|
+
```
|
31
35
|
|
32
36
|
example:
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
@holidays = JP::Holidays.new
|
40
|
+
@holidays.get_in_month(2016, 1)
|
41
|
+
@holidays => ["2016-1-2", "2016-1-3", "2016-1-9", "2016-1-10", "2016-1-16", "2016-1-17",
|
42
|
+
"2016-1-23", "2016-1-24", "2016-1-30", "2016-1-31", {"2016-01-01"=>"元日", "2016-01-11"=>"成人の日"}]
|
36
43
|
```
|
37
44
|
|
38
45
|
## License
|
data/lib/holidays_in_month.rb
CHANGED
@@ -4,32 +4,37 @@ require 'active_support/time'
|
|
4
4
|
require 'time'
|
5
5
|
require 'yaml'
|
6
6
|
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
module JP
|
8
|
+
class Holiday
|
9
|
+
def get_in_month(year, month)
|
10
|
+
init
|
11
|
+
#休日に祝日を追加
|
12
|
+
holidays(year, month) << nationaldays.select { |n| n.match(/#{year}-#{"%02d" % month}-*/) }
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
@
|
17
|
+
def init
|
18
|
+
@nationaldays = {}
|
19
|
+
@holidays = []
|
16
20
|
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
def nationaldays
|
23
|
+
yaml = YAML.load_file(File.expand_path('./../../holidays.yml', __FILE__))
|
24
|
+
yaml.each do |date, name|
|
25
|
+
@nationaldays.store(date.strftime("%Y-%m-%d"), name)
|
26
|
+
end
|
27
|
+
@nationaldays
|
23
28
|
end
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def holidays(year, month)
|
31
|
+
num_days_of_month = Date.new(year, month).end_of_month.day
|
32
|
+
|
33
|
+
1.upto(num_days_of_month) do |day|
|
34
|
+
wday = Date.new(year, month, day).wday
|
35
|
+
@holidays << "%04d-%02d-%02d" % [year, month, day] if wday == 6 || wday == 0
|
36
|
+
end
|
37
|
+
@holidays
|
32
38
|
end
|
33
|
-
@holidays << @national_holidays
|
34
39
|
end
|
35
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holidays_in_month
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Hasada
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|