google_holiday_calendar 0.0.1 → 0.0.2
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/.travis.yml +1 -2
- data/CHANGELOG.md +11 -0
- data/README.md +18 -4
- data/lib/google_holiday_calendar/calendar.rb +14 -1
- data/lib/google_holiday_calendar/version.rb +1 -1
- data/spec/google_holiday_calendar/calendar_spec.rb +27 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87ff02c8c74a34ae2db1d25e804e745673a5365f
|
|
4
|
+
data.tar.gz: e025c7f86ea9dcb8922e74c956cb6b9260c549b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa3d7ec59f3e7387b0b4ff9f00e560c7388dcf36817118444d9c7e5da07d7f2f6b5edaf3b3a12ead4db1d6ce0f3cf0537968296e04ff9046c3e3791f776cf41c
|
|
7
|
+
data.tar.gz: b8f6ba4975fda277f2286abe8ad8e883cbf055a79d512c0c20f392380a3561890a1e4b23858f4e3a91a08468d76fb0d1ba4f77f5a9cfa44c40c41c175d465460
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## master
|
|
2
|
+
[full changelog](http://github.com/sue445/google_holiday_calendar/compare/v0.0.2...master)
|
|
3
|
+
|
|
4
|
+
## v0.0.2
|
|
5
|
+
[full changelog](http://github.com/sue445/google_holiday_calendar/compare/v0.0.1...v0.0.2)
|
|
6
|
+
|
|
7
|
+
* bugfix: NoMethodError if not exists holidays
|
|
8
|
+
* Impl `GoogleHolidayCalendar::Calendar#holiday?`
|
|
9
|
+
|
|
10
|
+
## v0.0.1
|
|
11
|
+
* first release
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# GoogleHolidayCalendar [](https://travis-ci.org/sue445/google_holiday_calendar) [](https://coveralls.io/r/sue445/google_holiday_calendar) [](https://gemnasium.com/sue445/google_holiday_calendar) [](https://codeclimate.com/github/sue445/google_holiday_calendar)
|
|
1
|
+
# GoogleHolidayCalendar [](http://badge.fury.io/rb/google_holiday_calendar) [](https://travis-ci.org/sue445/google_holiday_calendar) [](https://coveralls.io/r/sue445/google_holiday_calendar) [](https://gemnasium.com/sue445/google_holiday_calendar) [](https://codeclimate.com/github/sue445/google_holiday_calendar)
|
|
2
2
|
|
|
3
3
|
Get holidays via Google Calendar.
|
|
4
4
|
|
|
@@ -26,13 +26,19 @@ require "google_holiday_calendar"
|
|
|
26
26
|
|
|
27
27
|
usa_calendar = GoogleHolidayCalendar::Calendar.new(country: "usa", lang: "en")
|
|
28
28
|
|
|
29
|
-
usa_calendar.holidays(start_date: "2014-01-01", end_date: "2014-03-01, limit: 5
|
|
29
|
+
usa_calendar.holidays(start_date: "2014-01-01", end_date: "2014-03-01", limit: 5)
|
|
30
30
|
# => {Wed, 01 Jan 2014=>"New Year's Day", Mon, 20 Jan 2014=>"Martin Luther King Day", Fri, 14 Feb 2014=>"Valentine's Day", Mon, 17 Feb 2014=>"Presidents' Day (Washington's Birthday)"}
|
|
31
31
|
|
|
32
32
|
japan_calendar = GoogleHolidayCalendar::Calendar.new(country: "japanese", lang: "ja")
|
|
33
33
|
|
|
34
|
-
japan_calendar.holidays(start_date: "2014-01-01", end_date: "2014-03-01, limit: 5
|
|
34
|
+
japan_calendar.holidays(start_date: "2014-01-01", end_date: "2014-03-01", limit: 5)
|
|
35
35
|
# => {Wed, 01 Jan 2014=>"元日", Thu, 02 Jan 2014=>"銀行休業日", Fri, 03 Jan 2014=>"銀行休業日", Mon, 13 Jan 2014=>"成人の日", Tue, 11 Feb 2014=>"建国記念の日"}
|
|
36
|
+
|
|
37
|
+
japan_calendar.holiday?("2014-01-01")
|
|
38
|
+
# => true
|
|
39
|
+
|
|
40
|
+
japan_calendar.holiday?("2014-02-01")
|
|
41
|
+
# => false
|
|
36
42
|
```
|
|
37
43
|
|
|
38
44
|
## Usage (via bash)
|
|
@@ -44,7 +50,9 @@ $ date +"%Y-%m-%d"
|
|
|
44
50
|
|
|
45
51
|
$ google_holiday_calendar
|
|
46
52
|
2014-03-09: Daylight Saving Time starts
|
|
53
|
+
```
|
|
47
54
|
|
|
55
|
+
```sh
|
|
48
56
|
# get holidays (2014/01/01 - 2014/07/01)
|
|
49
57
|
$ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01
|
|
50
58
|
2014-01-01: New Year's Day
|
|
@@ -57,14 +65,17 @@ $ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01
|
|
|
57
65
|
2014-05-11: Mothers' Day
|
|
58
66
|
2014-05-26: Memorial Day
|
|
59
67
|
2014-06-15: Fathers' Day
|
|
68
|
+
```
|
|
60
69
|
|
|
70
|
+
```sh
|
|
61
71
|
# get holidays (with limit)
|
|
62
72
|
$ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01 --limit=3
|
|
63
|
-
google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01 --limit=3
|
|
64
73
|
2014-02-14: Valentine's Day
|
|
65
74
|
2014-02-17: Presidents' Day (Washington's Birthday)
|
|
66
75
|
2014-04-13: Thomas Jefferson's Birthday
|
|
76
|
+
```
|
|
67
77
|
|
|
78
|
+
```sh
|
|
68
79
|
# get holidays (specify country and language)
|
|
69
80
|
$ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01 --country=japanese --lang=ja
|
|
70
81
|
2014-01-01: 元日
|
|
@@ -79,6 +90,9 @@ $ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01 --countr
|
|
|
79
90
|
2014-05-06: みどりの日 振替休日
|
|
80
91
|
```
|
|
81
92
|
|
|
93
|
+
## More reference
|
|
94
|
+
http://rubydoc.info/github/sue445/google_holiday_calendar
|
|
95
|
+
|
|
82
96
|
## Contributing
|
|
83
97
|
|
|
84
98
|
1. Fork it ( http://github.com/sue445/google_holiday_calendar/fork )
|
|
@@ -16,6 +16,7 @@ module GoogleHolidayCalendar
|
|
|
16
16
|
# @param end_date [String,Date] end date ("YYYY-MM-DD" or Date). not contain this date. default: 1 month after the start_date
|
|
17
17
|
# @param limit [Integer]
|
|
18
18
|
# @return [Hash] key: date, value: holiday title
|
|
19
|
+
# @return [{}] if found no holidays, return empty hash
|
|
19
20
|
def holidays(start_date: nil, end_date: nil, limit: 10)
|
|
20
21
|
start_date = Date.today unless start_date
|
|
21
22
|
end_date = to_date(start_date) + 1.month unless end_date
|
|
@@ -31,7 +32,10 @@ module GoogleHolidayCalendar
|
|
|
31
32
|
|
|
32
33
|
calendar_response = fetch(url)
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
entries = calendar_response["feed"]["entry"]
|
|
36
|
+
return {} unless entries
|
|
37
|
+
|
|
38
|
+
holidays = entries.inject({}){ |res, entry|
|
|
35
39
|
date = Date.parse(entry["gd$when"][0]["startTime"])
|
|
36
40
|
title = entry["title"]["$t"]
|
|
37
41
|
res[date] =title
|
|
@@ -41,6 +45,13 @@ module GoogleHolidayCalendar
|
|
|
41
45
|
Hash[holidays.sort_by{|k,v| k }]
|
|
42
46
|
end
|
|
43
47
|
|
|
48
|
+
# whether arg is holiday
|
|
49
|
+
# @param arg [#to_date, String] {Date}, {Time}, or date like String (ex. "YYYY-MM-DD")
|
|
50
|
+
def holiday?(arg)
|
|
51
|
+
date = to_date(arg)
|
|
52
|
+
holidays(start_date: date, end_date: date + 1.day, limit: 1).length > 0
|
|
53
|
+
end
|
|
54
|
+
|
|
44
55
|
private
|
|
45
56
|
|
|
46
57
|
# @param url [String]
|
|
@@ -62,6 +73,8 @@ module GoogleHolidayCalendar
|
|
|
62
73
|
def to_date(arg)
|
|
63
74
|
if arg.is_a?(String)
|
|
64
75
|
Date.parse(arg)
|
|
76
|
+
elsif arg.respond_to?(:to_date)
|
|
77
|
+
arg.to_date
|
|
65
78
|
else
|
|
66
79
|
arg
|
|
67
80
|
end
|
|
@@ -43,6 +43,13 @@ describe GoogleHolidayCalendar::Calendar do
|
|
|
43
43
|
|
|
44
44
|
it_behaves_like :holidays_in_japan_at_jan
|
|
45
45
|
end
|
|
46
|
+
|
|
47
|
+
context "When not found holidays" do
|
|
48
|
+
let(:start_date){ "2014-06-01" }
|
|
49
|
+
let(:end_date) { "2014-07-01" }
|
|
50
|
+
|
|
51
|
+
it{ should == {}}
|
|
52
|
+
end
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
context "When holidays in America" do
|
|
@@ -53,4 +60,24 @@ describe GoogleHolidayCalendar::Calendar do
|
|
|
53
60
|
end
|
|
54
61
|
end
|
|
55
62
|
end
|
|
63
|
+
|
|
64
|
+
describe "#holiday?" do
|
|
65
|
+
subject{ calendar.holiday?(date) }
|
|
66
|
+
|
|
67
|
+
let(:calendar){ GoogleHolidayCalendar::Calendar.new(country: country, lang: lang) }
|
|
68
|
+
let(:country) { "japanese" }
|
|
69
|
+
let(:lang) { "ja" }
|
|
70
|
+
|
|
71
|
+
context "arg is holiday" do
|
|
72
|
+
let(:date){ Date.parse("2014-01-01") }
|
|
73
|
+
|
|
74
|
+
it{ should be true }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context "arg is not holiday" do
|
|
78
|
+
let(:date){ Date.parse("2014-02-01") }
|
|
79
|
+
|
|
80
|
+
it{ should be false }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
56
83
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: google_holiday_calendar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sue445
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-02-
|
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -163,6 +163,7 @@ files:
|
|
|
163
163
|
- ".rspec"
|
|
164
164
|
- ".travis.yml"
|
|
165
165
|
- ".yardopts"
|
|
166
|
+
- CHANGELOG.md
|
|
166
167
|
- Gemfile
|
|
167
168
|
- LICENSE.txt
|
|
168
169
|
- README.md
|
|
@@ -198,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
198
199
|
version: '0'
|
|
199
200
|
requirements: []
|
|
200
201
|
rubyforge_project:
|
|
201
|
-
rubygems_version: 2.2.
|
|
202
|
+
rubygems_version: 2.2.2
|
|
202
203
|
signing_key:
|
|
203
204
|
specification_version: 4
|
|
204
205
|
summary: Get holidays via Google Calendar.
|