zakuro 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/README.md +41 -8
  4. data/VERSION +1 -1
  5. data/doc/gengou.md +1 -1
  6. data/doc/operation/csv/month.csv +8 -9
  7. data/doc/operation/operation.xlsx +0 -0
  8. data/images/logo-text.png +0 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +2 -4
  10. data/lib/zakuro/calculation/base/year.rb +1 -1
  11. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +6 -0
  12. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +2 -2
  13. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +4 -2
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +1 -1
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +13 -7
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +18 -9
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +6 -2
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +5 -2
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +3 -3
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +12 -4
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +10 -4
  22. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +5 -2
  23. data/lib/zakuro/calculation/era/version/internal/crawler.rb +3 -3
  24. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +1 -1
  25. data/lib/zakuro/calculation/monthly/internal/date_comparer.rb +78 -0
  26. data/lib/zakuro/calculation/monthly/{meta → internal/meta}/all_solar_term.rb +1 -1
  27. data/lib/zakuro/calculation/monthly/{meta → internal/meta}/meta_collector.rb +2 -2
  28. data/lib/zakuro/calculation/monthly/{first_day.rb → internal/part/first_day.rb} +2 -2
  29. data/lib/zakuro/calculation/monthly/{meta.rb → internal/part/meta.rb} +1 -1
  30. data/lib/zakuro/calculation/monthly/internal/solar_term_selector.rb +203 -0
  31. data/lib/zakuro/calculation/monthly/month.rb +38 -74
  32. data/lib/zakuro/calculation/monthly/operated_month.rb +7 -2
  33. data/lib/zakuro/calculation/option/dropped_date/location.rb +8 -1
  34. data/lib/zakuro/calculation/range/dated_full_range.rb +6 -3
  35. data/lib/zakuro/calculation/range/dated_operation_range.rb +2 -1
  36. data/lib/zakuro/calculation/range/medieval_annual_range.rb +0 -2
  37. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  38. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +24 -10
  39. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +3 -3
  40. data/lib/zakuro/calculation/summary/internal/option/dropped_date.rb +102 -0
  41. data/lib/zakuro/calculation/summary/internal/option/vanished_date.rb +111 -0
  42. data/lib/zakuro/calculation/summary/internal/option.rb +4 -137
  43. data/lib/zakuro/calculation/summary/japan/range.rb +4 -5
  44. data/lib/zakuro/calculation/summary/western/range.rb +8 -1
  45. data/lib/zakuro/calculation/summary/western/single.rb +10 -5
  46. data/lib/zakuro/context/version_class_resolver.rb +5 -5
  47. data/lib/zakuro/era/japan/calendar.rb +4 -4
  48. data/lib/zakuro/era/japan/gengou/alignment/division.rb +2 -2
  49. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +2 -2
  50. data/lib/zakuro/era/japan/gengou/alignment.rb +35 -6
  51. data/lib/zakuro/era/japan/gengou/resource/parser.rb +17 -16
  52. data/lib/zakuro/era/japan/gengou/resource/validator.rb +3 -394
  53. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +2 -2
  54. data/lib/zakuro/era/japan/gengou.rb +8 -6
  55. data/lib/zakuro/era/japan/type/base/both/date.rb +51 -0
  56. data/lib/zakuro/era/japan/type/base/both/year.rb +53 -0
  57. data/lib/zakuro/era/japan/type/base/gengou.rb +177 -0
  58. data/lib/zakuro/era/japan/type/base/gengou_set.rb +78 -0
  59. data/lib/zakuro/era/japan/type/base/switch_date.rb +74 -0
  60. data/lib/zakuro/era/japan/type/base/version_range.rb +189 -0
  61. data/lib/zakuro/era/japan/type/validation/both/date.rb +99 -0
  62. data/lib/zakuro/era/japan/type/validation/both/year.rb +75 -0
  63. data/lib/zakuro/era/japan/type/validation/gengou.rb +93 -0
  64. data/lib/zakuro/era/japan/type/validation/gengou_set.rb +133 -0
  65. data/lib/zakuro/era/japan/type/validation/switch_date.rb +73 -0
  66. data/lib/zakuro/era/japan/type/validation/version_range.rb +109 -0
  67. data/lib/zakuro/era/japan/type/validation/version_root.rb +102 -0
  68. data/lib/zakuro/era/japan/version/resource/parser.rb +266 -0
  69. data/lib/zakuro/era/japan/version/resource/validator.rb +37 -0
  70. data/lib/zakuro/era/japan/version/resource/yaml/version.yaml +80 -0
  71. data/lib/zakuro/era/japan/version/resource.rb +22 -0
  72. data/lib/zakuro/era/japan/version.rb +4 -115
  73. data/lib/zakuro/era/western/calendar.rb +2 -2
  74. data/lib/zakuro/exception/zakuro_error.rb +1 -1
  75. data/lib/zakuro/merchant.rb +5 -5
  76. data/lib/zakuro/operation/month/parser.rb +2 -2
  77. data/lib/zakuro/operation/yaml/month.yaml +8 -40
  78. data/lib/zakuro/output/logger.rb +4 -4
  79. data/lib/zakuro/parameter/catalog/basis_date.rb +55 -0
  80. data/lib/zakuro/parameter/catalog/column.rb +57 -0
  81. data/lib/zakuro/parameter/catalog/option.rb +60 -0
  82. data/lib/zakuro/parameter/catalog/range.rb +81 -0
  83. data/lib/zakuro/parameter/condition.rb +108 -0
  84. data/lib/zakuro/result/core.rb +2 -2
  85. data/lib/zakuro/{tools → tool}/remainder_comparer.rb +3 -2
  86. data/lib/zakuro/{tools → tool}/stringifier.rb +3 -3
  87. data/lib/zakuro/{tools → tool}/typeconv.rb +2 -2
  88. data/lib/zakuro/{tools → tool}/typeof.rb +2 -2
  89. data/lib/zakuro/version/daien/const/number.rb +42 -39
  90. data/lib/zakuro/version/daien/const/remainder.rb +38 -35
  91. data/lib/zakuro/version/daien/cycle/remainder.rb +77 -74
  92. data/lib/zakuro/version/daien/cycle/solar_term.rb +18 -15
  93. data/lib/zakuro/version/daien/daien.rb +8 -5
  94. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +67 -64
  95. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +15 -12
  96. data/lib/zakuro/version/daien/option/vanished_date/parameter.rb +15 -12
  97. data/lib/zakuro/version/daien/range/annual_range.rb +27 -24
  98. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +209 -206
  99. data/lib/zakuro/version/daien/stella/lunar/localization.rb +32 -29
  100. data/lib/zakuro/version/daien/stella/lunar/location.rb +53 -50
  101. data/lib/zakuro/version/daien/stella/lunar/value.rb +65 -62
  102. data/lib/zakuro/version/daien/stella/origin/average_november.rb +23 -20
  103. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +42 -39
  104. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +44 -41
  105. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +74 -71
  106. data/lib/zakuro/version/daien/stella/solar/average.rb +68 -65
  107. data/lib/zakuro/version/daien/stella/solar/interval.rb +95 -92
  108. data/lib/zakuro/version/daien/stella/solar/location.rb +41 -38
  109. data/lib/zakuro/version/daien/stella/solar/value.rb +21 -18
  110. data/lib/zakuro/version/genka/const/number.rb +31 -28
  111. data/lib/zakuro/version/genka/const/remainder.rb +20 -17
  112. data/lib/zakuro/version/genka/cycle/remainder.rb +72 -69
  113. data/lib/zakuro/version/genka/cycle/solar_term.rb +18 -15
  114. data/lib/zakuro/version/genka/genka.rb +8 -5
  115. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +82 -79
  116. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +13 -10
  117. data/lib/zakuro/version/genka/option/vanished_date/parameter.rb +13 -10
  118. data/lib/zakuro/version/genka/range/annual_range.rb +57 -54
  119. data/lib/zakuro/version/genka/stella/origin/first_term.rb +44 -41
  120. data/lib/zakuro/version/genka/stella/origin/january.rb +38 -35
  121. data/lib/zakuro/version/genka/stella/solar/average.rb +24 -21
  122. data/lib/zakuro/version/gihou/const/number.rb +40 -37
  123. data/lib/zakuro/version/gihou/const/remainder.rb +32 -29
  124. data/lib/zakuro/version/gihou/cycle/remainder.rb +38 -35
  125. data/lib/zakuro/version/gihou/cycle/solar_term.rb +18 -15
  126. data/lib/zakuro/version/gihou/gihou.rb +8 -5
  127. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +68 -65
  128. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +13 -10
  129. data/lib/zakuro/version/gihou/option/vanished_date/parameter.rb +13 -10
  130. data/lib/zakuro/version/gihou/range/annual_range.rb +27 -24
  131. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +212 -209
  132. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +32 -29
  133. data/lib/zakuro/version/gihou/stella/lunar/location.rb +53 -50
  134. data/lib/zakuro/version/gihou/stella/lunar/value.rb +65 -62
  135. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +23 -20
  136. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +42 -39
  137. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +44 -41
  138. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +74 -71
  139. data/lib/zakuro/version/gihou/stella/solar/average.rb +67 -64
  140. data/lib/zakuro/version/gihou/stella/solar/interval.rb +95 -92
  141. data/lib/zakuro/version/gihou/stella/solar/location.rb +41 -38
  142. data/lib/zakuro/version/gihou/stella/solar/value.rb +21 -18
  143. data/lib/zakuro/version/gregorio/gregorio.rb +8 -5
  144. data/lib/zakuro/version/houryaku/houryaku.rb +8 -5
  145. data/lib/zakuro/version/joukyou/joukyou.rb +8 -5
  146. data/lib/zakuro/version/kansei/kansei.rb +8 -5
  147. data/lib/zakuro/version/senmyou/const/number.rb +40 -37
  148. data/lib/zakuro/version/senmyou/const/remainder.rb +35 -32
  149. data/lib/zakuro/version/senmyou/cycle/remainder.rb +74 -71
  150. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +18 -15
  151. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +69 -66
  152. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +15 -12
  153. data/lib/zakuro/version/senmyou/option/vanished_date/parameter.rb +15 -12
  154. data/lib/zakuro/version/senmyou/range/annual_range.rb +27 -24
  155. data/lib/zakuro/version/senmyou/senmyou.rb +8 -5
  156. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +206 -203
  157. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +32 -29
  158. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +60 -57
  159. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -63
  160. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +23 -20
  161. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +42 -39
  162. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +44 -41
  163. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +74 -71
  164. data/lib/zakuro/version/senmyou/stella/solar/average.rb +67 -64
  165. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +93 -90
  166. data/lib/zakuro/version/senmyou/stella/solar/location.rb +41 -38
  167. data/lib/zakuro/version/senmyou/stella/solar/value.rb +23 -20
  168. data/lib/zakuro/version/tenpou/tenpou.rb +8 -5
  169. metadata +40 -15
  170. data/lib/zakuro/condition.rb +0 -306
  171. data/lib/zakuro/era/japan/gengou/resource/type.rb +0 -356
  172. /data/lib/zakuro/calculation/monthly/{operated_solar_term.rb → internal/operated_solar_term.rb} +0 -0
  173. /data/lib/zakuro/calculation/monthly/{const.rb → internal/part/const.rb} +0 -0
  174. /data/lib/zakuro/calculation/monthly/{month_label.rb → internal/part/month_label.rb} +0 -0
