zakuro 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -13
  3. data/VERSION +1 -1
  4. data/doc/dropped_date.md +93 -0
  5. data/doc/error.md +45 -0
  6. data/doc/operation/csv/month.csv +100 -79
  7. data/doc/operation/operation.xlsx +0 -0
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +5 -5
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  11. data/lib/zakuro/calculation/base/operated_year.rb +26 -24
  12. data/lib/zakuro/calculation/base/year.rb +7 -7
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
  14. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  15. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  16. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
  17. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  18. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  19. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
  27. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  28. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  29. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  30. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  31. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  32. data/lib/zakuro/calculation/monthly/month.rb +17 -17
  33. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  34. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  35. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  36. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  37. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  38. data/lib/zakuro/calculation/range/abstract_full_range.rb +40 -25
  39. data/lib/zakuro/calculation/range/abstract_operation_range.rb +111 -109
  40. data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
  41. data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
  42. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  43. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  44. data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
  45. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  46. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  47. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  48. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  49. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  50. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  51. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  52. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  53. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  54. data/lib/zakuro/calculation/summary/internal/month.rb +32 -11
  55. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  56. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  57. data/lib/zakuro/calculation/summary/japan/range.rb +145 -118
  58. data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
  59. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +57 -50
  60. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  61. data/lib/zakuro/calculation/summary/western/range.rb +95 -92
  62. data/lib/zakuro/calculation/summary/western/single.rb +78 -76
  63. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -119
  64. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +63 -56
  65. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  66. data/lib/zakuro/calculation/type/optional.rb +46 -0
  67. data/lib/zakuro/condition.rb +142 -92
  68. data/lib/zakuro/context/context.rb +44 -0
  69. data/lib/zakuro/context/option.rb +119 -0
  70. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  71. data/lib/zakuro/era/japan/calendar.rb +35 -33
  72. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +8 -4
  73. data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
  74. data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
  75. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
  76. data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
  77. data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -34
  78. data/lib/zakuro/era/japan/gengou/resource/type.rb +45 -37
  79. data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
  80. data/lib/zakuro/era/japan/gengou.rb +28 -26
  81. data/lib/zakuro/era/japan/version.rb +18 -16
  82. data/lib/zakuro/era/western/calendar.rb +104 -88
  83. data/lib/zakuro/exception/case/pattern.rb +39 -3
  84. data/lib/zakuro/exception/case/preset.rb +2 -2
  85. data/lib/zakuro/exception/exception.rb +17 -15
  86. data/lib/zakuro/exception/zakuro_error.rb +19 -1
  87. data/lib/zakuro/gateway/locale/date.rb +2 -2
  88. data/lib/zakuro/gateway/locale/range.rb +3 -3
  89. data/lib/zakuro/gateway/range.rb +3 -3
  90. data/lib/zakuro/gateway/single.rb +14 -3
  91. data/lib/zakuro/merchant.rb +79 -9
  92. data/lib/zakuro/operation/month/parser.rb +252 -249
  93. data/lib/zakuro/operation/month/type.rb +17 -8
  94. data/lib/zakuro/operation/month/validator.rb +148 -144
  95. data/lib/zakuro/operation/operation.rb +38 -36
  96. data/lib/zakuro/operation/yaml/month.yaml +955 -281
  97. data/lib/zakuro/output/response.rb +107 -141
  98. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  99. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  100. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  101. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  102. data/lib/zakuro/result/data/single_day.rb +9 -1
  103. data/lib/zakuro/result/operation/month/annotation.rb +2 -2
  104. data/lib/zakuro/result/operation/month/history.rb +2 -2
  105. data/lib/zakuro/result/operation/month.rb +31 -0
  106. data/lib/zakuro/result/operation.rb +39 -0
  107. data/lib/zakuro/result/result.rb +3 -3
  108. data/lib/zakuro/tools/stringifier.rb +67 -42
  109. data/lib/zakuro/tools/typeconv.rb +17 -15
  110. data/lib/zakuro/tools/typeof.rb +15 -13
  111. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  112. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  113. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  114. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  115. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  116. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  117. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  118. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  119. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  120. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  121. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  122. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  123. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  124. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  125. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  126. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  127. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  128. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  129. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  130. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  131. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  132. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  133. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  134. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  135. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  136. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  137. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  138. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  139. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  140. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  141. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  142. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  143. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  144. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  145. data/lib/zakuro/version/senmyou/const/remainder.rb +7 -1
  146. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  147. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  148. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  149. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  150. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  151. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  152. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  153. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  154. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  155. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  156. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  157. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  158. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  159. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  160. metadata +27 -7
  161. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
  162. data/lib/zakuro/result/operation/month/bundle.rb +0 -36
  163. data/lib/zakuro/result/operation/operation.rb +0 -44
  164. data/lib/zakuro/version/context.rb +0 -44
  165. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './exception/exception'
