zakuro 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -0
  3. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  4. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  5. data/lib/zakuro/calculation/base/operated_year.rb +5 -15
  6. data/lib/zakuro/calculation/base/year.rb +26 -14
  7. data/lib/zakuro/calculation/gengou/internal/counter.rb +129 -0
  8. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +183 -0
  9. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +382 -0
  10. data/lib/zakuro/calculation/gengou/internal/reserve.rb +42 -0
  11. data/lib/zakuro/calculation/gengou/scroll.rb +262 -0
  12. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  13. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  14. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  15. data/lib/zakuro/calculation/range/full_range.rb +65 -103
  16. data/lib/zakuro/calculation/range/operated_range.rb +13 -8
  17. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  18. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  19. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  20. data/lib/zakuro/calculation/specifier/single_day.rb +13 -35
  21. data/lib/zakuro/calculation/summary/single.rb +5 -2
  22. data/lib/zakuro/calculation/version/internal/crawler.rb +51 -0
  23. data/lib/zakuro/calculation/version/internal/range.rb +39 -0
  24. data/lib/zakuro/calculation/version/version.rb +24 -0
  25. data/lib/zakuro/era/japan/calendar.rb +133 -0
  26. data/lib/zakuro/era/japan/gengou/parser.rb +95 -25
  27. data/lib/zakuro/era/japan/gengou/type.rb +148 -41
  28. data/lib/zakuro/era/japan/gengou/validator.rb +157 -52
  29. data/lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml +1870 -0
  30. data/lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml +810 -0
  31. data/lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml +50 -0
  32. data/lib/zakuro/era/japan/gengou.rb +5 -5
  33. data/lib/zakuro/era/japan/version.rb +151 -0
  34. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  35. data/lib/zakuro/merchant.rb +12 -3
  36. data/lib/zakuro/operation/month/parser.rb +1 -1
  37. data/lib/zakuro/operation/month/type.rb +1 -1
  38. data/lib/zakuro/operation/month/validator.rb +1 -1
  39. data/lib/zakuro/output/response.rb +5 -5
  40. data/lib/zakuro/tools/typeconv.rb +38 -0
  41. data/lib/zakuro/tools/typeof.rb +4 -1
  42. data/lib/zakuro/version/context.rb +24 -3
  43. data/lib/zakuro/version/daien/daien.rb +1 -26
  44. data/lib/zakuro/version/genka/genka.rb +1 -26
  45. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  46. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  47. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  48. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  49. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  50. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  51. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  52. data/zakuro.gemspec +1 -3
  53. metadata +25 -17
  54. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  55. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  56. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  57. data/lib/zakuro/era/japan/reki.rb +0 -91
  58. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  59. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  60. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  61. data/lib/zakuro/version/abstract_version.rb +0 -29
  62. data/lib/zakuro/version.rb +0 -7
  63. data/lib/zakuro/version_factory.rb +0 -59
data/zakuro.gemspec CHANGED
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/zakuro/version'
4
-
5
3
  Gem::Specification.new do |spec|
6
4
  spec.name = 'zakuro'
7
- spec.version = Zakuro::VERSION
5
+ spec.version = File.read(File.expand_path('./VERSION', __dir__)).strip
8
6
  spec.authors = ['pldb']
9
7
  spec.email = ['pldb.github@gmail.com']
10
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zakuro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pldb
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-07 00:00:00.000000000 Z
11
+ date: 2022-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: mainly lunar solar calendar
14
14
  email:
@@ -26,6 +26,7 @@ files:
26
26
  - Makefile
27
27
  - README.md
28
28
  - Rakefile
29
+ - VERSION
29
30
  - bin/console
30
31
  - bin/setup
31
32
  - doc/gengou.md
@@ -40,13 +41,18 @@ files:
40
41
  - images/各月の求め方.png
41
42
  - images/太陽と月.png
42
43
  - lib/zakuro.rb
43
- - lib/zakuro/calculation/base/multi_gengou.rb
44
- - lib/zakuro/calculation/base/multi_gengou_roller.rb
44
+ - lib/zakuro/calculation/base/gengou.rb
45
+ - lib/zakuro/calculation/base/linear_gengou.rb
45
46
  - lib/zakuro/calculation/base/operated_year.rb