@@ -0,0 +1,266 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../type/base/version_range'
4
+ require_relative './validator'
5
+ require 'yaml'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Japan
11
+ # :nodoc:
12
+ module Version
13
+ #
14
+ # Resource yaml解析結果
15
+ #
16
+ module Resource
17
+ #
18
+ # Parser yaml解析
19
+ #
20
+ module Parser
21
+ #
22
+ # RangeParser 暦期間情報の検証/展開を行う
23
+ #
24
+ class RangeParser
25
+ # @return [Integer] 要素位置
26
+ attr_reader :index
27
+ # @return [String] 暦名
28
+ attr_reader :name
29
+ # @return [Hash<String, String>] 開始年
30
+ attr_reader :start_year
31
+ # @return [Hash<String, String>] 開始日
32
+ attr_reader :start_date
33
+ # @return [True] リリース有
34
+ # @return [False] リリース無
35
+ attr_reader :released
36
+
37
+ #
38
+ # 初期化
39
+ #
40
+ # @param [Hash<String, Strin>] hash 元号情報
41
+ # @param [Integer] index (元号セット内での)元号の要素位置
42
+ #
43
+ def initialize(hash:, index:)
44
+ @index = index
45
+ @name = hash['name']
46
+ @start_year = hash['start_year']
47
+ @start_date = hash['start_date']
48
+ @released = hash['released']
49
+ end
50
+
51
+ #
52
+ # 暦期間情報を生成する
53
+ #
54
+ # @return [Range] 暦期間情報
55
+ #
56
+ def create
57
+ year = Both::YearParser.new(hash: start_year).create
58
+ date = Both::DateParser.new(hash: start_date).create
59
+
60
+ Type::Base::VersionRange.new(
61
+ name: name, start_year: year,
62
+ start_date: date, released: released
63
+ )
64
+ end
65
+ end
66
+
67
+ #
68
+ # RootParser 暦期間情報の検証/展開
69
+ #
70
+ class RootParser
71
+ # @return [Hash<String, String>] 終了年
72
+ attr_reader :last_year
73
+ # @return [Hash<String, String>] 終了日
74
+ attr_reader :last_date
75
+ # @return [Array<Hash<String, String>>] 暦期間情報
76
+ attr_reader :list
77
+
78
+ #
79
+ # 初期化
80
+ #
81
+ # @param [Hash<String, Object>] hash 暦期間情報
82
+ #
83
+ def initialize(hash:)
84
+ @id = hash['id']
85
+ @name = hash['name']
86
+ @last_year = hash['last_year']
87
+ @last_date = hash['last_date']
88
+ @list = hash['list']
89
+ end
90
+
91
+ #
92
+ # 暦期間情報を生成する
93
+ #
94
+ # @return [Array<Range>] 暦期間情報
95
+ #
96
+ def create
97
+ Both::DateParser.new(hash: last_date).create
98
+
99
+ create_list
100
+ end
101
+
102
+ # :reek:TooManyStatements { max_statements: 7 }
103
+
104
+ #
105
+ # 暦期間情報を生成する
106
+ #
107
+ # @return [Array<Range>] 暦期間情報
108
+ #
109
+ def create_list
110
+ result = []
111
+ list.each_with_index do |li, index|
112
+ range = RangeParser.new(hash: li, index: index).create
113
+ next_index = index + 1
114
+ range = calc_last_date_on_range_data(next_index: next_index,
115
+ range: range)
116
+ result.push(range)
117
+ end
118
+
119
+ result
120
+ end
121
+
122
+ #
123
+ # 次の暦期間の開始日から、暦期間の終了日に変換する
124
+ #
125
+ # @param [Integer] next_index 次の暦期間の要素位置
126
+ # @param [RangeParser] range 暦期間
127
+ #
128
+ # @return [Range] 暦期間情報
129
+ #
130
+ def calc_last_date_on_range_data(next_index:, range:)
131
+ if next_index >= list.size
132
+ last_range_data(range: range)
133
+ return range
134
+ end
135
+ next_item = list[next_index]
136
+ next_start_date = Both::DateParser.new(
137
+ hash: next_item['start_date']
138
+ ).create
139
+
140
+ range.convert_next_start_year_to_last_year(
141
+ next_start_year: next_item['start_year']['western']
142
+ )
143
+ range.convert_next_start_date_to_last_date(
144
+ next_start_date: next_start_date.western
145
+ )
146
+ range
147
+ end
148
+
149
+ private
150
+
151
+ #
152
+ # 最後の元号の終了日を設定する
153
+ #
154
+ # @param [RangeParser] range 暦期間情報
155
+ #
156
+ def last_range_data(range:)
157
+ range.write_last_year(last_year: last_year['western'])
158
+
159
+ date = Both::DateParser.new(hash: last_date).create
160
+
161
+ range.write_last_date(last_date: date.western)
162
+ end
163
+ end
164
+
165
+ #
166
+ # 和暦/西暦
167
+ #
168
+ module Both
169
+ #
170
+ # YearParser 年
171
+ #
172
+ class YearParser
173
+ # @return [Integer] 和暦元号年
174
+ attr_reader :japan
175
+ # @return [Integer] 西暦年
176
+ attr_reader :western
177
+
178
+ #
179
+ # 初期化
180
+ #
181
+ # @param [Hash<String, Object>] hash 年情報
182
+ #
183
+ def initialize(hash:)
184
+ @japan = hash['japan']
185
+ @western = hash['western']
186
+ end
187
+
188
+ #
189
+ # 年情報を生成する
190
+ #
191
+ # @return [Type::Base::Both::Year] 年情報
192
+ #
193
+ def create
194
+ japan_year = japan.to_i
195
+ western_year = western.to_i
196
+
197
+ Type::Base::Both::Year.new(
198
+ japan: japan_year, western: western_year
199
+ )
200
+ end
201
+ end
202
+
203
+ #
204
+ # DateParser 日
205
+ #
206
+ class DateParser
207
+ # @return [Japan::Calendar] 和暦日
208
+ attr_reader :japan
209
+ # @return [Western::Calendar] 西暦日
210
+ attr_reader :western
211
+
212
+ #
213
+ # 初期化
214
+ #
215
+ # @param [Hash<String, Object>] hash 日情報
216
+ #
217
+ def initialize(hash:)
218
+ @japan = hash['japan']
219
+ @western = hash['western']
220
+ end
221
+
222
+ #
223
+ # 日情報を生成する
224
+ #
225
+ # @return [Type::Base::Both::Date] 日情報
226
+ #
227
+ def create
228
+ japan_date = Japan::Calendar.new
229
+ western_date = Western::Calendar.new
230
+
231
+ japan_date = Japan::Calendar.parse(text: japan) unless japan == ''
232
+ western_date = Western::Calendar.parse(text: western) unless western == ''
233
+
234
+ Type::Base::Both::Date.new(
235
+ japan: japan_date, western: western_date
236
+ )
237
+ end
238
+ end
239
+ end
240
+
241
+ class << self
242
+ #
243
+ # 解析/展開する
244
+ #
245
+ # @param [String] filepath 暦期間情報ファイルパス
246
+ #
247
+ # @return [Array<Range>] 暦期間情報
248
+ #
249
+ # @raise [ArgumentError] 引数エラー
250
+ #
251
+ def run(filepath: '')
252
+ yaml = YAML.load_file(filepath)
253
+
254
+ failed = Validator.run(yaml_hash: yaml)
255
+
256
+ raise ArgumentError, failed.join("\n") unless failed.empty?
257
+
258
+ parser = RootParser.new(hash: yaml)
259
+ parser.create
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../type/validation/version_root'
4
+
5
+ require 'yaml'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Japan
11
+ # :nodoc:
12
+ module Version
13
+ #
14
+ # Resource yaml解析結果
15
+ #
16
+ module Resource
17
+ #
18
+ # Validator yaml解析
19
+ #
20
+ module Validator
21
+ class << self
22
+ #
23
+ # 検証する
24
+ #
25
+ # @param [Hash<String, Object>] yaml_hash yaml取得結果
26
+ #
27
+ # @return [Array<String>] 不正メッセージ
28
+ #
29
+ def run(yaml_hash:)
30
+ Type::Validation::VersionRoot.new(hash: yaml_hash).validate
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,80 @@
1
+ ---
2
+ last_date:
3
+ western: '9999-12-31'
4
+ japan: '令和7981年12月31日'
5
+ last_year:
6
+ japan: 7981
7
+ western: 9999
8
+ list:
9
+ - name: 'Genka'
10
+ start_date:
11
+ western: '445-1-24'
12
+ japan: '允恭天皇34年01月01日'
13
+ start_year:
14
+ western: 445
15
+ japan: 34
16
+ released: true
17
+ - name: 'Gihou'
18
+ start_date:
19
+ western: '698-2-16'
20
+ japan: '文武天皇02年01月01日'
21
+ start_year:
22
+ western: 698
23
+ japan: 2
24
+ released: true
25
+ - name: 'Daien'
26
+ start_date:
27
+ western: '764-2-7'
28
+ japan: '天平宝字08年01月01日'
29
+ start_year:
30
+ western: 764
31
+ japan: 8
32
+ released: true
33
+ - name: 'Senmyou'
34
+ start_date:
35
+ western: '862-2-3'
36
+ japan: '貞観02年01月01日'
37
+ start_year:
38
+ western: 862
39
+ japan: 2
40
+ released: true
41
+ - name: 'Joukyou'
42
+ start_date:
43
+ western: '1685-2-4'
44
+ japan: '貞享02年01月01日'
45
+ start_year:
46
+ western: 1685
47
+ japan: 2
48
+ released: false
49
+ - name: 'Houryaku'
50
+ start_date:
51
+ western: '1755-2-11'
52
+ japan: '宝暦05年01月01日'
53
+ start_year:
54
+ western: 1755
55
+ japan: 5
56
+ released: false
57
+ - name: 'Kansei'
58
+ start_date:
59
+ western: '1798-2-16'
60
+ japan: '寛政10年01月01日'
61
+ start_year:
62
+ western: 1798
63
+ japan: 10
64
+ released: false
65
+ - name: 'Tenpou'
66
+ start_date:
67
+ western: '1844-2-18'
68
+ japan: '天保13年01月01日'
69
+ start_year:
70
+ western: 1844
71
+ japan: 13
72
+ released: false
73
+ - name: 'Gregorio'
74
+ start_date:
75
+ western: '1868-10-23'
76
+ japan: '明治01年09月08日'
77
+ start_year:
78
+ western: 1868
79
+ japan: 1
80
+ released: false
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './resource/parser'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Japan
9
+ # :nodoc:
10
+ module Version
11
+ #
12
+ # Resource yaml解析結果
13
+ #
14
+ module Resource
15
+ LIST = Parser.run(filepath: File.expand_path(
16
+ './resource/yaml/version.yaml',
17
+ __dir__
18
+ ))
19
+ end
20
+ end
21
+ end
22
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative '../western/calendar'
4
4
 