4
+
3
5
  require 'date'
4
6
 
5
7
  # :nodoc:
@@ -24,21 +26,28 @@ module Zakuro
24
26
  @date = date
25
27
  end
26
28
 
27
- #
28
- # 検証する
29
- #
30
- # @param [Date] date 日付
31
- #
32
- # @return [Array<String>] エラーメッセージ
33
- #
34
- def self.validate(date:)
35
- failed = []
36
- return failed unless date
37
-
38
- return failed if date.is_a?(Date) || date.is_a?(String)
39
-
40
- failed.push("invalid date: #{date}")
41
- failed
29
+ class << self
30
+ #
31
+ # 検証する
32
+ #
33
+ # @param [Date] date 日付
34
+ #
35
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
36
+ #
37
+ def validate(date:)
38
+ failed = []
39
+ return failed unless date
40
+
41
+ return failed if date.is_a?(Date) || date.is_a?(String)
42
+
43
+ failed.push(
44
+ Exception::Case::Preset.new(
45
+ date.class,
46
+ template: Exception::Case::Pattern::INVALID_DATE_TYPE
47
+ )
48
+ )
49
+ failed
50
+ end
42
51
  end
43
52
  end
44
53
 
@@ -54,7 +63,7 @@ module Zakuro
54
63
  #
55
64
  # 初期化
56
65
  #
57
- # @param [Hash<Symbol>] hash パラメータ
66
+ # @param [Hash<Symbol, Object>] hash パラメータ
58
67
  # @option hash [Symbol] :start 開始日
59
68
  # @option hash [Symbol] :start 終了日
60
69
  #
@@ -65,26 +74,33 @@ module Zakuro
65
74
 
66
75
  # :reek:TooManyStatements { max_statements: 7 }
67
76
 
68
- #
69
- # 検証する
70
- #
71
- # @param [Hash<Symbol>] hash パラメータ
72
- #
73
- # @return [Array<String>] エラーメッセージ
74
- #
75
- def self.validate(hash:)
76
- failed = []
77
- return failed unless hash
78
-
79
- unless hash.is_a?(Hash)
80
- failed.push("invalid range type. #{hash}. should be hash")
81
- return failed
77
+ class << self
78
+ #
79
+ # 検証する
80
+ #
81
+ # @param [Hash<Symbol, Object>] hash パラメータ
82
+ #
83
+ # @return [Array<Exception::Case::Preset>] エラープリセット
84
+ #
85
+ def validate(hash:)
86
+ failed = []
87
+ return failed unless hash
88
+
89
+ unless hash.is_a?(Hash)
90
+ failed.push(
91
+ Exception::Case::Preset.new(
92
+ hash.class,
93
+ template: Exception::Case::Pattern::INVALID_RANGE_TYPE
94
+ )
95
+ )
96
+ return failed
97
+ end
98
+
99
+ failed.concat(BasisDate.validate(date: hash[:start]))
100
+ failed.concat(BasisDate.validate(date: hash[:last]))
101
+
102
+ failed
82
103
  end
83
-
84
- failed.concat(BasisDate.validate(date: hash[:start]))
85
- failed.concat(BasisDate.validate(date: hash[:last]))
86
-
87
- failed
88
104
  end
89
105
 
90
106
  #
@@ -119,24 +135,31 @@ module Zakuro
119
135
  @columns = columns
120
136
  end
121
137
 
