zakuro 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/VERSION +1 -1
  4. data/doc/dropped_date.md +25 -0
  5. data/doc/operation/csv/month.csv +4 -5
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/doc/vanished_date.md +26 -0
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +26 -0
  9. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +7 -1
  10. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +8 -2
  11. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +5 -5
  12. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +18 -5
  13. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +24 -9
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +7 -2
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +7 -2
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +13 -3
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +15 -4
  18. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +8 -2
  19. data/lib/zakuro/calculation/monthly/initialized_month.rb +4 -2
  20. data/lib/zakuro/calculation/monthly/meta/all_solar_term.rb +64 -0
  21. data/lib/zakuro/calculation/monthly/meta/meta_collector.rb +80 -0
  22. data/lib/zakuro/calculation/monthly/meta.rb +60 -0
  23. data/lib/zakuro/calculation/monthly/month.rb +119 -5
  24. data/lib/zakuro/calculation/monthly/operated_month.rb +7 -19
  25. data/lib/zakuro/calculation/option/dropped_date/location.rb +20 -24
  26. data/lib/zakuro/calculation/option/vanished_date/location.rb +9 -2
  27. data/lib/zakuro/calculation/range/abstract_full_range.rb +19 -2
  28. data/lib/zakuro/calculation/range/abstract_operation_range.rb +20 -2
  29. data/lib/zakuro/calculation/range/dated_full_range.rb +8 -3
  30. data/lib/zakuro/calculation/range/dated_operation_range.rb +4 -1
  31. data/lib/zakuro/calculation/range/medieval_annual_range.rb +1 -1
  32. data/lib/zakuro/calculation/range/named_full_range.rb +3 -1
  33. data/lib/zakuro/calculation/range/named_operation_range.rb +3 -1
  34. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +2 -1
  35. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +10 -8
  36. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +8 -34
  37. data/lib/zakuro/calculation/summary/internal/option.rb +24 -5
  38. data/lib/zakuro/calculation/summary/western/range.rb +8 -1
  39. data/lib/zakuro/calculation/summary/western/single.rb +12 -5
  40. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +1 -1
  41. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +1 -1
  42. data/lib/zakuro/era/japan/gengou/alignment.rb +41 -2
  43. data/lib/zakuro/era/japan/gengou/resource/parser.rb +83 -25
  44. data/lib/zakuro/era/japan/gengou/resource/type.rb +81 -26
  45. data/lib/zakuro/era/japan/gengou/resource/validator.rb +100 -21
  46. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1123 -375
  47. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +487 -163
  48. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +30 -10
  49. data/lib/zakuro/era/japan/gengou/resource.rb +16 -0
  50. data/lib/zakuro/era/japan/gengou.rb +11 -6
  51. data/lib/zakuro/operation/yaml/month.yaml +4 -36
  52. data/lib/zakuro/output/logger.rb +21 -3
  53. data/lib/zakuro/tools/gengou_range_comparer.rb +82 -0
  54. data/lib/zakuro/tools/remainder_comparer.rb +100 -0
  55. metadata +11 -6
@@ -21,9 +21,9 @@ module Zakuro
21
21
  # @return [String] 元号名
22
22
  attr_reader :name
23
23
  # @return [Both::Year] 開始年(和暦/西暦)
24
- attr_reader :both_start_year
25
- # @return [Both::Date] 開始日(和暦/西暦)
26
- attr_reader :both_start_date
24
+ attr_reader :start_year
25
+ # @return [SwitchDate] 開始日(和暦/西暦)
26
+ attr_reader :start_date
27
27
  # @return [Integer] 終了年
28
28
  attr_reader :last_year
29
29
  # @return [Western::Calendar] 終了日
@@ -33,18 +33,18 @@ module Zakuro
33
33
  # 初期化
34
34
  #
35
35
  # @param [String] name 元号名
36
- # @param [Both::Year] both_start_year 開始年(和暦/西暦)
37
- # @param [Both::Date] both_start_date 開始日(和暦/西暦)
36
+ # @param [Both::Year] start_year 開始年(和暦/西暦)
37
+ # @param [SwitchDate] start_date 開始日(和暦/西暦)
38
38
  # @param [Integer] last_date 終了年
39
39
  # @param [Western::Calendar] last_date 終了日
40
40
  #
