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
@@ -58,26 +58,28 @@ module Zakuro
58
58
  Type::DEFAULT => Date::ITALY
59
59
  }.freeze
60
60
 
61
- #
62
- # 日付種別からRuby標準のグレゴリオ暦開始日を引き当てる
63
- #
64
- # @param [Symbol] type 日付種別
65
- #
66
- # @return [Integer] Ruby標準のグレゴリオ暦開始日
67
- #
68
- def self.to_native_start(type:)
69
- DATE_START.fetch(type, DATE_START[Type::DEFAULT])
70
- end
61
+ class << self
62
+ #
63
+ # 日付種別からRuby標準のグレゴリオ暦開始日を引き当てる
64
+ #
65
+ # @param [Symbol] type 日付種別
66
+ #
67
+ # @return [Integer] Ruby標準のグレゴリオ暦開始日
68
+ #
69
+ def to_native_start(type:)
70
+ DATE_START.fetch(type, DATE_START[Type::DEFAULT])
71
+ end
71
72
 
72
- #
73
- # Ruby標準のグレゴリオ暦開始日から日付種別を引き当てる
74
- #
75
- # @param [Integer] start Ruby標準のグレゴリオ暦開始日
76
- #
77
- # @return [Symbol] 日付種別
78
- #
79
- def self.to_type(start:)
80
- DATE_START.invert.fetch(start, Type::DEFAULT)
73
+ #
74
+ # Ruby標準のグレゴリオ暦開始日から日付種別を引き当てる
75
+ #
76
+ # @param [Integer] start Ruby標準のグレゴリオ暦開始日
77
+ #
78
+ # @return [Symbol] 日付種別
79
+ #
80
+ def to_type(start:)
81
+ DATE_START.invert.fetch(start, Type::DEFAULT)
82
+ end
81
83
  end
82
84
 
83
85
  #
@@ -131,8 +133,16 @@ module Zakuro
131
133
  # 定数 DATE_START のバリエーションで日付オブジェクトを初期化するだけで良い
132
134
  #
133
135
  class Calendar # rubocop:disable Metrics/ClassLength
134
- attr_reader :param, :date
136
+ # @return [Parameter] 初期化引数
137
+ attr_reader :param
138
+ # @return [Date] 日付(Ruby日付型)
139
+ attr_reader :date
135
140
 
141
+ #
142
+ # 検証する
143
+ #
144
+ # @return [Array<String>] エラー文字列
145
+ #
136
146
  def validate
137
147
  failed = valid_type
138
148
 
@@ -150,9 +160,9 @@ module Zakuro
150
160
  #
151
161
  def valid_type
152
162
  failed = []
153
- year = @param.year
154
- month = @param.month
155
- day = @param.day
163
+ year = param.year
164
+ month = param.month
165
+ day = param.day
156
166
  failed.push("wrong type. year: #{year}") unless year.is_a?(Integer)
157
167
  failed.push("wrong type. month: #{month}") unless month.is_a?(Integer)
158
168
  failed.push("wrong type. day: #{day}") unless day.is_a?(Integer)
@@ -169,10 +179,10 @@ module Zakuro
169
179
  def valid_date
170
180
  failed = []
171
181
 
172
- year = @param.year
173
- month = @param.month
174
- day = @param.day
175
- start = @param.start
182
+ year = param.year
183
+ month = param.month
184
+ day = param.day
185
+ start = param.start
176
186
  unless Date.valid_date?(year, month, day, start)
177
187
  failed.push("year: #{year}, month: #{month}, " \
178
188
  "day: #{day}, start: #{start}")
@@ -188,6 +198,8 @@ module Zakuro
188
198
  # @param [Integer] day 日
189
199
  # @param [Symbol] type 日付種別
190
200
  #
201
+ # @raise [ArgumentError] 引数エラー
202
+ #
191
203
  def initialize(year: -4712, month: 1, day: 1, type: Type::DEFAULT)
192
204
  start = Western.to_native_start(type: type)
193
205
  @param = Parameter.new(year: year, month: month, day: day, start: start)