5
+ require_relative './version/resource'
6
+
5
7
  # :nodoc:
6
8
  module Zakuro
7
9
  #
@@ -12,119 +14,6 @@ module Zakuro
12
14
  # Version 暦
13
15
  #
14
16
  module Version
15
- #
16
- # Range 暦(範囲)
17
- #
18
- class Range
19
- # @return [String] 暦名
20
- attr_reader :name
21
- # @return [Western::Calendar] 暦の開始日
22
- attr_reader :start_date
23
- # @return [Integer] 開始西暦年
24
- attr_reader :start_year
25
- # @return [Integer] 終了西暦年
26
- attr_reader :last_year
27
- # @return [True] リリース済
28
- # @return [False] 未リリース
29
- attr_reader :released
30
-
31
- #
32
- # 初期化
33
- #
34
- # @param [String] name 暦名
35
- # @param [Western::Calendar] start_date 暦の開始日
36
- # @param [Integer] start_year 開始西暦年
37
- # @param [Integer] last_year 終了西暦年
38
- # @param [True, False] released リリース済 / 未リリース
39
- #
40
- def initialize(name:, start_date:, start_year:, last_year:, released:)
41
- @name = name
42
- @start_date = start_date
43
- @start_year = start_year
44
- @last_year = last_year
45
- @released = released
46
- end
47
- end
48
-
49
- # TODO: yamlにする
50
- # TODO: last_year は不要
51
-
52
- # @return [Array<Range>] 全和暦
53
- LIST = [
54
- # 允恭天皇34年01月01日
55
- Range.new(
56
- name: 'Genka',
57
- start_date: Western::Calendar.new(year: 445, month: 1, day: 24),
58
- start_year: 445,
59
- last_year: 697,
60
- released: true
61
- ),
62
- # 文武天皇02年01月01日
63
- Range.new(
64
- name: 'Gihou',
65
- start_date: Western::Calendar.new(year: 698, month: 2, day: 16),
66
- start_year: 698,
67
- last_year: 763,
68
- released: true
69
- ),
70
- # 天平宝字08年01月01日
71
- Range.new(
72
- name: 'Daien',
73
- start_date: Western::Calendar.new(year: 764, month: 2, day: 7),
74
- start_year: 764,
75
- last_year: 861,
76
- released: true
77
- ),
78
- # 貞観02年01月01日
79
- Range.new(
80
- name: 'Senmyou',
81
- start_date: Western::Calendar.new(year: 862, month: 2, day: 3),
82
- start_year: 862,
83
- last_year: 1684,
84
- released: true
85
- ),
86
- # 貞享02年01月01日
87
- Range.new(
88
- name: 'Joukyou',
89
- start_date: Western::Calendar.new(year: 1685, month: 2, day: 4),
90
- start_year: 1685,
91
- last_year: 1754,
92
- released: false
93
- ),
94
- # 宝暦05年01月01日
95
- Range.new(
96
- name: 'Houryaku',
97
- start_date: Western::Calendar.new(year: 1755, month: 2, day: 11),
98
- start_year: 1755,
99
- last_year: 1797,
100
- released: false
101
- ),
102
- # 寛政10年01月01日
103
- Range.new(
104
- name: 'Kansei',
105
- start_date: Western::Calendar.new(year: 1798, month: 2, day: 16),
106
- start_year: 1798,
107
- last_year: 1843,
108
- released: false
109
- ),
110
- # 天保13年01月01日
111
- Range.new(
112
- name: 'Tenpou',
113
- start_date: Western::Calendar.new(year: 1844, month: 2, day: 18),
114
- start_year: 1844,
115
- last_year: 1867,
116
- released: false
117
- ),
118
- # 明治01年09月08日
119
- Range.new(
120
- name: 'Gregorio',
121
- start_date: Western::Calendar.new(year: 1868, month: 10, day: 23),
122
- start_year: 1868,
123
- last_year: 9999,
124
- released: false
125
- )
126
- ].freeze
127
-
128
17
  class << self