122
- #
123
- # 検証する
124
- #
125
- # @param [Array<String>] columns 列
126
- #
127
- # @return [Array<String>] エラーメッセージ
128
- #
129
- def self.validate(columns:)
130
- # TODO: 列内容のバリデーション
131
- failed = []
132
-
133
- return failed unless columns
134
-
135
- return failed if columns.is_a?(Array)
136
-
137
- failed.push("invalid columns type. #{columns}. should be array")
138
-
139
- failed
138
+ class << self
139
+ #
140
+ # 検証する
141
+ #
142
+ # @param [Array<String>] columns 列
143
+ #
144
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
145
+ #
146
+ def validate(columns:)
147
+ # TODO: 列内容のバリデーション
148
+ failed = []
149
+
150
+ return failed unless columns
151
+
152
+ return failed if columns.is_a?(Array)
153
+
154
+ failed.push(
155
+ Exception::Case::Preset.new(
156
+ hash.class,
157
+ template: Exception::Case::Pattern::INVALID_COLUMN_TYPE
158
+ )
159
+ )
160
+
161
+ failed
162
+ end
140
163
  end
141
164
  end
142
165
 
@@ -144,8 +167,8 @@ module Zakuro
144
167
  # Options オプション
145
168
  # 取得内容を変更する
146
169
  #
147
- # * unit: 年/月/日
148
- # * lost_days: 没日あり
170
+ # * version:
171
+ # * dropped_days: 没日あり
149
172
  # * seasons: 四季あり
150
173
  #
151
174
  class Options
@@ -155,7 +178,7 @@ module Zakuro
155
178
  #
156
179
  # 初期化
157
180
  #
158
- # @param [Array<String>] options オプション
181
+ # @param [Hash<Symbol, Object>] options オプション
159
182
  #
160
183
  def initialize(options: [])
161
184
  @options = options
@@ -163,22 +186,28 @@ module Zakuro
163
186
 
164
187
  # TODO: オプションキーのバリデーション
165
188
 
166
- #
167
- # 検証する
168
- #
169
- # @param [Array<String>] options オプション
170
- #
171
- # @return [Array<String>] エラーメッセージ
172
- #
173
- def self.validate(options:)
174
- failed = []
175
- return failed unless options
176
-
177
- return failed if options.is_a?(Hash)
178
-
179
- failed.push("invalid options type. #{options}. should be hash")
180
-
181
- failed
189
+ class << self
190
+ #
191
+ # 検証する
192
+ #
193
+ # @param [Hash<Symbol, Object>] options オプション
194
+ #
195
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
196
+ #
197
+ def validate(options:)
198
+ failed = []
199
+ return failed unless options
200
+
201
+ return failed if options.is_a?(Hash)
202
+
203
+ failed.push(
204
+ Exception::Case::Preset.new(
205
+ hash.class,
206
+ template: Exception::Case::Pattern::INVALID_OPTION_TYPE
207
+ )
208
+ )
209
+ failed
210
+ end
182
211
  end
183
212
  end
184
213
  end
@@ -193,7 +222,7 @@ module Zakuro
193
222
  attr_reader :range
194
223
  # @return [Array<String>] 列
195
224
  attr_reader :columns
196
- # @return [Array<String>] オプション
225
+ # @return [Hash<String, Object>] オプション
197
226
  attr_reader :options
198
227
 
199
228
  #
@@ -203,38 +232,59 @@ module Zakuro
203
232
  # @option hash [Date] :date 基準日
204
233
  # @option hash [Hash<Symbol, Date>] :range 範囲
205
234
  # @option hash [Array<String>] :columns 列
206
- # @option hash [Array<String>] :options オプション
235
+ # @option hash [Hash<String, Object>] :options オプション
207
236
  #
208
237
  def initialize(hash: {})
209
238
  @date = hash[:date]
210
239
  @range = hash[:range]
211
240
  @columns = hash[:columns]
212
- @options = hash[:options]
241
+ @options = hash[:options] || {}
213
242
  end
214
243
 
215
244
  # :reek:TooManyStatements { max_statements: 8 }
216
245
 
