zakuro 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/doc/dropped_date.md +25 -0
- data/doc/operation/csv/month.csv +1 -1
- 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/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 +9 -3
- 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 +9 -4
- 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 +5 -19
- 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 +24 -5
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +1 -1
- 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 +100 -21
- 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/operation/yaml/month.yaml +1 -1
- data/lib/zakuro/output/logger.rb +21 -3
- data/lib/zakuro/tools/remainder_comparer.rb +97 -0
- metadata +6 -2
@@ -23,6 +23,9 @@ module Zakuro
|
|
23
23
|
# @return [Aligner] 整列結果
|
24
24
|
SUMMARY = Aligner.new(resources: Resource::LIST)
|
25
25
|
|
26
|
+
# @return [Aligner] 整列結果(運用値)
|
27
|
+
OPERATED_SUMMARY = Aligner.new(resources: Resource::OPERATED_LIST)
|
28
|
+
|
26
29
|
class << self
|
27
30
|
#
|
28
31
|
# 指定した範囲内の元号を取得する
|
@@ -30,11 +33,17 @@ module Zakuro
|
|
30
33
|
# @param [Integer] line 行
|
31
34
|
# @param [Western::Calendar] start_date 開始日
|
32
35
|
# @param [Western::Calendar] last_date 終了日
|
36
|
+
# @param [True, False] operated 運用値設定
|
33
37
|
#
|
34
38
|
# @return [Array<LinearGengou>] 元号
|
35
39
|
#
|
36
40
|
def get(line: FIRST_LINE,
|
37
|
-
start_date: Western::Calendar.new, last_date: Western::Calendar.new
|
41
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
42
|
+
operated: false)
|
43
|
+
|
44
|
+
if operated
|
45
|
+
return OPERATED_SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
|
46
|
+
end
|
38
47
|
|
39
48
|
SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
|
40
49
|
end
|
@@ -44,10 +53,13 @@ module Zakuro
|
|
44
53
|
#
|
45
54
|
# @param [Integer] line 行
|
46
55
|
# @param [String] name 元号名
|
56
|
+
# @param [True, False] operated 運用値設定
|
47
57
|
#
|
48
58
|
# @return [Array<LinearGengou>] 元号
|
49
59
|
#
|
50
|
-
def get_by_name(line: FIRST_LINE, name:)
|
60
|
+
def get_by_name(line: FIRST_LINE, name:, operated: false)
|
61
|
+
return OPERATED_SUMMARY.get_by_name(line: line, name: name) if operated
|
62
|
+
|
51
63
|
SUMMARY.get_by_name(line: line, name: name)
|
52
64
|
end
|
53
65
|
end
|
@@ -30,9 +30,11 @@ module Zakuro
|
|
30
30
|
# @return [String] 元号名
|
31
31
|
attr_reader :name
|
32
32
|
# @return [Hash<String, String>] 開始年
|
33
|
-
attr_reader :
|
33
|
+
attr_reader :start_year
|
34
34
|
# @return [Hash<String, String>] 開始日
|
35
|
-
attr_reader :
|
35
|
+
attr_reader :start_date
|
36
|
+
# @return [True, False] 運用値
|
37
|
+
attr_reader :operated
|
36
38
|
|
37
39
|
#
|
38
40
|
# 初期化
|
@@ -40,11 +42,12 @@ module Zakuro
|
|
40
42
|
# @param [Hash<String, Strin>] hash 元号情報
|
41
43
|
# @param [Integer] index (元号セット内での)元号の要素位置
|
42
44
|
#
|
43
|
-
def initialize(hash:, index:)
|
45
|
+
def initialize(hash:, index:, operated: false)
|
44
46
|
@index = index
|
45
47
|
@name = hash['name']
|
46
|
-
@
|
47
|
-
@
|
48
|
+
@start_year = hash['start_year']
|
49
|
+
@start_date = hash['start_date']
|
50
|
+
@operated = operated
|
48
51
|
end
|
49
52
|
|
50
53
|
#
|
@@ -53,11 +56,11 @@ module Zakuro
|
|
53
56
|
# @return [Gengou] 元号情報
|
54
57
|
#
|
55
58
|
def create
|
56
|
-
|
57
|
-
|
59
|
+
year = Both::YearParser.new(hash: start_year).create
|
60
|
+
date = SwitchDateParser.new(hash: start_date, operated: operated).create
|
58
61
|
|
59
|
-
Gengou.new(name: name,
|
60
|
-
|
62
|
+
Gengou.new(name: name, start_year: year,
|
63
|
+
start_date: date)
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
@@ -70,23 +73,27 @@ module Zakuro
|
|
70
73
|
# @return [String] 元号セット名
|
71
74
|
attr_reader :name
|
72
75
|
# @return [Hash<String, String>] 終了年
|
73
|
-
attr_reader :
|
76
|
+
attr_reader :last_year
|
74
77
|
# @return [Hash<String, String>] 終了日
|
75
|
-
attr_reader :
|
78
|
+
attr_reader :last_date
|
76
79
|
# @return [Array<Hash<String, String>>] 元号情報
|
77
80
|
attr_reader :list
|
81
|
+
# @return [True, False] 運用値
|
82
|
+
attr_reader :operated
|
78
83
|
|
79
84
|
#
|
80
85
|
# 初期化
|
81
86
|
#
|
82
87
|
# @param [Hash<String, Object>] hash 元号セット情報
|
88
|
+
# @param [True, False] operated 運用値設定
|
83
89
|
#
|
84
|
-
def initialize(hash:)
|
90
|
+
def initialize(hash:, operated: false)
|
85
91
|
@id = hash['id']
|
86
92
|
@name = hash['name']
|
87
|
-
@
|
88
|
-
@
|
93
|
+
@last_year = hash['last_year']
|
94
|
+
@last_date = hash['last_date']
|
89
95
|
@list = hash['list']
|
96
|
+
@operated = operated
|
90
97
|
end
|
91
98
|
|
92
99
|
#
|
@@ -95,10 +102,10 @@ module Zakuro
|
|
95
102
|
# @return [Set] 元号セット情報
|
96
103
|
#
|
97
104
|
def create
|
98
|
-
|
105
|
+
date = SwitchDateParser.new(hash: last_date, operated: operated).create
|
99
106
|
list = create_list
|
100
107
|
Set.new(
|
101
|
-
id: id, name: name,
|
108
|
+
id: id, name: name, last_date: date, list: list
|
102
109
|
)
|
103
110
|
end
|
104
111
|
|
@@ -112,7 +119,9 @@ module Zakuro
|
|
112
119
|
def create_list
|
113
120
|
result = []
|
114
121
|
list.each_with_index do |li, index|
|
115
|
-
gengou = GengouParser.new(
|
122
|
+
gengou = GengouParser.new(
|
123
|
+
hash: li, index: index, operated: operated
|
124
|
+
).create
|
116
125
|
next_index = index + 1
|
117
126
|
gengou = calc_last_date_on_gengou_data(next_index: next_index,
|
118
127
|
gengou: gengou)
|
@@ -136,11 +145,15 @@ module Zakuro
|
|
136
145
|
return gengou
|
137
146
|
end
|
138
147
|
next_item = list[next_index]
|
148
|
+
next_start_date = SwitchDateParser.new(
|
149
|
+
hash: next_item['start_date'], operated: operated
|
150
|
+
).create
|
151
|
+
|
139
152
|
gengou.convert_next_start_year_to_last_year(
|
140
153
|
next_start_year: next_item['start_year']['western']
|
141
154
|
)
|
142
155
|
gengou.convert_next_start_date_to_last_date(
|
143
|
-
next_start_date:
|
156
|
+
next_start_date: next_start_date.western
|
144
157
|
)
|
145
158
|
gengou
|
146
159
|
end
|
@@ -153,9 +166,50 @@ module Zakuro
|
|
153
166
|
# @param [GengouParser] gengou 元号
|
154
167
|
#
|
155
168
|
def last_gengou_data(gengou:)
|
156
|
-
gengou.write_last_year(last_year:
|
157
|
-
|
158
|
-
|
169
|
+
gengou.write_last_year(last_year: last_year['western'])
|
170
|
+
|
171
|
+
date = SwitchDateParser.new(hash: last_date, operated: operated).create
|
172
|
+
|
173
|
+
gengou.write_last_date(last_date: date.western)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
#
|
178
|
+
# SwitchDateParser 切替日(運用/計算)
|
179
|
+
#
|
180
|
+
class SwitchDateParser
|
181
|
+
# @return [Hash<String, Strin>] 計算値
|
182
|
+
attr_reader :calculation
|
183
|
+
# @return [Hash<String, Strin>] 運用値
|
184
|
+
attr_reader :operation
|
185
|
+
# @return [True, False] 運用値
|
186
|
+
attr_reader :operated
|
187
|
+
|
188
|
+
#
|
189
|
+
# 初期化
|
190
|
+
#
|
191
|
+
# @param [Hash<String, Strin>] hash 切替日(運用/計算)
|
192
|
+
# @param [True, False] operated 運用値設定
|
193
|
+
#
|
194
|
+
def initialize(hash:, operated: false)
|
195
|
+
@calculation = hash['calculation']
|
196
|
+
@operation = hash['operation']
|
197
|
+
@operated = operated
|
198
|
+
end
|
199
|
+
|
200
|
+
#
|
201
|
+
# 切替日(運用/計算)情報を生成する
|
202
|
+
#
|
203
|
+
# @return [SwitchDate] 切替日(運用/計算)情報
|
204
|
+
#
|
205
|
+
def create
|
206
|
+
calculation_date = Both::DateParser.new(hash: calculation).create
|
207
|
+
operation_date = Both::DateParser.new(hash: operation).create
|
208
|
+
|
209
|
+
Japan::Gengou::Resource::SwitchDate.new(
|
210
|
+
calculation: calculation_date, operation: operation_date,
|
211
|
+
operated: operated
|
212
|
+
)
|
159
213
|
end
|
160
214
|
end
|
161
215
|
|
@@ -222,8 +276,11 @@ module Zakuro
|
|
222
276
|
# @return [Both::Date] 日情報
|
223
277
|
#
|
224
278
|
def create
|
225
|
-
japan_date = Japan::Calendar.
|
226
|
-
western_date = Western::Calendar.
|
279
|
+
japan_date = Japan::Calendar.new
|
280
|
+
western_date = Western::Calendar.new
|
281
|
+
|
282
|
+
japan_date = Japan::Calendar.parse(text: japan) unless japan == ''
|
283
|
+
western_date = Western::Calendar.parse(text: western) unless western == ''
|
227
284
|
|
228
285
|
Japan::Gengou::Resource::Both::Date.new(
|
229
286
|
japan: japan_date, western: western_date
|
@@ -237,19 +294,20 @@ module Zakuro
|
|
237
294
|
# 解析/展開する
|
238
295
|
#
|
239
296
|
# @param [String] filepath 元号セットファイルパス
|
297
|
+
# @param [True, False] operated 運用値設定
|
240
298
|
#
|
241
299
|
# @return [Set] 元号セット情報
|
242
300
|
#
|
243
301
|
# @raise [ArgumentError] 引数エラー
|
244
302
|
#
|
245
|
-
def run(filepath: '')
|
303
|
+
def run(filepath: '', operated: false)
|
246
304
|
yaml = YAML.load_file(filepath)
|
247
305
|
|
248
306
|
failed = Validator.run(yaml_hash: yaml)
|
249
307
|
|
250
308
|
raise ArgumentError, failed.join("\n") unless failed.empty?
|
251
309
|
|
252
|
-
parser = SetParser.new(hash: yaml)
|
310
|
+
parser = SetParser.new(hash: yaml, operated: operated)
|
253
311
|
parser.create
|
254
312
|
end
|
255
313
|
end
|
@@ -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,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
|
|