129
18
  #
130
19
  # 年を基準に暦を引き当てる
@@ -137,10 +26,10 @@ module Zakuro
137
26
  def ranges_with_year(start_year:, last_year:)
138
27
  result = []
139
28
 
140
- LIST.each do |range|
29
+ Resource::LIST.each do |range|
141
30
  next if start_year > range.last_year
142
31
 
143
- next if last_year < range.start_year
32
+ next if last_year < range.start_year.western
144
33
 
145
34
  result.push(range)
146
35
  end
@@ -148,7 +148,7 @@ module Zakuro
148
148
  def validate
149
149
  failed = valid_type
150
150
 
151
- return failed unless failed.size.zero?
151
+ return failed unless failed.empty?
152
152
 
153
153
  valid_date
154
154
  end
@@ -207,7 +207,7 @@ module Zakuro
207
207
  @param = Parameter.new(year: year, month: month, day: day, start: start)
208
208
 
209
209
  failed = validate
210
- raise ArgumentError, failed.join('\n') unless failed.size.zero?
210
+ raise ArgumentError, failed.join('\n') unless failed.empty?
211
211
 
212
212
  @date = Date.new(year, month, day, start)
213
213
  end
@@ -36,7 +36,7 @@ module Zakuro
36
36
  def text
37
37
  list = []
