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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5da277bf2485dfff7687b9b69cc6412bec04eaf0
4
- data.tar.gz: ed804e3612ccf900ccf7cf6920d9c15cb01100a9
3
+ metadata.gz: 32194ceaa55090daa2d8e39a007c60ab825e9302
4
+ data.tar.gz: 8aa28cdac1d28f10806a16e5c4a2596b05ef09e4
5
5
  SHA512:
6
- metadata.gz: 693a365bc88064c71f2c2ceeba3ae8dedad7998d7090a3678e18a637ecc33a857b83ce052eb3e36dfb010315cbc90cd1d94c0b13edec4f89a7bc4818f6a281d3
7
- data.tar.gz: 73e0cf31b8d7dbb87334296d0beb87d4a3c79ff8a88c4cae43584f96c32d006e74cb7ce413d9f88bbe289f60e1c4458231be09d541659ea5e952c8f1db273582
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) in month in Japan.
3
+ This gem is return holidays(Saturday, Sunday, National) of month in Japan.
4
4
 
5
5
  ```ruby
6
- Holidays.holidays_in_month(1,2016)
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.holidays_in_month(month,year)
32
+ holidays = JP::Holidays.new
33
+ holidays.get_in_month(year, month)
34
+ ```
31
35
 
32
36
  example:
33
- Holidays.holidays_in_month(12,2016)
34
- => ["2016-12-3", "2016-12-4", "2016-12-10", "2016-12-11", "2016-12-17", "2016-12-18",
35
- "2016-12-24", "2016-12-25", "2016-12-31", {"2016-12-23"=>"天皇誕生日"}]
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
@@ -1,3 +1,3 @@
1
1
  module Holidays
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -4,32 +4,37 @@ require 'active_support/time'
4
4
  require 'time'
5
5
  require 'yaml'
6
6
 
7
- module Holidays
8
- def self.holidays_in_month(month, year)
9
- @national_holidays = {}
10
- @holidays = []
11
- d = 0
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
- yaml = YAML.load_file(File.expand_path('./../../holidays.yml', __FILE__))
14
- yaml.each do |date, name|
15
- @national_holidays.store(date.strftime("%Y-%m-%d"), name)
17
+ def init
18
+ @nationaldays = {}
19
+ @holidays = []
16
20
  end
17
21
 
18
- Time.days_in_month(month, year).times do
19
- d += 1
20
- wday = Date.new(year, month, d).wday
21
- #Saturday => wday == 6, Sunday => wday == 0
22
- @holidays << "#{year}-#{month}-#{d}" if wday == 6 || wday == 0
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
- case month
26
- when 1
27
- @national_holidays = @national_holidays.select { |k| k.match(/#{year}-0#{month}-*/) }
28
- when 2
29
- @national_holidays = @national_holidays.select { |k| k.match(/#{year}-0#{month}-*/) }
30
- else
31
- @national_holidays = @national_holidays.select { |k| k.match(/#{year}-#{month}-*/) }
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.2
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-02-24 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport