era_ja 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ -
3
+ README.md
4
+ README.ja.md
5
+ LICENSE
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle
@@ -0,0 +1,3 @@
1
+ --charset=UTF-8
2
+ --no-private
3
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in era_ja.gemspec
4
+ gemspec
@@ -0,0 +1,9 @@
1
+ # -*- mode: ruby -*-
2
+ # A sample Guardfile
3
+ # More info at https://github.com/guard/guard#readme
4
+
5
+ guard 'rspec', :version => 2, :cli => '--color', :all_after_pass => false do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/era_ja/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 tomi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # EraJa
2
+
3
+ 日本の和暦に変換します。
4
+
5
+ ## Installation
6
+
7
+ 以下のコードをアプリケーションのGemfileに追記します。
8
+
9
+ gem 'era_ja'
10
+
11
+ そして、以下をのコマンドを実行します。
12
+
13
+ $ bundle
14
+
15
+ もしくは
16
+
17
+ $ gem install era_ja
18
+
19
+ ## Usage
20
+
21
+ ### Timeインスタンスを和暦に変換します。
22
+
23
+ ```ruby
24
+ Time.mktime(2012,4,29).to_era # => "H24.4.29"
25
+ ```
26
+
27
+ ### Dateインタンスを和暦に変換します。
28
+
29
+ ```ruby
30
+ Date.new(2012,4,29).to_era # => "H24.4.29"
31
+ ```
32
+
33
+ ## Support
34
+
35
+ 問題を報告したり、機能追加の要望する場合はgithubのIssuesに登録してください。 https://github.com/tomiacannondale/era_ja/issues
36
+
37
+ ## Contributing
38
+
39
+ 1. フォークして
40
+ 2. feature branchを作成して (`git checkout -b my-new-feature`)
41
+ 3. 変更をコミットして (`git commit -am 'Added some feature'`)
42
+ 4. ブランチをプッシュして (`git push origin my-new-feature`)
43
+ 5. プルリクエストをください
44
+
45
+ ## Note
46
+
47
+ 元号については以下の問題点があります。
48
+
49
+ * 明治の開始を1968年9月8日としていますが旧暦での日付です。
50
+ * 大正、昭和の開始日はそれぞれ明治、大正の最終日と同日です。
51
+ * [昭和ト改元](http://ja.wikisource.org/wiki/%e6%98%ad%e5%92%8c%e3%83%88%e6%94%b9%e5%85%83)
52
+ * [大正十五年十二月ニ十五日以後ヲ改メテ昭和元年ト爲ス](http://ja.wikisource.org/wiki/%e5%a4%a7%e6%ad%a3%e5%8d%81%e4%ba%94%e5%b9%b4%e5%8d%81%e4%ba%8c%e6%9c%88%e3%83%8b%e5%8d%81%e4%ba%94%e6%97%a5%e4%bb%a5%e5%be%8c%e3%83%b2%e6%94%b9%e3%83%a1%e3%83%86%e6%98%ad%e5%92%8c%e5%85%83%e5%b9%b4%e3%83%88%e7%88%b2%e3%82%b9)
53
+ * [明治45年(1912)7月|大正と改元:日本のあゆみ](http://www.archives.go.jp/ayumi/kobetsu/m45_1912_01.html)
54
+
55
+ ## Author
56
+
57
+ tomi tomiacannondale@gmail.com
58
+
59
+ ## License
60
+
61
+ MITライセンスです。詳細は LICENSE を参照してください。
@@ -0,0 +1,61 @@
1
+ # EraJa
2
+
3
+ Convert to Japanese era.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'era_ja'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install era_ja
18
+
19
+ ## Usage
20
+
21
+ ### Time instance to japanese era
22
+
23
+ ```ruby
24
+ Time.mktime(2012,4,29).to_era # => "H24.4.29"
25
+ ```
26
+
27
+ ### Date instance to japanese era
28
+
29
+ ```ruby
30
+ Date.new(2012,4,29).to_era # => "H24.4.29"
31
+ ```
32
+
33
+ ## Support
34
+
35
+ Report issues and feature requests to github Issues. https://github.com/tomiacannondale/era_ja/issues
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
44
+
45
+ ## Note
46
+
47
+ I think about the era and there is a problem in the following.
48
+
49
+ * The date in the lunar calendar Although it is September 8, 1968 the start of the Meiji era.
50
+ * Start date Taisho, Showa is the same day as the last day of the Meiji, Taisho, respectively.
51
+ * [昭和ト改元](http://ja.wikisource.org/wiki/%e6%98%ad%e5%92%8c%e3%83%88%e6%94%b9%e5%85%83)
52
+ * [大正十五年十二月ニ十五日以後ヲ改メテ昭和元年ト爲ス](http://ja.wikisource.org/wiki/%e5%a4%a7%e6%ad%a3%e5%8d%81%e4%ba%94%e5%b9%b4%e5%8d%81%e4%ba%8c%e6%9c%88%e3%83%8b%e5%8d%81%e4%ba%94%e6%97%a5%e4%bb%a5%e5%be%8c%e3%83%b2%e6%94%b9%e3%83%a1%e3%83%86%e6%98%ad%e5%92%8c%e5%85%83%e5%b9%b4%e3%83%88%e7%88%b2%e3%82%b9)
53
+ * [明治45年(1912)7月|大正と改元:日本のあゆみ](http://www.archives.go.jp/ayumi/kobetsu/m45_1912_01.html)
54
+
55
+ ## Author
56
+
57
+ tomi tomiacannondale@gmail.com
58
+
59
+ ## License
60
+
61
+ MIT License. For more imformation, please see LICENSE.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8; mode: ruby -*-
2
+ require File.expand_path('../lib/era_ja/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["tomi"]
6
+ gem.email = ["tomiacannondale@gmail.com"]
7
+ gem.description = %q{Convert to Japanese era.}
8
+ gem.summary = %q{Convert Date or Time instance to String of Japanese era.}
9
+ gem.homepage = "https://github.com/tomiacannondale/era_ja"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "era_ja"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = EraJa::VERSION
17
+
18
+ gem.add_development_dependency "rake", '>= 0.9.2'
19
+ gem.add_development_dependency 'rspec', '>= 2.9.0'
20
+ gem.add_development_dependency 'growl', '>= 1.0.3'
21
+ gem.add_development_dependency "guard-rspec", '>= 0.7.0'
22
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "era_ja/version"
3
+ require 'date'
4
+
5
+ module EraJa
6
+ def to_era
7
+ if self.to_time < ::Time.mktime(1868,9,8)
8
+ raise "#to_era is expeted later in 1968,9,8"
9
+ elsif self.to_time < ::Time.mktime(1912,7,30)
10
+ "M#{year - 1867}.#{month}.#{day}"
11
+ elsif self.to_time < ::Time.mktime(1926,12,25)
12
+ "T#{year - 1911}.#{month}.#{day}"
13
+ elsif self.to_time < ::Time.mktime(1989,1,8)
14
+ "S#{year - 1925}.#{month}.#{day}"
15
+ else
16
+ "H#{year - 1988}.#{month}.#{day}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'era_ja'
3
+
4
+ class Date
5
+ include EraJa
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../era_ja', File.dirname(__FILE__))
3
+
4
+ class Time
5
+ include EraJa
6
+ end
@@ -0,0 +1,3 @@
1
+ module EraJa
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../lib/era_ja/date', File.dirname(__FILE__))
3
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
4
+
5
+ describe Date do
6
+ describe "#to_era" do
7
+
8
+ context "date is 2012,4,29" do
9
+ subject { Date.new(2012,4,29).to_era }
10
+ it { should eq "H24.4.29" }
11
+ end
12
+
13
+ context "date is 1989,1,8" do
14
+ subject { Date.new(1989,1,8).to_era }
15
+
16
+ it { should eq "H1.1.8" }
17
+ end
18
+
19
+ context "date is 1989,1,7" do
20
+ subject { Date.new(1989,1,7).to_era }
21
+ it { should eq "S64.1.7" }
22
+ end
23
+
24
+ context "date is 1926,12,25" do
25
+ subject { Date.new(1926,12,25).to_era }
26
+ it { should eq "S1.12.25" }
27
+ end
28
+
29
+ context "date is 1926,12,24" do
30
+ subject { Date.new(1926,12,24).to_era }
31
+ it { should eq "T15.12.24" }
32
+ end
33
+
34
+ context "date is 1912,7,30" do
35
+ subject { Date.new(1912,7,30).to_era }
36
+ it { should eq "T1.7.30" }
37
+ end
38
+
39
+ context "date is 1912,7,29" do
40
+ subject { Date.new(1912,7,29).to_era }
41
+ it { should eq "M45.7.29" }
42
+ end
43
+
44
+ context "date is 1868,9,8" do
45
+ subject { Date.new(1868,9,8).to_era }
46
+ it { should eq "M1.9.8" }
47
+ end
48
+
49
+ context "date is 1868,9,7" do
50
+ it { expect { Date.new(1868,9,7).to_era }.
51
+ to raise_error(RuntimeError, "#to_era is expeted later in 1968,9,8") }
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,2 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rspec'
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../lib/era_ja/time', File.dirname(__FILE__))
3
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
4
+
5
+ describe Time do
6
+ describe "#to_era" do
7
+
8
+ context "time is 2012,4,29" do
9
+ subject { Time.mktime(2012,4,29).to_era }
10
+ it { should eq "H24.4.29" }
11
+ end
12
+
13
+ context "time is 1989,1,8" do
14
+ subject { Time.mktime(1989,1,8).to_era }
15
+
16
+ it { should eq "H1.1.8" }
17
+ end
18
+
19
+ context "time is 1989,1,7" do
20
+ subject { Time.mktime(1989,1,7).to_era }
21
+ it { should eq "S64.1.7" }
22
+ end
23
+
24
+ context "time is 1926,12,25" do
25
+ subject { Time.mktime(1926,12,25).to_era }
26
+ it { should eq "S1.12.25" }
27
+ end
28
+
29
+ context "time is 1926,12,24" do
30
+ subject { Time.mktime(1926,12,24).to_era }
31
+ it { should eq "T15.12.24" }
32
+ end
33
+
34
+ context "time is 1912,7,30" do
35
+ subject { Time.mktime(1912,7,30).to_era }
36
+ it { should eq "T1.7.30" }
37
+ end
38
+
39
+ context "time is 1912,7,29" do
40
+ subject { Time.mktime(1912,7,29).to_era }
41
+ it { should eq "M45.7.29" }
42
+ end
43
+
44
+ context "time is 1868,9,8" do
45
+ subject { Time.mktime(1868,9,8).to_era }
46
+ it { should eq "M1.9.8" }
47
+ end
48
+
49
+ context "time is 1868,9,7" do
50
+ it { expect { Time.mktime(1868,9,7).to_era }.
51
+ to raise_error(RuntimeError, "#to_era is expeted later in 1968,9,8") }
52
+ end
53
+
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: era_ja
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tomi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70163837341380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70163837341380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70163837340780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.9.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70163837340780
36
+ - !ruby/object:Gem::Dependency
37
+ name: growl
38
+ requirement: &70163837340180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.3
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70163837340180
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard-rspec
49
+ requirement: &70163837339620 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70163837339620
58
+ description: Convert to Japanese era.
59
+ email:
60
+ - tomiacannondale@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .document
66
+ - .gitignore
67
+ - .yardopts
68
+ - Gemfile
69
+ - Guardfile
70
+ - LICENSE
71
+ - README.ja.md
72
+ - README.md
73
+ - Rakefile
74
+ - era_ja.gemspec
75
+ - lib/era_ja.rb
76
+ - lib/era_ja/date.rb
77
+ - lib/era_ja/time.rb
78
+ - lib/era_ja/version.rb
79
+ - spec/date_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/time_spec.rb
82
+ homepage: https://github.com/tomiacannondale/era_ja
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -2444577613430226578
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: -2444577613430226578
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.17
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Convert Date or Time instance to String of Japanese era.
112
+ test_files:
113
+ - spec/date_spec.rb
114
+ - spec/spec_helper.rb
115
+ - spec/time_spec.rb