217
- #
218
- # 検証する
219
- #
220
- # @param [Hash<Symbol, Object>] hash パラメータ
221
- #
222
- # @return [Array<String>] エラーメッセージ
223
- #
224
- def self.validate(hash:)
225
- failed = []
246
+ class << self
247
+ #
248
+ # 検証する
249
+ #
250
+ # @param [Hash<Symbol, Object>] hash パラメータ
251
+ #
252
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
253
+ #
254
+ def validate(hash:)
255
+ failed = []
256
+
257
+ unless hash.is_a?(Hash)
258
+ failed.push(
259
+ Exception::Case::Preset.new(
260
+ hash.class,
261
+ template: Exception::Case::Pattern::INVALID_CONDITION_TYPE
262
+ )
263
+ )
264
+ return failed
265
+ end
266
+
267
+ failed.concat(validate_hash(hash: hash))
226
268
 
227
- unless hash.is_a?(Hash)
228
- failed.push("invalid condition type. #{hash}. should be hash")
229
- return failed
269
+ failed
230
270
  end
231
271
 
232
- failed.concat(Catalog::BasisDate.validate(date: hash[:date]))
233
- failed.concat(Catalog::Range.validate(hash: hash[:range]))
234
- failed.concat(Catalog::Columns.validate(columns: hash[:columns]))
235
- failed.concat(Catalog::Options.validate(options: hash[:options]))
272
+ #
273
+ # ハッシュ内を検証する
274
+ #
275
+ # @param [Hash<Symbol, Object>] hash パラメータ
276
+ #
277
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
278
+ #
279
+ def validate_hash(hash:)
280
+ failed = []
281
+ failed.concat(Catalog::BasisDate.validate(date: hash[:date]))
282
+ failed.concat(Catalog::Range.validate(hash: hash[:range]))
283
+ failed.concat(Catalog::Columns.validate(columns: hash[:columns]))
284
+ failed.concat(Catalog::Options.validate(options: hash[:options]))
236
285
 
237
- failed
286
+ failed
287
+ end
238
288
  end
239
289
 