38
38
  causes.each do |cause|
39
- list.push(Tools::Stringifier.to_h(obj: cause, class_prefix: 'Zakuro'))
39
+ list.push(Tool::Stringifier.to_h(obj: cause, class_prefix: 'Zakuro'))
40
40
  end
41
41
 
42
42
  JSON.generate(list)
@@ -4,7 +4,7 @@ require_relative './gateway/single'
4
4
 
5
5
  require_relative './gateway/range'
6
6
 
7
- require_relative './condition'
7
+ require_relative './parameter/condition'
8
8
 
9
9
  require_relative './exception/exception'
10
10
 
@@ -19,7 +19,7 @@ module Zakuro
19
19
  class Merchant
20
20
  # @return [Output::Logger] ロガー
21
21
  LOGGER = Output::Logger.new(location: Merchant)
22
- # @return [Hash<Symbol, Object>] 条件
22
+ # @return [Parameter::Condition] 条件
23
23
  attr_reader :condition
24
24
 
25
25
  #
@@ -30,10 +30,10 @@ module Zakuro
30
30
  # @raise [Exception::ZakuroError] ライブラリ内エラー
31
31
  #
32
32
  def initialize(condition: {})
33
- failed = Condition.validate(hash: condition)
33
+ failed = Parameter::Condition.validate(hash: condition)
34
34
  raise Exception.get(presets: failed) unless failed.empty?
35
35
 
36
- @condition = Condition.new(hash: condition)
36
+ @condition = Parameter::Condition.new(hash: condition)
37
37
  rescue Exception::ZakuroError => e
38
38
  raise e
39
39
  rescue StandardError => e
@@ -50,7 +50,7 @@ module Zakuro
50
50
  # @raise [Exception::ZakuroError] ライブラリ内エラー
51
51
  #
52
52
  def offer(condition: {})
53
- failed = Condition.validate(hash: condition)
53
+ failed = Parameter::Condition.validate(hash: condition)
54
54
  raise Exception.get(presets: failed) unless failed.empty?
55
55
 
56
56
  condition.rewrite(hash: condition)
@@ -102,7 +102,7 @@ module Zakuro
102
102
 
103
103
  str.to_i
104
104
  end
105
- end
105
+ end
106
106
  end
107
107
 
108
108
  #
@@ -266,7 +266,7 @@ module Zakuro
266
266
 
267
267
  relations[id] = relation_id
268
268
  end
269
- end
269
+ end
270
270
 
271
271
  #
272
272
  # 注釈を特定する