zakuro 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -18
- data/VERSION +1 -1
- data/doc/condition.md +3 -1
- data/doc/dropped_date.md +25 -0
- data/doc/expection.md +11 -0
- data/doc/operation/csv/month.csv +5 -5
- data/doc/operation/operation.xlsx +0 -0
- data/doc/vanished_date.md +26 -0
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +26 -0
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +1 -1
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +2 -2
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +6 -2
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +5 -5
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +12 -5
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +14 -8
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -2
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +4 -2
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +5 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +10 -5
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +5 -2
- data/lib/zakuro/calculation/monthly/initialized_month.rb +4 -2
- data/lib/zakuro/calculation/monthly/meta/all_solar_term.rb +64 -0
- data/lib/zakuro/calculation/monthly/meta/meta_collector.rb +80 -0
- data/lib/zakuro/calculation/monthly/meta.rb +60 -0
- data/lib/zakuro/calculation/monthly/month.rb +60 -5
- data/lib/zakuro/calculation/monthly/operated_month.rb +6 -3
- data/lib/zakuro/calculation/option/dropped_date/location.rb +12 -23
- data/lib/zakuro/calculation/option/vanished_date/location.rb +9 -2
- data/lib/zakuro/calculation/range/abstract_full_range.rb +19 -2
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +20 -2
- data/lib/zakuro/calculation/range/dated_full_range.rb +3 -1
- data/lib/zakuro/calculation/range/dated_operation_range.rb +3 -1
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +1 -1
- data/lib/zakuro/calculation/range/named_full_range.rb +3 -1
- data/lib/zakuro/calculation/range/named_operation_range.rb +3 -1
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +2 -1
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +10 -8
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +8 -34
- data/lib/zakuro/calculation/summary/internal/option.rb +51 -25
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +1 -1
- data/lib/zakuro/era/japan/calendar.rb +2 -2
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +1 -1
- data/lib/zakuro/era/japan/gengou/alignment.rb +14 -2
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +83 -25
- data/lib/zakuro/era/japan/gengou/resource/type.rb +81 -26
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +102 -23
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1123 -375
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +487 -163
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +30 -10
- data/lib/zakuro/era/japan/gengou/resource.rb +16 -0
- data/lib/zakuro/era/japan/gengou.rb +7 -4
- data/lib/zakuro/era/western/calendar.rb +5 -11
- data/lib/zakuro/era/western/date_text.rb +40 -0
- data/lib/zakuro/gateway/locale/date.rb +2 -2
- data/lib/zakuro/operation/month/validator.rb +7 -1
- data/lib/zakuro/operation/yaml/month.yaml +15 -15
- data/lib/zakuro/output/logger.rb +21 -3
- data/lib/zakuro/tools/remainder_comparer.rb +97 -0
- metadata +7 -2
@@ -21,9 +21,9 @@ module Zakuro
|
|
21
21
|
# @return [String] 元号名
|
22
22
|
attr_reader :name
|
23
23
|
# @return [Both::Year] 開始年(和暦/西暦)
|
24
|
-
attr_reader :
|
25
|
-
# @return [
|
26
|
-
attr_reader :
|
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]
|
37
|
-
# @param [
|
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: '',
|
42
|
-
|
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
|
-
@
|
47
|
-
@
|
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
|
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 [
|
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, '
|
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
|
-
|
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 >=
|
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
|
-
|
135
|
-
|
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},
|
148
|
-
"
|
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 :
|
192
|
+
attr_reader :last_year
|
194
193
|
# @return [Both::Date] 元号セットでの終了日
|
195
|
-
attr_reader :
|
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: '',
|
208
|
-
|
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
|
-
@
|
212
|
-
@
|
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 :
|
31
|
+
attr_reader :last_year
|
32
32
|
# @return [Hash<String, String>] 終了日
|
33
|
-
attr_reader :
|
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
|
-
@
|
46
|
-
@
|
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 |=
|
61
|
+
failed |= validate_last_year
|
62
62
|
|
63
|
-
failed |=
|
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
|
99
|
-
Both::Year.new(hash:
|
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
|
108
|
-
|
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 :
|
148
|
+
attr_reader :start_year
|
149
149
|
# @return [Hash<String, String>] 開始日
|
150
|
-
attr_reader :
|
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
|
-
@
|
162
|
-
@
|
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 |=
|
176
|
+
failed |= validate_start_year
|
177
177
|
|
178
|
-
failed |=
|
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
|
201
|
-
Both::Year.new(hash:
|
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
|
210
|
-
|
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,7 +374,9 @@ module Zakuro
|
|
315
374
|
# @return [False] 正しくない
|
316
375
|
#
|
317
376
|
def japan?
|
318
|
-
|
377
|
+
return true if optional?(text: japan)
|
378
|
+
|
379
|
+
Japan::Calendar.valid_date_text(text: japan)
|
319
380
|
end
|
320
381
|
|
321
382
|
#
|
@@ -325,7 +386,25 @@ module Zakuro
|
|
325
386
|
# @return [False] 正しくない
|
326
387
|
#
|
327
388
|
def western?
|
328
|
-
|
389
|
+
return true if optional?(text: western)
|
390
|
+
|
391
|
+
Western::Calendar.valid_date_text(text: western)
|
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
|
329
408
|
end
|
330
409
|
end
|
331
410
|
end
|