240
290
  #
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './option'
4
+
5
+ require_relative './version_class_resolver'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Context
11
+ #
12
+ # Context 暦コンテキスト
13
+ #
14
+ class Context
15
+ # @return [Option] オプション
16
+ attr_reader :option
17
+ # @return [VersionClassResolver] 暦リゾルバー
18
+ attr_reader :resolver
19
+
20
+ #
21
+ # 初期化
22
+ #
23
+ # @param [Hash<String, Object>] options オプション値
24
+ #
25
+ # @raise [ArgumentError] 引数エラー
26
+ #
27
+ def initialize(version: Option::INVALID_VERSION_NAME, options: {})
28
+ @option = Option.new(default_version: version, hash: options)
29
+
30
+ @resolver = VersionClassResolver.new(version_name: option.version)
31
+ end
32
+
33
+ #
34
+ # 不正か
35
+ #
36
+ # @return [True] 不正
37
+ # @return [False] 不正なし
38
+ #
39
+ def invalid?
40
+ !option.version?
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Context
7
+ #
8
+ # Option オプション値
9
+ #
10
+ class Option
11
+ # @return [String] 無効暦名
12
+ INVALID_VERSION_NAME = ''
13
+ # @return [Array<String>] 暦名
14
+ VERSION_NAMES = %w[Genka Gihou Daien Senmyou Joukyou Kansei Tenpou Gregorio].freeze
15
+
16
+ # @return [String] 没日オプションキー名
17
+ DROPPED_DATE_KEY = 'dropped_date'
18
+
19
+ # @return [Hash<String, Object>] オプション値
20
+ attr_reader :hash
21
+ # @return [String] デフォルト暦名
22
+ attr_reader :default_version
23
+
24
+ #
25
+ # 初期化
26
+ #
27
+ # @param [String] default_version デフォルト暦名
28
+ #
29
+ # @param [Hash<String, Object>] options オプション値
30
+ #
31
+ def initialize(default_version: INVALID_VERSION_NAME, hash: {})
32
+ @default_version = default_version
33
+ @hash = hash
34
+ end
35
+
36
+ #
37
+ # 暦名を返す
38
+ #
39
+ # @return [String] 暦名
40
+ #
41
+ def version
42
+ version = self.class.version(version: @default_version)
43
+
44
+ return version if self.class.version?(version: version)
45
+
46
+ version = hash['version']
47
+
48
+ self.class.version(version: version)
49
+ end
50
+
51
+ #
52
+ # 有効なデフォルト暦名か
53
+ #
54
+ # @return [True] 有効
55
+ # @return [False] 無効
56
+ #
57
+ def default_version?
58
+ self.class.version?(version: @default_version)
59
+ end
60
+
61
+ #
62
+ # 有効な暦名か
63
+ #
64
+ # @return [True] 有効
65
+ # @return [False] 無効
66
+ #
67
+ def version?
68
+ self.class.version?(version: version)
69
+ end
70
+
71
+ #
72
+ # 没日か
73
+ #
74
+ # @return [True] 没日あり
75
+ # @return [False] 没日なし
76
+ #
77
+ def dropped_date?
78
+ value = @hash[DROPPED_DATE_KEY]
79
+
80
+ return true if value.is_a?(TrueClass)
81
+
82
+ false
83
+ end
84
+
85
+ class << self
86
+ #
87
+ # 暦名を返す
88
+ #
89
+ # @param [String] version 暦名
90
+ #
91
+ # @return [String] 暦名
92
+ #
93
+ def version(version: INVALID_VERSION_NAME)
94
+ return INVALID_VERSION_NAME unless version
95
+
96
+ return INVALID_VERSION_NAME if version.empty?
97
+
98
+ return INVALID_VERSION_NAME unless VERSION_NAMES.include?(version)
99
+
100
+ version
101
+ end
102
+
103
+ #
104
+ # 有効な暦か
105
+ #
106
+ # @param [String] version 暦名
107
+ #
108
+ # @return [True] 有効
109
+ # @return [False] 無効
110
+ #
111
+ def version?(version: INVALID_VERSION_NAME)
112
+ return false if version == INVALID_VERSION_NAME
113
+
114
+ true
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../version/genka/cycle/remainder'
4
+ require_relative '../version/genka/cycle/solar_term'
5
+ require_relative '../version/genka/range/annual_range'
6
+ require_relative '../version/genka/option/dropped_date/parameter'
7
+
8
+ require_relative '../version/gihou/cycle/remainder'
9
+ require_relative '../version/gihou/cycle/solar_term'
10
+ require_relative '../version/gihou/range/annual_range'
11
+ require_relative '../version/gihou/option/dropped_date/parameter'
12
+
13
+ require_relative '../version/daien/cycle/remainder'
14
+ require_relative '../version/daien/cycle/solar_term'
15
+ require_relative '../version/daien/range/annual_range'
16
+ require_relative '../version/daien/option/dropped_date/parameter'
17
+
18
+ require_relative '../version/senmyou/cycle/remainder'
19
+ require_relative '../version/senmyou/cycle/solar_term'
20
+ require_relative '../version/senmyou/range/annual_range'
21
+ require_relative '../version/senmyou/option/dropped_date/parameter'
22
+
23
+ # :nodoc:
24
+ module Zakuro
25
+ # :nodoc:
26
+ module Context
27
+ #
28
+ # VersionClassResolver 暦リゾルバー
29
+ #
30
+ class VersionClassResolver
31
+ # @return [String] 暦名
32
+ attr_reader :version_name
33
+
34
+ # @return [Hash<String, String>] 関連
35
+ CLASSES = {
36
+ 'remainder' => 'Zakuro::$VERSION::Cycle::Remainder',
37
+ 'solar_term' => 'Zakuro::$VERSION::Cycle::SolarTerm',
38
+ 'annual_range' => 'Zakuro::$VERSION::Range::AnnualRange',
39
+ 'dropped_date_parameter' => 'Zakuro::$VERSION::Option::DroppedDate::Parameter'
40
+ }.freeze
41
+
42
+ #
43
+ # 初期化
44
+ #
45
+ # @param [String] version_name 暦名
46
+ #
47
+ def initialize(version_name:)
48
+ @version_name = version_name
49
+ end
50
+
51
+ #
52
+ # 大余小余(暦別)クラスを返す
53
+ #
54
+ # @return [Class] 大余小余(暦別)クラス
55
+ #
56
+ def remainder
57
+ self.class.get_class(version_name: @version_name, class_name: 'remainder')
58
+ end
59
+
60
+ #
61
+ # 二十四節気クラスを返す
62
+ #
63
+ # @return [Class] 二十四節気クラス
64
+ #
65
+ def solar_term
66
+ self.class.get_class(version_name: @version_name, class_name: 'solar_term')
67
+ end
68
+
69
+ #
70
+ # 年間範囲クラスを返す
71
+ #
72
+ # @return [Class] 年間範囲クラス
73
+ #
74
+ def annual_range
75
+ self.class.get_class(version_name: @version_name, class_name: 'annual_range')
76
+ end
77
+
78
+ #
79
+ # 没日引数を返す
80
+ #
81
+ # @return [Class] 没日引数クラス
82
+ #
83
+ def dropped_date_parameter
84
+ self.class.get_class(
85
+ version_name: @version_name, class_name: 'dropped_date_parameter'
86
+ )
87
+ end
88
+
89
+ class << self
90
+ #
91
+ # 該当の暦のクラスを取得する
92
+ #
93
+ # @param [String] version_name 暦名
94
+ # @param [String] class_name クラス名
95
+ #
96
+ # @return [Object] 該当クラス
97
+ #
98
+ # @raise [ArgumentError] 引数エラー
99
+ #
100
+ def get_class(version_name:, class_name:)
101
+ constant = CLASSES.fetch(class_name, '')
102
+
103
+ raise ArgumentError.new, 'invalid class name' if constant == ''
104
+
105
+ resolved_constant = constant.gsub('$VERSION', version_name)
106
+
107
+ Object.const_get(resolved_constant)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -88,45 +88,47 @@ module Zakuro
88
88
  @month == month
