era_ja 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d6d464cb5c1bc163494728e662dcff888a83c45
4
+ data.tar.gz: bee2c4edbec74306347c2af4f93fc71baec4776d
5
+ SHA512:
6
+ metadata.gz: 1fa4e0f19b50dd285b43941bbf66a2a4401ab0870bd9b728a258fad47be17148a6a2a24e57caef80846892f7e804281aded75ed67a50c06113a79f998154986e
7
+ data.tar.gz: 6f2d8354564782403dd624bfd45c8cd6fcc061beb5f6c2e0a7414608b8a3b5771d1a9e6af1538732bc93d4f0fe2fafe54ba3f8374fcc3614e40bd80938e41773
@@ -38,7 +38,7 @@ EraJa#to_eraメソッドでの追加のフォーマット文字列は以下の
38
38
  require 'era_ja/time'
39
39
  Time.mktime(2012,4,29).to_era # => "H24.4.29"
40
40
  Time.mktime(2012,4,29).to_era("%O%E年%m月%d日") # => "平成24年4月29日"
41
- Time.mktime(2012,4,29).to_era("%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
41
+ Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
42
42
  ```
43
43
 
44
44
  ### Dateインタンスを和暦に変換します。
@@ -47,7 +47,7 @@ EraJa#to_eraメソッドでの追加のフォーマット文字列は以下の
47
47
  require 'era_ja/date'
48
48
  Date.new(2012,4,29).to_era # => "H24.4.29"
49
49
  Date.new(2012,4,29).to_era("%O%E年%m月%d日") # => "平成24年4月29日"
50
- Date.new(2012,4,29).to_era("%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
50
+ Date.new(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
51
51
  ```
52
52
 
53
53
  ### 数字を漢数字に変換します。 ###
data/README.md CHANGED
@@ -36,19 +36,19 @@ EraJa#to_era of extra format string is follow.
36
36
  ### Time instance to japanese era
37
37
 
38
38
  ```ruby
39
- require 'era_ja/time'
39
+ require 'era_ja'
40
40
  Time.mktime(2012,4,29).to_era # => "H24.4.29"
41
41
  Time.mktime(2012,4,29).to_era("%O%E年%m月%d日") # => "平成24年4月29日"
42
- Time.mktime(2012,4,29).to_era("%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
42
+ Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
43
43
  ```
44
44
 
45
45
  ### Date instance to japanese era
46
46
 
47
47
  ```ruby
48
- require 'era_ja/date'
48
+ require 'era_ja'
49
49
  Date.new(2012,4,29).to_era # => "H24.4.29"
50
50
  Date.new(2012,4,29).to_era("%O%E年%m月%d日") # => "平成24年4月29日"
51
- Date.new(2012,4,29).to_era("%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
51
+ Date.new(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
52
52
  ```
53
53
 
54
54
  ### Change number to kansuuzi ###
@@ -1,77 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "era_ja/version"
3
- require 'date'
4
-
5
- module EraJa
6
- ERA = [["M", "明治"], ["T", "大正"], ["S", "昭和"], ["H", "平成"]]
7
-
8
- # Convert to Japanese era.
9
- # @param [String] format_string
10
- # Time#strftime format string can be used
11
- # #### extra format string
12
- # * %o - era(alphabet)
13
- # * %O - era(kanzi)
14
- # * %E - era year
15
- # * %J - kanzi number
16
- # @return [String]
17
- def to_era(format = "%o%E.%m.%d")
18
- @era_format = format
19
- @era_format.gsub!(/%J/, "%J%")
20
- @era_format.sub!(/%o/i) { |m| m + ' ' }
21
- @era_format.sub!(/%E/) { |m| m + ' ' }
22
- str_time = strftime(@era_format)
23
- if @era_format =~ /%E/
24
- if self.to_time < ::Time.mktime(1868,9,8)
25
- raise "#to_era is expeted later in 1868,9,8"
26
- elsif self.to_time < ::Time.mktime(1912,7,30)
27
- str_time = era_year(year - 1867, 'M')
28
- elsif self.to_time < ::Time.mktime(1926,12,25)
29
- str_time = era_year(year - 1911, 'T')
30
- elsif self.to_time < ::Time.mktime(1989,1,8)
31
- str_time = era_year(year - 1925, 'S')
32
- else
33
- str_time = era_year(year - 1988, 'H')
34
- end
35
- end
36
- str_time.gsub(/%J(\d+)/) { to_kanzi($1) }
37
- end
38
-
39
- private
40
- def era_year(year, era)
41
- strftime(@era_format).sub(/(%J)?%E /) { format_year(year, $1) }.sub(/%o /i) { format_era(era) }
42
- end
43
-
44
- def format_era(string)
45
- if @era_format =~ /%o/
46
- return "#{ERA.detect{ |i| i[0] == string}[0]}"
47
- elsif @era_format =~ /%O/
48
- return "#{ERA.detect{ |i| i[0] == string}[1]}"
49
- end
50
- end
51
-
52
- def format_year(year, match)
53
- era_year = sprintf("%02d", year)
54
- if match == "%J"
55
- era_year = year == 1 ? "元" : to_kanzi(era_year)
56
- end
57
- era_year
58
- end
59
-
60
- def to_kanzi(numeric, kanzi = "")
61
- figures = (10 ** numeric.to_s.size) / 10
62
- numeric = numeric.to_i
63
- kanzi_string = [nil, "一", "二", "三", "四", "五", "六", "七", "八", "九"]
64
- figures_string = { 1000 => "千", 100 => "百", 10 => "十", 1 => "" }
65
- return kanzi + kanzi_string[numeric] if figures == 1
66
-
67
- numeral = numeric / figures
68
- if numeral > 1
69
- to_kanzi(numeric - numeral * figures, "#{kanzi}#{kanzi_string[numeral]}#{figures_string[figures]}")
70
- elsif numeral == 1
71
- to_kanzi(numeric - numeral * figures, "#{kanzi}#{figures_string[figures]}")
72
- else
73
- to_kanzi(numeric - numeral * figures, kanzi)
74
- end
75
- end
76
-
77
- end
3
+ require "era_ja/date"
4
+ require "era_ja/time"
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'date'
3
+
4
+ module EraJa
5
+ module Conversion
6
+ ERA = [["M", "明治"], ["T", "大正"], ["S", "昭和"], ["H", "平成"]]
7
+
8
+ # Convert to Japanese era.
9
+ # @param [String] format_string
10
+ # Time#strftime format string can be used
11
+ # #### extra format string
12
+ # * %o - era(alphabet)
13
+ # * %O - era(kanzi)
14
+ # * %E - era year
15
+ # * %J - kanzi number
16
+ # @return [String]
17
+ def to_era(format = "%o%E.%m.%d")
18
+ @era_format = format
19
+ @era_format.gsub!(/%J/, "%J%")
20
+ @era_format.sub!(/%o/i) { |m| m + ' ' }
21
+ @era_format.sub!(/%E/) { |m| m + ' ' }
22
+ str_time = strftime(@era_format)
23
+ if @era_format =~ /%E/
24
+ if self.to_time < ::Time.mktime(1868,9,8)
25
+ raise "#to_era is expeted later in 1868,9,8"
26
+ elsif self.to_time < ::Time.mktime(1912,7,30)
27
+ str_time = era_year(year - 1867, 'M')
28
+ elsif self.to_time < ::Time.mktime(1926,12,25)
29
+ str_time = era_year(year - 1911, 'T')
30
+ elsif self.to_time < ::Time.mktime(1989,1,8)
31
+ str_time = era_year(year - 1925, 'S')
32
+ else
33
+ str_time = era_year(year - 1988, 'H')
34
+ end
35
+ end
36
+ str_time.gsub(/%J(\d+)/) { to_kanzi($1) }
37
+ end
38
+
39
+ private
40
+ def era_year(year, era)
41
+ strftime(@era_format).sub(/(%J)?%E /) { format_year(year, $1) }.sub(/%o /i) { format_era(era) }
42
+ end
43
+
44
+ def format_era(string)
45
+ if @era_format =~ /%o/
46
+ return "#{ERA.detect{ |i| i[0] == string}[0]}"
47
+ elsif @era_format =~ /%O/
48
+ return "#{ERA.detect{ |i| i[0] == string}[1]}"
49
+ end
50
+ end
51
+
52
+ def format_year(year, match)
53
+ era_year = sprintf("%02d", year)
54
+ if match == "%J"
55
+ era_year = year == 1 ? "元" : to_kanzi(era_year)
56
+ end
57
+ era_year
58
+ end
59
+
60
+ def to_kanzi(numeric, kanzi = "")
61
+ figures = (10 ** numeric.to_s.size) / 10
62
+ numeric = numeric.to_i
63
+ kanzi_string = [nil, "一", "二", "三", "四", "五", "六", "七", "八", "九"]
64
+ figures_string = { 1000 => "千", 100 => "百", 10 => "十", 1 => "" }
65
+ return kanzi + kanzi_string[numeric] if figures == 1
66
+
67
+ numeral = numeric / figures
68
+ if numeral > 1
69
+ to_kanzi(numeric - numeral * figures, "#{kanzi}#{kanzi_string[numeral]}#{figures_string[figures]}")
70
+ elsif numeral == 1
71
+ to_kanzi(numeric - numeral * figures, "#{kanzi}#{figures_string[figures]}")
72
+ else
73
+ to_kanzi(numeric - numeral * figures, kanzi)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'era_ja'
2
+ require 'era_ja/conversion'
3
3
 
4
4
  class Date
5
- include EraJa
5
+ include EraJa::Conversion
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.expand_path('../era_ja', File.dirname(__FILE__))
2
+ require 'era_ja/conversion'
3
3
 
4
4
  class Time
5
- include EraJa
5
+ include EraJa::Conversion
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module EraJa
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: era_ja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - tomi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: guard-rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rb-fsevent
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: terminal-notifier-guard
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -109,6 +98,7 @@ files:
109
98
  - Rakefile
110
99
  - era_ja.gemspec
111
100
  - lib/era_ja.rb
101
+ - lib/era_ja/conversion.rb
112
102
  - lib/era_ja/date.rb
113
103
  - lib/era_ja/time.rb
114
104
  - lib/era_ja/version.rb
@@ -118,33 +108,26 @@ files:
118
108
  homepage: https://github.com/tomiacannondale/era_ja
119
109
  licenses:
120
110
  - MIT
111
+ metadata: {}
121
112
  post_install_message:
122
113
  rdoc_options: []
123
114
  require_paths:
124
115
  - lib
125
116
  required_ruby_version: !ruby/object:Gem::Requirement
126
- none: false
127
117
  requirements:
128
- - - ! '>='
118
+ - - '>='
129
119
  - !ruby/object:Gem::Version
130
120
  version: '0'
131
- segments:
132
- - 0
133
- hash: -956347074724186715
134
121
  required_rubygems_version: !ruby/object:Gem::Requirement
135
- none: false
136
122
  requirements:
137
- - - ! '>='
123
+ - - '>='
138
124
  - !ruby/object:Gem::Version
139
125
  version: '0'
140
- segments:
141
- - 0
142
- hash: -956347074724186715
143
126
  requirements: []
144
127
  rubyforge_project:
145
- rubygems_version: 1.8.23
128
+ rubygems_version: 2.0.14
146
129
  signing_key:
147
- specification_version: 3
130
+ specification_version: 4
148
131
  summary: Convert Date or Time instance to String of Japanese era.
149
132
  test_files:
150
133
  - spec/date_spec.rb