@@ -213,7 +225,7 @@ module Zakuro
213
225
  #
214
226
  def redate(type: Type::DEFAULT)
215
227
  start = DATE_START.fetch(type, DATE_START[Type::DEFAULT])
216
- @date = @date.new_start(start)
228
+ @date = date.new_start(start)
217
229
  self
218
230
  end
219
231
 
@@ -225,7 +237,7 @@ module Zakuro
225
237
  # @return [Calendar] 年月日情報(西暦)
226
238
  #
227
239
  def +(other)
228
- return @date.jd + other.date.jd if other.is_a?(Western::Calendar)
240
+ return date.jd + other.date.jd if other.is_a?(Western::Calendar)
229
241
 
230
242
  @date += other
231
243
  self
@@ -239,7 +251,7 @@ module Zakuro
239
251
  # @return [Calendar] 年月日情報(西暦)
240
252
  #
241
253
  def -(other)
242
- return @date.jd - other.date.jd if other.is_a?(Western::Calendar)
254
+ return date.jd - other.date.jd if other.is_a?(Western::Calendar)
243
255
 
244
256
  @date -= other
245
257
  self
@@ -254,7 +266,7 @@ module Zakuro
254
266
  # @return [False] 以下(現在日/過去日である)
255
267
  #
256
268
  def >(other)
257
- @date > other.date
269
+ date > other.date
258
270
  end
259
271
 
260
272
  #
@@ -266,7 +278,7 @@ module Zakuro
266
278
  # @return [False] より小さい(過去日である)
267
279
  #
268
280
  def >=(other)
269
- @date >= other.date
281
+ date >= other.date
270
282
  end
271
283
 
272
284
  #
@@ -278,7 +290,7 @@ module Zakuro
278
290
  # @return [False] 以上(現在日/未来日である)
279
291
  #
280
292
  def <(other)
281
- @date < other.date
293
+ date < other.date
282
294
  end
283
295
 
284
296
  #
@@ -290,7 +302,7 @@ module Zakuro
290
302
  # @return [False] より大きい(未来日である)
291
303
  #
292
304
  def <=(other)
293
- @date <= other.date
305
+ date <= other.date
294
306
  end
295
307
 
296
308
  #
@@ -302,7 +314,7 @@ module Zakuro
302
314
  # @return [False] 等しくない(過去日/未来日である)
303
315
  #
304
316
  def ==(other)
305
- @date == other.date
317
+ date == other.date
306
318
  end
307
319
 
308
320
  #
@@ -311,7 +323,7 @@ module Zakuro
311
323
  # @return [Integer] 年
312
324
  #
313
325
  def year
314
- @date.year
326
+ date.year
315
327
  end
316
328
 
317
329
  #
@@ -320,7 +332,7 @@ module Zakuro
320
332
  # @return [Integer] 月
321
333
  #
322
334
  def month
323
- @date.month
335
+ date.month
324
336
  end
325
337
 
326
338
  #
@@ -329,7 +341,7 @@ module Zakuro
329
341
  # @return [Integer] 日
330
342
  #
331
343
  def day
332
- @date.day
344
+ date.day
333
345
  end
334
346
 
335
347
  #
@@ -340,7 +352,7 @@ module Zakuro
340
352
  # @return [Calendar] 年月日情報(西暦)
341
353
  #
342
354
  def next_year(num: 1)
343
- @date = @date.next_year(num)
355
+ @date = date.next_year(num)
344
356
  self
345
357
  end
346
358
 
@@ -351,7 +363,7 @@ module Zakuro
351
363
  # @return [False] 無効値以外
352
364
  #
353
365
  def invalid?
354
- (@date == Date.new)
366
+ (date == Date.new)
355
367
  end
356
368
 
357
369
  #
@@ -362,60 +374,64 @@ module Zakuro
362
374
  # @return [String] 年月日情報
363
375
  #
364
376
  def format(form: '%Y-%m-%d')