89
89
  end
90
90
 
91
- #
92
- # 年月日情報(和暦)を生成する
93
- #
94
- # @param [Regexp] regex 正規表現
95
- # @param [String] text 和暦日文字列
96
- #
97
- # @return [Calendar] 年月日情報(和暦)
98
- #
99
- def self.parse(regex: FORMAT, text: '')
100
- return Calendar.new unless valid_date_string(regex: regex, text: text)
91
+ class << self
92
+ #
93
+ # 年月日情報(和暦)を生成する
94
+ #
95
+ # @param [Regexp] regex 正規表現
96
+ # @param [String] text 和暦日文字列
97
+ #
98
+ # @return [Calendar] 年月日情報(和暦)
99
+ #
100
+ def parse(regex: FORMAT, text: '')
101
+ return Calendar.new unless valid_date_string(regex: regex, text: text)
101
102
 
102
- matched = text.match(regex)
103
+ matched = text.match(regex)
103
104
 
104
- Calendar.new(
105
- gengou: matched[1],
106
- year: Tools::Typeconv.to_i(text: matched[2], default: INVALID),
107
- leaped: matched[3] ? true : false,
108
- month: Tools::Typeconv.to_i(text: matched[4], default: INVALID),
109
- day: Tools::Typeconv.to_i(text: matched[5], default: INVALID)
110
- )
111
- end
105
+ Calendar.new(
106
+ gengou: matched[1],
107
+ year: Tools::Typeconv.to_i(text: matched[2], default: INVALID),
108
+ leaped: matched[3] ? true : false,
109
+ month: Tools::Typeconv.to_i(text: matched[4], default: INVALID),
110
+ day: Tools::Typeconv.to_i(text: matched[5], default: INVALID)
111
+ )
112
+ end
112
113
 
113
- #
114
- # 日付文字列を検証する
115
- #
116
- # @param [Regexp] regex 正規表現
117
- # @param [String] text 和暦日文字列
118
- #
119
- # @return [True] 正しい
120
- # @return [True] 正しくない
121
- #
122
- def self.valid_date_string(regex: FORMAT, text: '')
123
- return false unless text
114
+ #
115
+ # 日付文字列を検証する
116
+ #
117
+ # @param [Regexp] regex 正規表現
118
+ # @param [String] text 和暦日文字列
119
+ #
120
+ # @return [True] 正しい
121
+ # @return [True] 正しくない
122
+ #
123
+ def valid_date_string(regex: FORMAT, text: '')
124
+ return false unless text
124
125
 
125
- matched = text.match(regex)
126
+ matched = text.match(regex)
126
127
 
127
- return false unless matched
128
+ return false unless matched
128
129
 
129
- matched.size == 6
130
+ matched.size == 6
131
+ end
130
132
  end
131
133
  end
132
134
  end