china-holidays 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b8331b49fb69fe5a8be1b1fe7242185086b9630
4
+ data.tar.gz: 7a77ee772be513d04440f70b6faf53a6475aa45a
5
+ SHA512:
6
+ metadata.gz: 9a1fd406731df30388db27d832cd9ce1ed8a7fc44542727541c4a89b5cef924118b56e4f92f705c72b92411bbd1c0c1608ff6882818fb31cca84a3c756d9f972
7
+ data.tar.gz: 259c2b3a57e29cb1de89abbbe20b0abd0497788c7a2bebe2f6f7881c8cd0df39856347712d01f3afb3c41f261ca879e7bad10c4dcde78c84b7f0c8bc21305931
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in china-holidays.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # China Holidays
2
+
3
+ Add `holiday?` instance method to Rails Date and Time class
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ # Date instance method
9
+ "2016-01-01".to_date.holiday? # true
10
+
11
+ # Time instance method
12
+ "2016-01-01 20:11:12 +0800".to_time.holiday? # true
13
+ ```
14
+
15
+ #### You can change holidays in `holidays.json` file
16
+ ```bash
17
+ {
18
+ "holidays": [
19
+ "2016-01-01",// 元旦
20
+ "2016-01-02",
21
+ "2016-01-03",
22
+ "2016-02-07",// 春节
23
+ "2016-02-08",
24
+ "2016-02-09",
25
+ "2016-02-10",
26
+ "2016-02-11",
27
+ "2016-02-12",
28
+ "2016-02-13",
29
+ "2016-04-02",// 清明节
30
+ "2016-04-03",
31
+ "2016-04-04",
32
+ "2016-04-30",// 劳动节
33
+ "2016-05-01",
34
+ "2016-05-02",
35
+ "2016-06-09",// 端午节
36
+ "2016-06-10",
37
+ "2016-06-11",
38
+ "2016-09-15",// 中秋节
39
+ "2016-09-16",
40
+ "2016-09-17",
41
+ "2016-10-01",// 国庆节
42
+ "2016-10-02",
43
+ "2016-10-03",
44
+ "2016-10-04",
45
+ "2016-10-05",
46
+ "2016-10-06",
47
+ "2016-10-07",
48
+ "2016-02-28"
49
+ ]
50
+ }
51
+ ```
52
+ ## Installation
53
+
54
+ Add this line to your application's Gemfile:
55
+
56
+ ```ruby
57
+ gem 'china-holidays'
58
+ ```
59
+
60
+ And then execute:
61
+
62
+ $ bundle
63
+
64
+ Or install it yourself as:
65
+
66
+ $ gem install china-holidays
67
+
68
+
69
+ ## License
70
+ MIT
71
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "china/holidays"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'china/holidays/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "china-holidays"
8
+ spec.version = China::Holidays::VERSION
9
+ spec.authors = ["DawnyWu"]
10
+ spec.email = ["wuzhaoyang@gmail.com"]
11
+
12
+ spec.summary = "A gem contains 2016 china holidays"
13
+ spec.description = "A gem contains 2016 china holidays"
14
+ spec.homepage = "https://github.com/DawnyWu/china-holidays"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ end
data/holidays.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "holidays": [
3
+ "2016-01-01",// 元旦
4
+ "2016-01-02",
5
+ "2016-01-03",
6
+ "2016-02-07",// 春节
7
+ "2016-02-08",
8
+ "2016-02-09",
9
+ "2016-02-10",
10
+ "2016-02-11",
11
+ "2016-02-12",
12
+ "2016-02-13",
13
+ "2016-04-02",// 清明节
14
+ "2016-04-03",
15
+ "2016-04-04",
16
+ "2016-04-30",// 劳动节
17
+ "2016-05-01",
18
+ "2016-05-02",
19
+ "2016-06-09",// 端午节
20
+ "2016-06-10",
21
+ "2016-06-11",
22
+ "2016-09-15",// 中秋节
23
+ "2016-09-16",
24
+ "2016-09-17",
25
+ "2016-10-01",// 国庆节
26
+ "2016-10-02",
27
+ "2016-10-03",
28
+ "2016-10-04",
29
+ "2016-10-05",
30
+ "2016-10-06",
31
+ "2016-10-07",
32
+ "2016-02-28"
33
+ ]
34
+ }
@@ -0,0 +1,5 @@
1
+ module China
2
+ module Holidays
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ require "china/holidays/version"
2
+ require 'json'
3
+
4
+ module China
5
+ module Holidays
6
+ file = File.read(File.join(__dir__, '..', '..', 'holidays.json'))
7
+ hash = JSON.parse(file.force_encoding('utf-8'))
8
+
9
+ DATES = hash['holidays'].map(&:to_date)
10
+
11
+ def self.dates
12
+ DATES
13
+ end
14
+
15
+ module Date
16
+ def holiday?
17
+ DATES.include?(self)
18
+ end
19
+ end
20
+
21
+ module Time
22
+ def holiday?
23
+ DATES.include?(self.to_date)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ class Date
30
+ include China::Holidays::Date
31
+ end
32
+
33
+ class Time
34
+ include China::Holidays::Time
35
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: china-holidays
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - DawnyWu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-29 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ description: A gem contains 2016 china holidays
42
+ email:
43
+ - wuzhaoyang@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - china-holidays.gemspec
55
+ - holidays.json
56
+ - lib/china/holidays.rb
57
+ - lib/china/holidays/version.rb
58
+ homepage: https://github.com/DawnyWu/china-holidays
59
+ licenses: []
60
+ metadata:
61
+ allowed_push_host: https://rubygems.org
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.8
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A gem contains 2016 china holidays
82
+ test_files: []