365
- @date.strftime(form)
366
- end
367
-
368
- #
369
- # 年月日情報(西暦)を生成する
370
- #
371
- # @param [Date] date Ruby標準日付
372
- #
373
- # @return [Calendar] 年月日情報(西暦)
374
- #
375
- def self.create(date: Date.new)
376
- type = Western.to_type(start: date.start)
377
- Calendar.new(year: date.year, month: date.month,
378
- day: date.day, type: type)
377
+ date.strftime(form)
379
378
  end
380
379
 
381
- #
382
- # 年月日情報(西暦)を生成する
383
- #
384
- # @param [String] text 日付文字列
385
- # @param [Symbol] type 日付種別
386
- #
387
- # @return [Calendar] 年月日情報(西暦)
388
- #
389
- def self.parse(text: '', type: Type::DEFAULT)
390
- unless Calendar.valid_date_string(text: text, type: type)
391
- raise ArgumentError, "invalid date string: #{text}"
380
+ class << self
381
+ #
382
+ # 年月日情報(西暦)を生成する
383
+ #
384
+ # @param [Date] date Ruby標準日付
385
+ #
386
+ # @return [Calendar] 年月日情報(西暦)
387
+ #
388
+ def create(date: Date.new)
389
+ type = Western.to_type(start: date.start)
390
+ Calendar.new(year: date.year, month: date.month,
391
+ day: date.day, type: type)
392
392
  end
393
393
 
394
- start = DATE_START.fetch(type, DATE_START[Type::DEFAULT])
395
- date = Date.parse(text, start)
396
-
397
- Calendar.new(
398
- year: date.year, month: date.month, day: date.day, type: type
399
- )
400
- end
394
+ #
395
+ # 年月日情報(西暦)を生成する
396
+ #
397
+ # @param [String] text 日付文字列
398
+ # @param [Symbol] type 日付種別
399
+ #
400
+ # @return [Calendar] 年月日情報(西暦)
401
+ #
402
+ # @raise [ArgumentError] 引数エラー
403
+ #
404
+ def parse(text: '', type: Type::DEFAULT)
405
+ unless valid_date_string(text: text, type: type)
406
+ raise ArgumentError, "invalid date string: #{text}"
407
+ end
408
+
409
+ start = DATE_START.fetch(type, DATE_START[Type::DEFAULT])
410
+ date = Date.parse(text, start)
411
+
412
+ Calendar.new(
413
+ year: date.year, month: date.month, day: date.day, type: type
414
+ )
415
+ end
401
416
 
402
- #
403
- # 日付文字列を検証する
404
- #
405
- # @param [String] text 日付文字列
406
- # @param [Symbol] type 日付種別
407
- #
408
- # @return [True] 正しい
409
- # @return [True] 正しくない
410
- #
411
- def self.valid_date_string(text: '', type: Type::DEFAULT)
412
- start = DATE_START.fetch(type, DATE_START[Type::DEFAULT])
413
- begin
414
- Date.parse(text, start)
415
- rescue ArgumentError => _e
416
- return false
417
+ #
418
+ # 日付文字列を検証する
419
+ #
420
+ # @param [String] text 日付文字列
421
+ # @param [Symbol] type 日付種別
422
+ #
423
+ # @return [True] 正しい
424
+ # @return [True] 正しくない
425
+ #
426
+ def valid_date_string(text: '', type: Type::DEFAULT)
427
+ start = DATE_START.fetch(type, DATE_START[Type::DEFAULT])
428
+ begin
429
+ Date.parse(text, start)
430
+ rescue ArgumentError => _e
431
+ return false
432
+ end
433
+ true
417
434
  end
418
- true
419
435
  end
420
436
  end
421
437
  end
@@ -14,21 +14,57 @@ module Zakuro
14
14
  module Pattern
15
15
  INTERNAL_ERROR = Template.new(
16
16
  code: 'ERROR_0001',
17
- message: '致命的なエラーです。',
17
+ message: '内部エラーです。',
18
18
  length: 0
19
19
  )
20
20
 