46
47
  - lib/zakuro/calculation/base/year.rb
47
48
  - lib/zakuro/calculation/cycle/abstract_remainder.rb
48
49
  - lib/zakuro/calculation/cycle/abstract_solar_term.rb
49
50
  - lib/zakuro/calculation/cycle/zodiac.rb
51
+ - lib/zakuro/calculation/gengou/internal/counter.rb
52
+ - lib/zakuro/calculation/gengou/internal/reserve.rb
53
+ - lib/zakuro/calculation/gengou/internal/reserve/interval.rb
54
+ - lib/zakuro/calculation/gengou/internal/reserve/list.rb
55
+ - lib/zakuro/calculation/gengou/scroll.rb
50
56
  - lib/zakuro/calculation/monthly/abstract_lunar_phase.rb
51
57
  - lib/zakuro/calculation/monthly/first_day.rb
52
58
  - lib/zakuro/calculation/monthly/initialized_month.rb
@@ -57,7 +63,7 @@ files:
57
63
  - lib/zakuro/calculation/range/medieval_annual_range.rb
58
64
  - lib/zakuro/calculation/range/operated_range.rb
59
65
  - lib/zakuro/calculation/range/operated_solar_terms.rb
60
- - lib/zakuro/calculation/range/transfer/western_date_allocation.rb
66
+ - lib/zakuro/calculation/range/transfer/gengou_scroller.rb
61
67
  - lib/zakuro/calculation/range/transfer/year_boundary.rb
62
68
  - lib/zakuro/calculation/specifier/single_day.rb
63
69
  - lib/zakuro/calculation/stella/lunar/abstract_location.rb
@@ -67,16 +73,20 @@ files:
67
73
  - lib/zakuro/calculation/stella/solar/choukei_value.rb
68
74
  - lib/zakuro/calculation/summary/single.rb
69
75
  - lib/zakuro/calculation/type/old_float.rb
76
+ - lib/zakuro/calculation/version/internal/crawler.rb
77
+ - lib/zakuro/calculation/version/internal/range.rb
78
+ - lib/zakuro/calculation/version/version.rb
70
79
  - lib/zakuro/condition.rb
80
+ - lib/zakuro/era/japan/calendar.rb
71
81
  - lib/zakuro/era/japan/gengou.rb
72
82
  - lib/zakuro/era/japan/gengou/parser.rb
73
83
  - lib/zakuro/era/japan/gengou/type.rb
74
84
  - lib/zakuro/era/japan/gengou/validator.rb
75
- - lib/zakuro/era/japan/reki.rb
76
- - lib/zakuro/era/japan/yaml/set-001-until-south.yaml
77
- - lib/zakuro/era/japan/yaml/set-002-from-north.yaml
78
- - lib/zakuro/era/japan/yaml/set-003-modern.yaml
79
- - lib/zakuro/era/western.rb
85
+ - lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml
86
+ - lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml
87
+ - lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml
88
+ - lib/zakuro/era/japan/version.rb
89
+ - lib/zakuro/era/western/calendar.rb
80
90
  - lib/zakuro/merchant.rb
81
91
  - lib/zakuro/operation/month/parser.rb
82
92
  - lib/zakuro/operation/month/type.rb
@@ -91,9 +101,8 @@ files:
91
101
  - lib/zakuro/result/operation.rb
92
102
  - lib/zakuro/result/result.rb
93
103
  - lib/zakuro/tools/stringifier.rb
104
+ - lib/zakuro/tools/typeconv.rb
94
105
  - lib/zakuro/tools/typeof.rb
95
- - lib/zakuro/version.rb
96
- - lib/zakuro/version/abstract_version.rb
97
106
  - lib/zakuro/version/context.rb
98
107
  - lib/zakuro/version/daien/const/number.rb
99
108
  - lib/zakuro/version/daien/const/remainder.rb
@@ -169,7 +178,6 @@ files:
169
178
  - lib/zakuro/version/senmyou/stella/solar/value.rb