41
- def initialize(name: '', both_start_year: Both::Year.new,
42
- both_start_date: Both::Date.new,
41
+ def initialize(name: '', start_year: Both::Year.new,
42
+ start_date: SwitchDate.new,
43
43
  last_date: Western::Calendar.new,
44
44
  last_year: Both::Year::INVALID)
45
45
  @name = name
46
- @both_start_year = both_start_year
47
- @both_start_date = both_start_date
46
+ @start_year = start_year
47
+ @start_date = start_date
48
48
  @last_year = last_year
49
49
  @last_date = last_date
50
50
  end
@@ -86,7 +86,7 @@ module Zakuro
86
86
  # @param [Integer] next_start_year 次回開始年
87
87
  #
88
88
  def convert_next_start_year_to_last_year(next_start_year:)
89
- if both_start_year.western >= next_start_year
89
+ if start_year.western >= next_start_year
90
90
  @last_year = next_start_year
91
91
  return
92
92
  end
@@ -99,15 +99,14 @@ module Zakuro
99
99
  #
100
100
  # 次の元号の開始日から、元号の終了日に変換する
101
101
  #
102
- # @param [String] next_start_date 次回開始日
102
+ # @param [Western::Calendar] next_start_date 次回開始日
103
103
  #
104
104
  # @raise [ArgumentError] 引数エラー
105
105
  #
106
- def convert_next_start_date_to_last_date(next_start_date: '')
107
- raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
106
+ def convert_next_start_date_to_last_date(next_start_date: Western::Calendar.new)
107
+ raise ArgumentError, 'invalid value. cannot convert' if next_start_date.invalid?
108
108
 
109
- start_date = Western::Calendar.parse(text: next_start_date)
110
- @last_date = start_date - 1
109
+ @last_date = next_start_date.clone - 1
111
110
 
112
111
  nil
113
112
  end
@@ -121,7 +120,7 @@ module Zakuro
121
120
  # @return [False] 含まれない
122
121
  #
123
122
  def include?(date:)
124
- date >= both_start_date.western && date <= last_date
123
+ date >= start_date.western && date <= last_date
125
124
  end
126
125
 
127
126
  #
@@ -131,8 +130,8 @@ module Zakuro
131
130
  # @return [False] 不正なし
132
131
  #
133
132
  def invalid?
134
- both_start_year.japan == -1 || both_start_year.invalid? ||
135
- both_start_date.invalid? || last_date.invalid?
133
+ start_year.japan == -1 || start_year.invalid? ||
134
+ start_date.invalid? || last_date.invalid?
136
135
  end
137
136
 
138
137
  #
@@ -144,8 +143,8 @@ module Zakuro
144
143
  # end
145
144
 
146
145
  def to_s
147
- "name: #{@name}, both_start_year: #{both_start_year.format}, " \
148
- "both_start_date: #{both_start_date.format}, last_date: #{last_date.format}"
146
+ "name: #{@name}, start_year: #{start_year.format}, " \
147
+ "start_date: #{start_date.format}, last_date: #{last_date.format}"
149
148
  end
150
149
 
151
150
  class << self
@@ -190,9 +189,9 @@ module Zakuro
190
189
  # @return [String] 元号セット名
191
190
  attr_reader :name
192
191
  # @return [Both::Date] 元号セットでの終了年
193
- attr_reader :both_last_year
192
+ attr_reader :last_year
194
193
  # @return [Both::Date] 元号セットでの終了日
195
- attr_reader :both_last_date
194
+ attr_reader :last_date
196
195
  # @return [Array<Gengou>] 元号リスト
197
196
  attr_reader :list
198
197
 
@@ -204,12 +203,12 @@ module Zakuro
204
203
  # @param [Western::Calendar] last_date 元号セットでの終了日
205
204
  # @param [Array<Gengou>] list 元号リスト
206
205
  #
207
- def initialize(id: INVALID, name: '', both_last_year: Both::Year.new,
208
- both_last_date: Both::Date.new, list: [])
206
+ def initialize(id: INVALID, name: '', last_year: Both::Year.new,
207
+ last_date: Both::Date.new, list: [])
209
208
  @id = id
210
209
  @name = name
211
- @both_last_year = both_last_year
212
- @both_last_date = both_last_date
210
+ @last_year = last_year
211
+ @last_date = last_date
213
212
  @list = list
214
213
  end
215
214
 
@@ -239,6 +238,62 @@ module Zakuro
239
238
  end
240
239
  end
241
240
 
241
+ #
242
+ # SwitchDate 切替日(運用/計算)
243
+ #
244
+ class SwitchDate
245
+ # @return [Both::Date] 計算値
246
+ attr_reader :calculation
247
+ # @return [Both::Date] 運用値
248
+ attr_reader :operation
249
+ # @return [True, False] 運用値
250
+ attr_reader :operated
251
+ # @return [Japan::Calendar] 和暦日
252
+ attr_reader :japan
253
+ # @return [Western::Calendar] 西暦日
254
+ attr_reader :western
255
+
256
+ #
257
+ # 初期化
258
+ #
259
+ # @param [Both::Date] calculation 計算値
260
+ # @param [Both::Date] operation 運用値
261
+ # @param [True, False] operated 運用値設定
262
+ #
263
+ def initialize(calculation: Both::Date.new, operation: Both::Date.new, operated: false)
264
+ @calculation = calculation
265
+ @operation = operation
266
+ @operated = operated
267
+
268
+ select
269
+ end
270
+
271
+ #
272
+ # 不正か
273
+ #
274
+ # @return [True] 不正
275
+ # @return [False] 不正なし
276
+ #
277
+ def invalid?
278
+ japan.invalid? || western.invalid?
279
+ end
280
+
281
+ private
282
+
283
+ def select
284
+ @japan = operation.japan
285
+ @western = operation.western
286
+
287
+ return if operated
288
+
289
+ calc_japan = calculation.japan
290
+ calc_western = calculation.western
291
+
292
+ @japan = calc_japan unless calc_japan.invalid?
293
+ @western = calc_western unless calc_western.invalid?
294
+ end
295
+ end
296
+
242
297
  #
243
298
  # 和暦/西暦
244
299
  #
@@ -28,9 +28,9 @@ module Zakuro
28
28
  # @return [String] 元号セット名
29
29
  attr_reader :name
30
30
  # @return [Hash<String, String>] 終了年
31
- attr_reader :both_last_year
31
+ attr_reader :last_year
32
32
  # @return [Hash<String, String>] 終了日
33
- attr_reader :both_last_date
33
+ attr_reader :last_date
34
34
  # @return [Array<Hash<String, String>>] 元号情報
35
35
  attr_reader :list
36
36
 
@@ -42,8 +42,8 @@ module Zakuro
42
42
  def initialize(hash:)
43
43
  @id = hash['id']
44
44
  @name = hash['name']
45
- @both_last_year = hash['last_year']
46
- @both_last_date = hash['last_date']
45
+ @last_year = hash['last_year']
46
+ @last_date = hash['last_date']
47
47
  @list = hash['list']
48
48
  end
49
49
 
@@ -58,9 +58,9 @@ module Zakuro
58
58
 
59
59
  failed.push("invalid name. #{name}") unless name?
60
60
 
61
- failed |= validate_both_last_year
61
+ failed |= validate_last_year
62
62
 
63
- failed |= validate_both_last_date
63
+ failed |= validate_last_date
64
64
 
65
65
  failed |= validate_list
66
66
  failed
@@ -95,8 +95,8 @@ module Zakuro
95
95
  #
96
96
  # @return [Array<String>] 不正メッセージ
97
97
  #
98
- def validate_both_last_year
99
- Both::Year.new(hash: both_last_year).validate
98
+ def validate_last_year
99
+ Both::Year.new(hash: last_year).validate
100
100
  end
101
101
 
102
102
  #
@@ -104,8 +104,8 @@ module Zakuro
104
104
  #
105
105
  # @return [Array<String>] 不正メッセージ
106
106
  #
107
- def validate_both_last_date
108
- Both::Date.new(hash: both_last_date).validate
107
+ def validate_last_date
108
+ SwitchDate.new(hash: last_date).validate
109
109
  end
110
110
 
111
111
  #
@@ -145,9 +145,9 @@ module Zakuro
145
145
  # @return [String] 元号名
146
146
  attr_reader :name
147
147
  # @return [Hash<String, String>] 開始年
148
- attr_reader :both_start_year
148
+ attr_reader :start_year
149
149
  # @return [Hash<String, String>] 開始日
150
- attr_reader :both_start_date
150
+ attr_reader :start_date
151
151
 
152
152
  #
153
153
  # 初期化
@@ -158,8 +158,8 @@ module Zakuro
158
158
  def initialize(hash:, index:)
159
159
  @index = index
160
160
  @name = hash['name']
161
- @both_start_year = hash['start_year']
162
- @both_start_date = hash['start_date']
161
+ @start_year = hash['start_year']
162
+ @start_date = hash['start_date']
163
163
  end
164
164
 
165
165
  #
@@ -173,9 +173,9 @@ module Zakuro
173
173
 
174
174
  failed.push(prefix + "invalid name. #{name}") unless name?
175
175
 
176
- failed |= validate_both_start_year
176
+ failed |= validate_start_year
177
177
 
178
- failed |= validate_both_start_date
178
+ failed |= validate_start_date
179
179
 
180
180
  failed
181
181
  end
@@ -197,8 +197,8 @@ module Zakuro
197
197
  #
198
198
  # @return [Array<String>] 不正メッセージ
199
199
  #
200
- def validate_both_start_year
201
- Both::Year.new(hash: both_start_year).validate
200
+ def validate_start_year
201
+ Both::Year.new(hash: start_year).validate
202
202
  end
203
203
 
204
204
  #
@@ -206,8 +206,63 @@ module Zakuro
206
206
  #
207
207
  # @return [Array<String>] 不正メッセージ
208
208
  #
209
- def validate_both_start_date
210
- Both::Date.new(hash: both_start_date).validate
209
+ def validate_start_date
210
+ SwitchDate.new(hash: start_date).validate
211
+ end
212
+ end
213
+
214
+ #
215
+ # SwitchDate 切替日(運用/計算)
216
+ #
217
+ class SwitchDate
218
+ # @return [Hash<String, Strin>] 計算値
219
+ attr_reader :calculation
220
+ # @return [Hash<String, Strin>] 運用値
221
+ attr_reader :operation
222
+
223
+ #
224
+ # 初期化
225
+ #
226
+ # @param [Hash<String, Strin>] hash 切替日(運用/計算)
227
+ #
228
+ def initialize(hash:)
229
+ @calculation = hash['calculation']
230
+ @operation = hash['operation']
231
+ end
232
+
233
+ #
234
+ # 検証する
235
+ #
236
+ # @return [Array<String>] 不正メッセージ
237
+ #
238
+ def validate
239
+ failed = []
240
+
241
+ failed |= validate_calculation_date
242
+
243
+ failed |= validate_operation_date
244
+
245
+ failed
246
+ end
247
+
248
+ private
249
+
250
+ #
251
+ # 日(計算値)を検証する
252
+ #
253
+ # @return [Array<String>] 不正メッセージ
254
+ #
255
+ def validate_calculation_date
256
+ Both::Date.new(hash: calculation, optional: true).validate
257
+ end
258
+
259
+ #
260
+ # 日(運用値)を検証する
261
+ #
262
+ # @return [Array<String>] 不正メッセージ
263
+ #
264
+ def validate_operation_date
265
+ Both::Date.new(hash: operation).validate
211
266
  end
212
267
  end
213
268
 
@@ -282,15 +337,19 @@ module Zakuro
282
337
  attr_reader :japan
283
338
  # @return [String] 西暦日
284
339
  attr_reader :western
340
+ # @return [True] 省略可
341
+ # @return [False] 省略不可
342
+ attr_reader :optional
285
343
 
286
344
  #
287
345
  # 初期化
288
346
  #
289
347
  # @param [Hash<String, Strin>] hash 日情報
290
348
  #
291
- def initialize(hash:)
349
+ def initialize(hash:, optional: false)
292
350
  @japan = hash['japan']
293
351
  @western = hash['western']
352
+ @optional = optional
294
353
  end
295
354
 
296
355
  #
@@ -315,6 +374,8 @@ module Zakuro
315
374
  # @return [False] 正しくない
316
375
  #
317
376
  def japan?
377
+ return true if optional?(text: japan)
378
+
318
379
  Japan::Calendar.valid_date_text(text: japan)
319
380
  end
320
381
 
@@ -325,8 +386,26 @@ module Zakuro
325
386
  # @return [False] 正しくない
326
387
  #
327
388
  def western?
389
+ return true if optional?(text: western)
390
+
328
391
  Western::Calendar.valid_date_text(text: western)
329
392
  end
393
+
394
+ #
395
+ # 省略可で省略されているか
396
+ #
397
+ # @param [String] text 文字列
398
+ #
399
+ # @return [True] 省略あり
400
+ # @return [False] 省略なし
401
+ #
402
+ def optional?(text: '')
403
+ return false unless optional
404
+
405
+ return true if text == ''
406
+
407
+ false
408
+ end
330
409
  end
331
410
  end
332
411