21
+ INVALID_DATE_TYPE = Template.new(
22
+ code: 'ERROR_0101',
23
+ message: '日付の型は文字列/日付です。指定型:%s',
24
+ length: 1
25
+ )
26
+
27
+ INVALID_RANGE_TYPE = Template.new(
28
+ code: 'ERROR_0102',
29
+ message: '範囲の型はhashです。指定型:%s',
30
+ length: 1
31
+ )
32
+
33
+ INVALID_OPTION_TYPE = Template.new(
34
+ code: 'ERROR_0103',
35
+ message: 'オプションの型はhashです。指定型:%s',
36
+ length: 1
37
+ )
38
+
39
+ INVALID_COLUMN_TYPE = Template.new(
40
+ code: 'ERROR_0104',
41
+ message: '列の型は配列です。指定型:%s',
42
+ length: 1
43
+ )
44
+
45
+ INVALID_CONDITION_TYPE = Template.new(
46
+ code: 'ERROR_0105',
47
+ message: '条件の型は配列です。指定型:%s',
48
+ length: 1
49
+ )
50
+
21
51
  INVALID_DATE = Template.new(
22
- code: 'ERROR_0002',
52
+ code: 'ERROR_0201',
23
53
  message: '一日検索の日付指定が誤っています。',
24
54
  length: 0
25
55
  )
26
56
 
27
57
  INVALID_RANGE = Template.new(
28
- code: 'ERROR_0003',
58
+ code: 'ERROR_0202',
29
59
  message: '範囲検索の日付指定が誤っています。',
30
60
  length: 0
31
61
  )
62
+
63
+ UNCOMMITTABLE_DATE = Template.new(
64
+ code: 'ERROR_0203',
65
+ message: '検索不可能な日付指定です。',
66
+ length: 0
67
+ )
32
68
  end
33
69
  end
34
70
  end
@@ -34,7 +34,7 @@ module Zakuro
34
34
  # @return [String] エラーコード
35
35
  #
36
36
  def code
37
- @template.code
37
+ template.code
38
38
  end
39
39
 
40
40
  #
@@ -43,7 +43,7 @@ module Zakuro
43
43
  # @return [String] メッセージ
44
44
  #
45
45
  def message
46
- @template.format(*args)
46
+ template.format(*args)
47
47
  end
48
48
  end
49
49
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  require_relative '../output/logger'
4
4
 
5
- require_relative './cause'
6
-
5
+ require_relative './case/preset'
7
6
  require_relative './case/pattern'
8
7
 
9
8
  require_relative './zakuro_error'
9
+ require_relative './cause'
10
10
 
11
11
  # :nodoc:
12
12
  module Zakuro
@@ -18,20 +18,22 @@ module Zakuro
18
18
  # @return [String] 共通メッセージ
19
19
  MESSAGE = 'an error has occurred'
20
20
 
21
- #
22
- # 例外を取得する
23
- #
24
- # @param [Array<Template>] presets 原因プリセット
25
- #
26
- # @return [ZakuroError] ライブラリエラー
27
- #
28
- def self.get(presets: [])
29
- causes = []
30
- presets.each do |preset|
31
- causes.push(Cause.new(code: preset.code, message: preset.message))
21
+ class << self
22
+ #
23
+ # 例外を取得する
24
+ #
25
+ # @param [Array<Case::Preset>] presets 原因プリセット
26
+ #
27
+ # @return [ZakuroError] ライブラリエラー
28
+ #
29
+ def get(presets: [])
30
+ causes = []
31
+ presets.each do |preset|
32
+ causes.push(Cause.new(code: preset.code, message: preset.message))
33
+ end
34
+
35
+ ZakuroError.new(msg: MESSAGE, causes: causes)
32
36
  end
33
-
34
- ZakuroError.new(msg: MESSAGE, causes: causes)
35
37
  end
36
38
  end
37
39
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require_relative './cause'
4
5
 
5
6
  # :nodoc:
@@ -20,8 +21,25 @@ module Zakuro
20
21
  # @param [Array<Cause>] causes 原因
21
22
  #
22
23
  def initialize(msg: '', causes: [])
23
- super(msg)
24
24
  @causes = causes