170
179
  - lib/zakuro/version/tenpou/tenpou.rb
171
180
  - lib/zakuro/version/version_class_resolver.rb
172
- - lib/zakuro/version_factory.rb
173
181
  - zakuro.gemspec
174
182
  homepage: https://github.com/pldb/zakuro
175
183
  licenses:
@@ -179,7 +187,7 @@ metadata:
179
187
  homepage_uri: https://github.com/pldb/zakuro
180
188
  source_code_uri: https://github.com/pldb/zakuro
181
189
  changelog_uri: https://github.com/pldb/zakuro
182
- post_install_message:
190
+ post_install_message:
183
191
  rdoc_options: []
184
192
  require_paths:
185
193
  - lib
@@ -194,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
202
  - !ruby/object:Gem::Version
195
203
  version: '0'
196
204
  requirements: []
197
- rubygems_version: 3.1.2
198
- signing_key:
205
+ rubygems_version: 3.1.4
206
+ signing_key:
199
207
  specification_version: 4
200
208
  summary: japanese calendar library.
201
209
  test_files: []
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../era/japan/gengou'
4
- require_relative '../../era/western'
5
-
6
- # :nodoc:
7
- module Zakuro
8
- # :nodoc:
9
- module Calculation
10
- # :nodoc:
11
- module Base
12
- #
13
- # MultiGengou 複数元号
14
- #
15
- class MultiGengou
16
- # @return [Japan::Gengou] 元号(1行目)
17
- attr_reader :first_line
18
- # @return [Japan::Gengou] 元号(2行目)
19
- attr_reader :second_line
20
- # @return [Western::Calendar] 元旦
21
- attr_reader :new_year_date
22
-
23
- def initialize(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new,
24
- new_year_date: Western::Calendar.new)
25
- @first_line = first_line
26
- @second_line = second_line
27
- @new_year_date = new_year_date
28
- end
29
-
30
- # :reek:TooManyStatements { max_statements: 7 }
31
-
32
- #
33
- # 改元する
34
- #
35
- # @param [Japan::Gengou] first_line 元号(1行目)
36
- # @param [Japan::Gengou] second_line 元号(2行目)
37
- #
38
- # @return [MultiGengou] 自身
39
- #
40
- def transfer(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new)
41
- cloned_first_line = first_line.clone
42
- cloned_second_line = second_line.clone
43
-
44
- if integrated?(first_line: cloned_first_line, second_line: cloned_second_line)
45
- @first_line = @second_line.clone
46
- @second_line = cloned_second_line
47
- end
48
-
49
- @first_line = cloned_first_line if @first_line.name != first_line.name
50
- @second_line = cloned_second_line if @second_line.name != second_line.name
51
-
52
- self
53
- end
54
-
55
- #
56
- # 次年にする
57
- #
58
- # @param [Japan::Gengou] first_line 元号(1行目)
59
- # @param [Japan::Gengou] second_line 元号(2行目)
60
- #
61
- # @return [MultiGengou] 自身
62
- #
63
- def next_year
64
- @first_line.next_year
65
- @second_line.next_year
66
-
67
- self
68
- end
69
-
70
- #
71
- # ディープコピー
72
- #
73
- # @param [MultiGengou] obj 自身
74
- #
75
- def initialize_copy(obj)
76
- @first_line = obj.first_line.clone
77
- @second_line = obj.second_line.clone
78
- end
79
-
80
- private
81
-
82
- #
83
- # 複数元号を統一するかどうか
84
- #
85
- # @param [Japan::Gengou] first_line 元号(1行目)
86
- # @param [Japan::Gengou] second_line 元号(2行目)
87
- #
88
- # @return [True] 統一する
89
- # @return [False] 統一しない
90
- #
91
- def integrated?(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new)
92
- return false if @second_line.name != first_line.name
93
-
94
- return false unless second_line.invalid?
95
-
96
- true
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,218 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './multi_gengou'
4
-
5
- require_relative '../../era/japan/gengou'
6
-
7
- # :nodoc:
8
- module Zakuro
9
- # :nodoc:
10
- module Calculation
11
- # :nodoc:
12
- module Base
13
- #
14
- # MultiGengouRoller 改元処理
15
- #
16
- class MultiGengouRoller
17
- # @return [MultiGengou] 複数元号
18
- attr_reader :multi_gengou
19
- # @return [Western::Calendar] 元旦(元号が2つある場合は再過去の日付になる)
20
- attr_reader :oldest_date
21
- # @return [Western::Calendar] 元号内での最未来日(元号が2つある場合は再未来の日付になる)
22
- attr_reader :newest_date
23
- # @return [Western::Calendar] 現在日
24
- attr_reader :current_date
25
-
26
- def initialize(start_date: Western::Calendar.new, end_date: Western::Calendar.new)
27
- end_date = start_date if end_date.invalid?
28
-
29
- @oldest_date = MultiGengouRoller.choise_oldest_gengou_date(
30
- first_line: MultiGengouRoller.first_line(date: start_date),
31
- second_line: MultiGengouRoller.second_line(date: start_date)
32
- )
33
- @current_date = @oldest_date.clone
34
- @newest_date = MultiGengouRoller.choise_newest_gengou_date(
35
- first_line: MultiGengouRoller.first_line(date: end_date),
36
- second_line: MultiGengouRoller.second_line(date: end_date)
37
- )
38
-
39
- @multi_gengou = MultiGengou.new(
40
- first_line: current_first_line,
41
- second_line: current_second_line,
42
- new_year_date: @oldest_date
43
- )
44
- end
45
-
46
- #
47
- # 現在日付を未来に進める
48
- #
49
- # @param [<Type>] days <description>
50
- #
51
- # @return [<Type>] <description>
52
- #
53
- def next(days: 0)
54
- @current_date += days
55
- end
56
-
57
- #
58
- # 現在日から元号(1行目)を取得する
59
- #
60
- # @return [Japan::Gengou] 元号(1行目)
61
- #
62
- def current_first_line
63
- MultiGengouRoller.first_line(date: @current_date)
64
- end
65
-
66
- #
67
- # 現在日から元号(2行目)を取得する
68
- #
69
- # @return [Japan::Gengou] 元号(2行目)
70
- #
71
- def current_second_line
72
- MultiGengouRoller.second_line(date: @current_date)
73
- end
74
-
75
- #
76
- # 改元する
77
- #
78
- # @return [MultiGengou] 複数元号
79
- #
80
- def transfer
81
- MultiGengouRoller.transfer(multi_gengou: @multi_gengou, date: @current_date)
82
- end
83
-
84
- #
85
- # 次年にする
86
- #
87
- # @return [MultiGengou] 複数元号
88
- #
89
- def next_year
90
- @multi_gengou.next_year
91
- end
92
-
93
- #
94
- # 元号(1行目)を取得する
95
- #
96
- # @return [Japan::Gengou] 元号(1行目)
97
- #
98
- def self.first_line(date: Western::Calender.new)
99
- Japan::GengouResource.first_line(date: date)
100
- end
101
-
102
- #
103
- # 元号(2行目)を取得する
104
- #
105
- # @return [Japan::Gengou] 元号(2行目)
106
- #
107
- def self.second_line(date: Western::Calender.new)
108
- Japan::GengouResource.second_line(date: date)
109
- end
110
-
111
- #
112
- # 改元する
113
- #
114
- # @param [MultiGengou] multi_gengou 複数元号
115
- # @param [Western::Calendar] date 対象日
116
- #
117
- # @return [MultiGengou] 改元済み複数元号
118
- #
119
- def self.transfer(multi_gengou:, date:)
120
- multi_gengou.transfer(
121
- first_line: first_line(date: date),
122
- second_line: second_line(date: date)
123
- )
124
-
125
- multi_gengou
126
- end
127
-
128
- #
129
- # 現在日からみて直近の未来に対する元号の切替前日を求める
130
- # @note 2つの元号が重複した場合はより過去の日となる
131
- #
132
- # @param [Japan::Gengou] first_line 元号(1行目)
133
- # @param [Japan::Gengou] second_line 元号(2行目)
134
- #
135
- # @return [Western::Calendar] 元号の切替前日
136
- #
137
- def choise_nearest_end_date
138
- condition = lambda do |first_date, second_date|
139
- first_date < second_date ? first_date : second_date
140
- end
141
-
142
- second_line = current_second_line
143
-
144
- MultiGengouRoller.choise_date(condition: condition, second_line: second_line,
145
- first_date: current_first_line.end_date.clone,
146
- second_date: second_line.end_date.clone)
147
- end
148
-
149
- #
150
- # 最過去の元旦を求める
151
- # @note 2つの元号が重複した場合はより過去の日となる
152
- #
153
- # @param [Japan::Gengou] first_line 元号(1行目)
154
- # @param [Japan::Gengou] second_line 元号(2行目)
155
- #
156
- # @return [Western::Calendar] 最過去の元旦
157
- #
158
- def self.choise_oldest_gengou_date(first_line:, second_line:)
159
- condition = lambda do |first_date, second_date|
160
- first_date < second_date ? first_date : second_date
161
- end
162
- choise_date(condition: condition, second_line: second_line,
163
- first_date: first_line.new_year_date.clone,
164
- second_date: second_line.new_year_date.clone)
165
- end
166
-
167
- #
168
- # 元号内での最未来日を求める
169
- # @note 2つの元号が重複した場合はより未来の日となる
170
- #
171
- # @param [Japan::Gengou] first_line 元号(1行目)
172
- # @param [Japan::Gengou] second_line 元号(2行目)
173
- #
174
- # @return [Western::Calendar] 最未来日
175
- #
176
- def self.choise_newest_gengou_date(first_line:, second_line:)
177
- condition = lambda do |first_date, second_date|
178
- first_date > second_date ? first_date : second_date
179
- end
180
- choise_date(condition: condition, second_line: second_line,
181
- first_date: first_line.end_date.clone,
182
- second_date: second_line.end_date.clone)
183
- end
184
-
185
- # :reek:LongParameterList {max_params: 4}
186
-
187
- #
188
- # 条件を元に日付を求める
189
- #
190
- # @param [Proc] condition 比較条件
191
- # @param [Japan::Gengou] second_line 元号(2行目)
192
- # @param [Western::Calendar] first_date 比較対象(1行目)
193
- # @param [Western::Calendar] second_date 比較対象(2行目)
194
- #
195
- # @return [Western::Calendar] 比較結果
196
- #
197
- def self.choise_date(condition:, second_line:, first_date:, second_date:)
198
- # first_lineは常に存在する
199
- return first_date if second_line.invalid?
200
-
201
- condition.call(first_date, second_date)
202
- end
203
-
204
- #
205
- # ディープコピー
206
- #
207
- # @param [MultiGengou] obj 自身
208
- #
209
- def initialize_copy(obj)
210
- @oldest_date = obj.oldest_date.clone
211
- @current_date = obj.current_date.clone
212
- @newest_date = obj.newest_date.clone
213
- @multi_gengou = obj.multi_gengou.clone
214
- end
215
- end
216
- end
217
- end
218
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Calculation
7
- # :nodoc:
8
- module Range
9
- # :nodoc:
10
- module Transfer
11
- #
12
- # WesternDateAllocation 西暦日の割り当て
13
- #
14
- module WesternDateAllocation
15
- #
16
- # 月初日の西暦日を更新する
17
- #
18
- # @param [Context] context 暦コンテキスト
19
- # @param [Array<Year>] years 完全範囲(月初日なし)
20
- #
21
- # @return [Array<Year>] 完全範囲(月初日あり)
22
- #
23
- def self.get(context:, years:)
24
- update_first_day(context: context, years: years)
25
-
26
- years
27
- end
28
-
29
- #
30
- # 月初日の西暦日を更新する
31
- #
32
- # @param [Context] context 暦コンテキスト
33
- # @param [Array<Year>] years 完全範囲(月初日なし)
34
- #
35
- def self.update_first_day(context:, years:)
36
- years.each_with_index do |year, index|
37
- new_year_date = year.new_year_date.clone
38
-
39
- months = year.months
40
- update_first_day_within_all_months(
41
- context: context,
42
- new_year_date: new_year_date, months: months
43
- )
44
-
45
- years[index] = Base::Year.new(
46
- multi_gengou: year.multi_gengou, new_year_date: new_year_date,
47
- months: months, total_days: year.total_days
48
- )
49
- end
50
- end
51
-
52
- #
53
- # 全ての月で月初日の西暦日を更新する
54
- #
55
- # @param [Context] context 暦コンテキスト
56
- # @param [Western::Calendar] new_year_date 元旦
57
- # @param [Array<Month>] months 月データ
58
- #
59
- def self.update_first_day_within_all_months(context:,
60
- new_year_date:, months:)
61
- date = new_year_date.clone
62
- months.each_with_index do |month, index|
63
- updated_month = Monthly::Month.new(
64
- context: context,
65
- month_label: month.month_label,
66
- first_day: Monthly::FirstDay.new(
67
- remainder: month.first_day.remainder,
68
- western_date: date
69
- ),
70
- solar_terms: month.solar_terms
71
- )
72
- months[index] = updated_month
73
-
74
- date = date.clone + updated_month.days
75
- end
76
- end
77
- private_class_method :update_first_day_within_all_months
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../western'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- #
8
- # Japan 和暦
9
- #
10
- module Japan
11
- #
12
- # Reki 暦
13
- #
14
- module Reki
15
- #
16
- # Range 暦(範囲)
17
- #
18
- class Range
19
- # @return [String] 暦のクラス名
20
- # version 以下を参照
21
- attr_reader :class_name
22
- # @return [Western::Calendar] 暦の開始日
23
- attr_reader :start_date
24
-
25
- #
26
- # 初期化
27
- #
28
- # @param [String] class_name 暦のクラス名
29
- # @param [Western::Calendar] start_date 暦の開始日
30
- #
31
- def initialize(class_name:, start_date:)
32
- @class_name = class_name
33
- @start_date = start_date
34
- end
35
- end
36
-
37
- LIST = [
38
- Range.new(
39
- class_name: 'Zakuro::Genka::Gateway',
40
- start_date: Western::Calendar.new(year: 445, month: 1, day: 24)
41
- ),
42
- Range.new(
43
- class_name: 'Zakuro::Gihou::Gateway',
44
- start_date: Western::Calendar.new(year: 698, month: 2, day: 16)
45
- ),
46
- Range.new(
47
- class_name: 'Zakuro::Daien::Gateway',
48
- start_date: Western::Calendar.new(year: 764, month: 2, day: 7)
49
- ),
50
- Range.new(
51
- class_name: 'Zakuro::Senmyou::Gateway',
52
- start_date: Western::Calendar.new(year: 862, month: 2, day: 3)
53
- ),
54
- Range.new(
55
- class_name: 'Zakuro::Joukyou::Gateway',
56
- start_date: Western::Calendar.new(year: 1685, month: 2, day: 4)
57
- ),
58
- Range.new(
59
- class_name: 'Zakuro::Houryaku::Gateway',
60
- start_date: Western::Calendar.new(year: 1755, month: 2, day: 11)
61
- ),
62
- Range.new(
63
- class_name: 'Zakuro::Kansei::Gateway',
64
- start_date: Western::Calendar.new(year: 1798, month: 2, day: 16)
65
- ),
66
- Range.new(
67
- class_name: 'Zakuro::Tenpou::Gateway',
68
- start_date: Western::Calendar.new(year: 1844, month: 2, day: 18)
69
- ),
70
- Range.new(
71
- class_name: 'Zakuro::Gregorio::Gateway',
72
- start_date: Western::Calendar.new(year: 1872, month: 12, day: 9)
73
- )
74
- ].freeze
75
-
76
- #
77
- # 指定した日付から対象の暦を引き当てる
78
- #
79
- # @param [Western::Calendar] date 日付
80
- #
81
- # @return [String] 暦のクラス名
82
- #
83
- def self.class_name(date: Western::Calendar.new)
84
- LIST.reverse_each do |range|
85
- return range.class_name if date >= range.start_date
86
- end
87
- raise ArgumentError, "invalid date: #{date.format}"
88
- end
89
- end
90
- end
91
- end