hk_holidays 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "> 1.0.0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "simplecov", ">= 0"
14
+ gem "ri_cal"
15
+ end
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ atomic (1.1.10)
11
+ git (1.2.5)
12
+ i18n (0.6.4)
13
+ jeweler (1.8.4)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ rdoc
18
+ json (1.8.0)
19
+ minitest (4.7.5)
20
+ multi_json (1.7.7)
21
+ rake (10.1.0)
22
+ rdoc (3.12.2)
23
+ json (~> 1.4)
24
+ ri_cal (0.8.8)
25
+ shoulda (3.5.0)
26
+ shoulda-context (~> 1.0, >= 1.0.1)
27
+ shoulda-matchers (>= 1.4.1, < 3.0)
28
+ shoulda-context (1.1.4)
29
+ shoulda-matchers (2.2.0)
30
+ activesupport (>= 3.0.0)
31
+ simplecov (0.7.1)
32
+ multi_json (~> 1.0)
33
+ simplecov-html (~> 0.7.1)
34
+ simplecov-html (0.7.1)
35
+ thread_safe (0.1.0)
36
+ atomic
37
+ tzinfo (0.3.37)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (> 1.0.0)
44
+ jeweler (~> 1.8.4)
45
+ rdoc (~> 3.12)
46
+ ri_cal
47
+ shoulda
48
+ simplecov
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Alan Ho
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = hk_holidays
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to hk_holidays
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Alan Ho. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "hk_holidays"
18
+ gem.homepage = "http://github.com/alanho/hk_holidays"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A utility to tell whether a specific date is a Hong Kong's holiday}
21
+ gem.description = %Q{A utility to tell whether a specific date is a Hong Kong's holiday}
22
+ gem.email = "alanho@gmail.com"
23
+ gem.authors = ["Alan Ho"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "hk_holidays #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
46
+
47
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "hk_holidays"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alan Ho"]
12
+ s.date = "2013-06-29"
13
+ s.description = "A utility to tell whether a specific date is a Hong Kong's holiday"
14
+ s.email = "alanho@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "hk_holidays.gemspec",
28
+ "lib/core_ext/date.rb",
29
+ "lib/hk_holidays.rb",
30
+ "lib/hk_holidays.yml",
31
+ "lib/hk_holidays/version.rb",
32
+ "tasks/update.rake",
33
+ "test/helper.rb",
34
+ "test/test_hk_holidays.rb"
35
+ ]
36
+ s.homepage = "http://github.com/alanho/hk_holidays"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.25"
40
+ s.summary = "A utility to tell whether a specific date is a Hong Kong's holiday"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
50
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
51
+ s.add_development_dependency(%q<ri_cal>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
57
+ s.add_dependency(%q<simplecov>, [">= 0"])
58
+ s.add_dependency(%q<ri_cal>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
65
+ s.add_dependency(%q<simplecov>, [">= 0"])
66
+ s.add_dependency(%q<ri_cal>, [">= 0"])
67
+ end
68
+ end
69
+
@@ -0,0 +1,11 @@
1
+ class Date
2
+ def is_hk_holiday?(options = {})
3
+ return_name = (options[:return_name] == true)
4
+
5
+ if HKHolidays.is_hk_holiday?(self)
6
+ return_name ? HKHolidays.holiday_name(self) : true
7
+ else
8
+ false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ $:.unshift File.dirname(__FILE__)
3
+
4
+ require "date"
5
+ require "yaml"
6
+
7
+ class HKHolidays
8
+ class << self
9
+ def is_hk_holiday?(date)
10
+ holidays.map { |d| d[:date] }.include? date
11
+ end
12
+
13
+ def holiday_name(date)
14
+ holiday = holidays.find { |d| d[:date] == date }
15
+ holiday ? holiday[:name] : false
16
+ end
17
+
18
+ def holidays
19
+ @holidays ||= load_holidays
20
+ end
21
+
22
+ protected
23
+ def load_holidays
24
+ YAML::load_file(File.join(File.dirname(__FILE__), "hk_holidays.yml"))
25
+ end
26
+ end
27
+ end
28
+
29
+ require "core_ext/date"
@@ -0,0 +1,107 @@
1
+ ---
2
+ - :name: The first weekday after Chrstmas Day
3
+ :date: 2011-12-26
4
+ - :name: The second weekday after Chrstmas Day
5
+ :date: 2011-12-27
6
+ - :name: The day following the first day of January
7
+ :date: 2012-01-02
8
+ - :name: Lunar New Year's Day
9
+ :date: 2012-01-23
10
+ - :name: The second day of Lunar New Year
11
+ :date: 2012-01-24
12
+ - :name: The third day of Lunar New Year
13
+ :date: 2012-01-25
14
+ - :name: Ching Ming Festival
15
+ :date: 2012-04-04
16
+ - :name: Good Friday
17
+ :date: 2012-04-06
18
+ - :name: The day following Good Friday
19
+ :date: 2012-04-07
20
+ - :name: Easter Monday
21
+ :date: 2012-04-09
22
+ - :name: The Birthday of the Buddha
23
+ :date: 2012-04-28
24
+ - :name: Labour Day
25
+ :date: 2012-05-01
26
+ - :name: Tuen Ng Festival
27
+ :date: 2012-06-23
28
+ - :name: The day following Hong Kong Special Administrative Region Establishment Day
29
+ :date: 2012-07-02
30
+ - :name: The day following the Chinese Mid-Autumn Festival
31
+ :date: 2012-10-01
32
+ - :name: The day following National Day
33
+ :date: 2012-10-02
34
+ - :name: Chung Yeung Festival
35
+ :date: 2012-10-23
36
+ - :name: Christmas Day
37
+ :date: 2012-12-25
38
+ - :name: The first weekday after Christmas Day
39
+ :date: 2012-12-26
40
+ - :name: The first day of January
41
+ :date: 2013-01-01
42
+ - :name: The second day of Lunar New Year
43
+ :date: 2013-02-11
44
+ - :name: The third day of Lunar New Year
45
+ :date: 2013-02-12
46
+ - :name: The fourth day of Lunar New Year
47
+ :date: 2013-02-13
48
+ - :name: Good Friday
49
+ :date: 2013-03-29
50
+ - :name: The day following Good Friday
51
+ :date: 2013-03-30
52
+ - :name: Easter Monday
53
+ :date: 2013-04-01
54
+ - :name: Ching Ming Festival
55
+ :date: 2013-04-04
56
+ - :name: Labour Day
57
+ :date: 2013-05-01
58
+ - :name: The Birthday of the Buddha
59
+ :date: 2013-05-17
60
+ - :name: Tuen Ng Festival
61
+ :date: 2013-06-12
62
+ - :name: Hong Kong Special Administrative Region Establishment Day
63
+ :date: 2013-07-01
64
+ - :name: The day following the Chinese Mid-Autumn Festival
65
+ :date: 2013-09-20
66
+ - :name: National Day
67
+ :date: 2013-10-01
68
+ - :name: The day following Chung Yeung Festival
69
+ :date: 2013-10-14
70
+ - :name: Christmas Day
71
+ :date: 2013-12-25
72
+ - :name: The first weekday after Christmas Day
73
+ :date: 2013-12-26
74
+ - :name: The first day of January
75
+ :date: 2014-01-01
76
+ - :name: Lunar New Year’s Day
77
+ :date: 2014-01-31
78
+ - :name: The second day of Lunar New Year
79
+ :date: 2014-02-01
80
+ - :name: The fourth day of Lunar New Year
81
+ :date: 2014-02-03
82
+ - :name: Ching Ming Festival
83
+ :date: 2014-04-05
84
+ - :name: Good Friday
85
+ :date: 2014-04-18
86
+ - :name: The day following Good Friday
87
+ :date: 2014-04-19
88
+ - :name: Easter Monday
89
+ :date: 2014-04-21
90
+ - :name: Labour Day
91
+ :date: 2014-05-01
92
+ - :name: The Birthday of the Buddha
93
+ :date: 2014-05-06
94
+ - :name: Tuen Ng Festival
95
+ :date: 2014-06-02
96
+ - :name: Hong Kong Special Administrative Region Establishment Day
97
+ :date: 2014-07-01
98
+ - :name: The day following the Chinese Mid-Autumn Festival
99
+ :date: 2014-09-09
100
+ - :name: National Day
101
+ :date: 2014-10-01
102
+ - :name: Chung Yeung Festival
103
+ :date: 2014-10-02
104
+ - :name: Christmas Day
105
+ :date: 2014-12-25
106
+ - :name: The first weekday after Christmas Day
107
+ :date: 2014-12-26
File without changes
@@ -0,0 +1,22 @@
1
+ require "open-uri"
2
+ require "ri_cal"
3
+ require "yaml"
4
+
5
+ desc "Update holidays from HK Government's official iCal file"
6
+ namespace :hk_holidays do
7
+ task :update do
8
+ ICAL_URL = "http://www.1823.gov.hk/common/ical/en.ics"
9
+
10
+ holidays = []
11
+ RiCal.parse_string(open(ICAL_URL).read).first.events.each do |event|
12
+ # p event.dtstart
13
+ holidays << {
14
+ name: event.summary.force_encoding("utf-8").gsub(/[[:cntrl:]]/,""),
15
+ date: event.dtstart
16
+ }
17
+ end
18
+ File.open(File.join(File.dirname(__FILE__), "../lib/hk_holidays.yml"), "w") do |f|
19
+ f.write YAML::dump(holidays)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'hk_holidays'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestHkHolidays < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hk_holidays
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alan Ho
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>'
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>'
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.4
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: ri_cal
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A utility to tell whether a specific date is a Hong Kong's holiday
111
+ email: alanho@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - LICENSE.txt
116
+ - README.rdoc
117
+ files:
118
+ - .document
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - hk_holidays.gemspec
126
+ - lib/core_ext/date.rb
127
+ - lib/hk_holidays.rb
128
+ - lib/hk_holidays.yml
129
+ - lib/hk_holidays/version.rb
130
+ - tasks/update.rake
131
+ - test/helper.rb
132
+ - test/test_hk_holidays.rb
133
+ homepage: http://github.com/alanho/hk_holidays
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ segments:
147
+ - 0
148
+ hash: -1196745162011333692
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.25
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: A utility to tell whether a specific date is a Hong Kong's holiday
161
+ test_files: []