25
+ out = "#{msg}:#{text}"
26
+ super(out)
27
+ end
28
+
29
+ private
30
+
31
+ #
32
+ # 原因をJSON文字列にする
33
+ #
34
+ # @return [String] JSON文字列
35
+ #
36
+ def text
37
+ list = []
38
+ causes.each do |cause|
39
+ list.push(Tools::Stringifier.to_h(obj: cause, class_prefix: 'Zakuro'))
40
+ end
41
+
42
+ JSON.generate(list)
25
43
  end
26
44
  end
27
45
  end
@@ -51,7 +51,7 @@ module Zakuro
51
51
  # @return [False] 不正なし
52
52
  #
53
53
  def invalid_japan?
54
- @japan_date.invalid?
54
+ japan_date.invalid?
55
55
  end
56
56
 
57
57
  #
@@ -71,7 +71,7 @@ module Zakuro
71
71
  # @return [False] 不正なし
72
72
  #
73
73
  def invalid_western?
74
- @western_date.invalid?
74
+ western_date.invalid?
75
75
  end
76
76
 
77
77
  #
@@ -39,7 +39,7 @@ module Zakuro
39
39
  # @return [False] 無効
40
40
  #
41
41
  def valid_western?
42
- @start_date.valid_western? && @last_date.valid_western?
42
+ start_date.valid_western? && last_date.valid_western?
43
43
  end
44
44
 
45
45
  #
@@ -49,7 +49,7 @@ module Zakuro
49
49
  # @return [False] 無効
50
50
  #
51
51
  def valid_japan?
52
- @start_date.valid_japan? && @last_date.valid_japan?
52
+ start_date.valid_japan? && last_date.valid_japan?
53
53
  end
54
54
 
55
55
  #
@@ -59,7 +59,7 @@ module Zakuro
59
59
  # @return [False] 不正なし
60
60
  #
61
61
  def invalid?
62
- @start_date.invalid? && @last_date.invalid?
62
+ start_date.invalid? && last_date.invalid?
63
63
  end
64
64
  end
65
65
  end
@@ -15,7 +15,7 @@ module Zakuro
15
15
  # Range 範囲
16
16
  #
17
17
  class Range
18
- # @return [Context] 暦コンテキスト
18
+ # @return [Context::Context] 暦コンテキスト
19
19
  attr_reader :context
20
20
  # @return [Locale::Range] 範囲
21
21
  attr_reader :range
@@ -23,7 +23,7 @@ module Zakuro
23
23
  #
24
24
  # 初期化
25
25
  #
26
- # @param [Context] context 暦コンテキスト
26
+ # @param [Context::Context] context 暦コンテキスト
27
27
  # @param [Hash<Symbol, Object>] range 範囲
28
28
  #
29
29
  def initialize(context:, range:)
@@ -38,7 +38,7 @@ module Zakuro
38
38
  # @return [False] 不正なし
39
39
  #
40
40
  def invalid?
41
- @range.invalid?
41
+ range.invalid?
42
42
  end
43
43
 
44
44
  #
@@ -21,7 +21,7 @@ module Zakuro
21
21
  #
22
22
  # 初期化
23
23
  #
24
- # @param [Context] context 暦コンテキスト
24
+ # @param [Context::Context] context 暦コンテキスト
25
25
  # @param [Date, String] date 日付
26
26
  #
27
27
  def initialize(context:, date:)
@@ -36,7 +36,7 @@ module Zakuro
36
36
  # @return [False] 不正なし
37
37
  #
38
38
  def invalid?
39
- @date.invalid?
39
+ date.invalid?
40
40
  end
41
41
 
42
42
  #
@@ -57,7 +57,18 @@ module Zakuro
57
57
  )
58
58
  end
59
59
 
60
- raise Exception.get(
60
+ raise invalid_date_error
61
+ end
62
+
63
+ private
64
+
65
+ #
66
+ # 日付不正エラーを取得する
67
+ #
68
+ # @return [ZakuroError] ライブラリエラー
69
+ #
70
+ def invalid_date_error
71
+ Exception.get(
61
72
  presets: [
62
73
  Exception::Case::Preset.new(
63
74
  template: Exception::Case::Pattern::INVALID_DATE