holiday_jp 0.2.1 → 0.3.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.
data/.gemtest ADDED
File without changes
data/.gitignore CHANGED
@@ -1,21 +1,6 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
1
  coverage
18
2
  rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
3
+ pkg/*
4
+ Gemfile.lock
5
+ *.gem
6
+ .bundle
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ holiday_jp (0.3.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ json (1.6.1)
10
+ rake (0.9.2.2)
11
+ rdoc (3.11)
12
+ json (~> 1.4)
13
+ shoulda (2.11.3)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ holiday_jp!
20
+ rake (= 0.9.2.2)
21
+ rdoc (= 3.11)
22
+ shoulda (= 2.11.3)
data/Rakefile CHANGED
@@ -1,23 +1,4 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "holiday_jp"
8
- gem.summary = %Q{Japanese Holidays.}
9
- gem.description = %Q{Japanese Holidays from 1970 to 2050.}
10
- gem.email = "komagata@gmail.com"
11
- gem.homepage = "http://github.com/komagata/holiday_jp"
12
- gem.authors = ["Masaki KOMAGATA"]
13
- gem.add_development_dependency "shoulda", ">= 2.11.3"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
- end
20
-
1
+ require "bundler/gem_tasks"
21
2
  require 'rake/testtask'
22
3
  Rake::TestTask.new(:test) do |test|
23
4
  test.libs << 'lib' << 'test'
@@ -25,27 +6,12 @@ Rake::TestTask.new(:test) do |test|
25
6
  test.verbose = true
26
7
  end
27
8
 
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
- task :test => :check_dependencies
42
-
43
9
  task :default => :test
44
10
 
45
- require 'rake/rdoctask'
11
+ require 'rdoc/task'
12
+ require 'holiday_jp/version'
46
13
  Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
14
+ version = HolidayJp::VERSION
49
15
  rdoc.rdoc_dir = 'rdoc'
50
16
  rdoc.title = "holiday_jp #{version}"
51
17
  rdoc.rdoc_files.include('README*')
data/benchmark.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'benchmark'
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
3
+ require 'holiday_jp'
4
+
5
+ def bench_holiday
6
+ Benchmark.measure {
7
+ d = Date.new(2011, 9, 19)
8
+ 10000.times do
9
+ HolidayJp.holiday?(d)
10
+ end
11
+ }
12
+ end
13
+ def bench_between
14
+ Benchmark.measure {
15
+ d = Date.new(2009, 1, 1)
16
+ d2 = Date.new(2009, 12, 31)
17
+ 10000.times do
18
+ HolidayJp.between(d,d2)
19
+ end
20
+ }
21
+ end
22
+
23
+ puts bench_holiday
24
+ puts bench_between
data/holiday_jp.gemspec CHANGED
@@ -1,54 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "holiday_jp/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{holiday_jp}
8
- s.version = "0.2.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Masaki KOMAGATA"]
12
- s.date = %q{2010-09-14}
6
+ s.name = "holiday_jp"
7
+ s.version = HolidayJp::VERSION
8
+ s.authors = ["Masaki Komagata"]
9
+ s.email = ["komagata@gmail.com"]
10
+ s.homepage = "http://github.com/komagata/holiday_jp"
11
+ s.summary = %q{Japanese Holidays.}
13
12
  s.description = %q{Japanese Holidays from 1970 to 2050.}
14
- s.email = %q{komagata@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "holiday_jp.gemspec",
27
- "lib/holiday_jp.rb",
28
- "test/helper.rb",
29
- "test/test_holiday_jp.rb"
30
- ]
31
- s.homepage = %q{http://github.com/komagata/holiday_jp}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
35
- s.summary = %q{Japanese Holidays.}
36
- s.test_files = [
37
- "test/helper.rb",
38
- "test/test_holiday_jp.rb"
39
- ]
40
13
 
41
- if s.respond_to? :specification_version then
42
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
- s.specification_version = 3
14
+ s.rubyforge_project = "holiday_jp"
44
15
 
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
47
- else
48
- s.add_dependency(%q<shoulda>, [">= 2.11.3"])
49
- end
50
- else
51
- s.add_dependency(%q<shoulda>, [">= 2.11.3"])
52
- end
53
- end
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
54
20
 
21
+ s.add_development_dependency "rake", '0.9.2.2'
22
+ s.add_development_dependency "rdoc", '3.11'
23
+ s.add_development_dependency "shoulda", '2.11.3'
24
+ end
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'date'
3
+ module HolidayJp
4
+ class Holiday
5
+ WDAY_NAMES = %w(日 月 火 水 木 金 土)
6
+
7
+ EN_HOLIDAY_NAMES = {
8
+ "元日" => "New Year's Day",
9
+ "成人の日" => "Coming of Age Day",
10
+ "建国記念の日" => "National Foundation Day",
11
+ "春分の日" => "Vernal Equinox Day",
12
+ "憲法記念日" => "Constitution Memorial Day",
13
+ "みどりの日" => "Greenery Day",
14
+ "こどもの日" => "Children's Day",
15
+ "海の日" => "Marine Day",
16
+ "敬老の日" => "Respect for the Aged Day",
17
+ "秋分の日" => "Autumnal Equinox Day",
18
+ "体育の日" => "Health and Sports Day",
19
+ "文化の日" => "National Culture Day",
20
+ "勤労感謝の日" => "Labor Thanksgiving Day",
21
+ "天皇誕生日" => "Emperor's Birthday",
22
+ "昭和の日" => "Showa Day",
23
+ "振替休日" => "Holiday in lieu",
24
+ "国民の休日" => "Citizen's Holiday",
25
+ "即位礼正殿の儀" => "The Ceremony of the Enthronement of His Majesty th Emperor (at the Seiden)",
26
+ "昭和天皇の大喪の礼" => "The Funeral Ceremony of Emperor Showa.",
27
+ "皇太子徳仁親王の結婚の儀" => "The Rite of Wedding of HIH Crown Prince Naruhito"
28
+ }
29
+
30
+ attr_reader :date, :name
31
+ def initialize(date, name)
32
+ @date = parse_date(date)
33
+ @name = name
34
+ end
35
+
36
+ def name_en
37
+ EN_HOLIDAY_NAMES[name]
38
+ end
39
+
40
+ def wday_name
41
+ WDAY_NAMES[date.wday]
42
+ end
43
+ alias :week :wday_name
44
+
45
+ def parse_date(date)
46
+ begin
47
+ Date.parse(date)
48
+ rescue ArgumentError
49
+ raise ArgumentError, "invalid date on :#{date}, #{name}"
50
+ end
51
+ end
52
+ end
53
+ end