zakuro 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +3 -0
- data/README.md +6 -4
- data/VERSION +1 -1
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/gengou.rb +46 -0
- data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +6 -8
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +37 -51
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +17 -17
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +2 -3
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/monthly/month.rb +39 -0
- data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
- data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +5 -4
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +9 -11
- data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
- data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
- data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
- data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -2
- data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +1 -1
- data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -0
- data/lib/zakuro/calculation/summary/western/range.rb +124 -0
- data/lib/zakuro/calculation/summary/western/single.rb +113 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +169 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
- data/lib/zakuro/condition.rb +1 -2
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +89 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +125 -122
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +141 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +171 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +38 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +183 -182
- data/lib/zakuro/era/japan/gengou/resource/type.rb +233 -232
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +255 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +5 -20
- data/lib/zakuro/era/western/calendar.rb +9 -9
- data/lib/zakuro/exception/case/pattern.rb +35 -0
- data/lib/zakuro/exception/case/preset.rb +51 -0
- data/lib/zakuro/exception/case/template.rb +48 -0
- data/lib/zakuro/exception/cause.rb +28 -0
- data/lib/zakuro/exception/exception.rb +37 -0
- data/lib/zakuro/exception/zakuro_error.rb +28 -0
- data/lib/zakuro/gateway/locale/date.rb +127 -0
- data/lib/zakuro/gateway/locale/range.rb +67 -0
- data/lib/zakuro/gateway/range.rb +99 -0
- data/lib/zakuro/gateway/single.rb +70 -0
- data/lib/zakuro/merchant.rb +8 -44
- data/lib/zakuro/operation/month/parser.rb +9 -9
- data/lib/zakuro/operation/month/type.rb +31 -31
- data/lib/zakuro/operation/month/validator.rb +49 -49
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/result/data/day.rb +43 -0
- data/lib/zakuro/result/data/gengou.rb +35 -0
- data/lib/zakuro/result/data/month.rb +63 -0
- data/lib/zakuro/result/data/single_day.rb +48 -0
- data/lib/zakuro/result/data/solar_term.rb +35 -0
- data/lib/zakuro/result/data/year.rb +45 -0
- data/lib/zakuro/result/operation/month/annotation.rb +40 -0
- data/lib/zakuro/result/operation/month/bundle.rb +36 -0
- data/lib/zakuro/result/operation/month/history.rb +54 -0
- data/lib/zakuro/result/operation/operation.rb +44 -0
- data/lib/zakuro/result/result.rb +4 -2
- metadata +46 -14
- data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
- data/lib/zakuro/calculation/summary/range.rb +0 -120
- data/lib/zakuro/calculation/summary/single.rb +0 -110
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/result/operation.rb +0 -114
@@ -7,231 +7,44 @@ require 'yaml'
|
|
7
7
|
|
8
8
|
# :nodoc:
|
9
9
|
module Zakuro
|
10
|
-
#
|
11
|
-
# Japan 和暦
|
12
|
-
#
|
10
|
+
# :nodoc:
|
13
11
|
module Japan
|
14
|
-
#
|
15
|
-
|
16
|
-
#
|
17
|
-
module Resource
|
12
|
+
# :nodoc:
|
13
|
+
module Gengou
|
18
14
|
#
|
19
|
-
#
|
15
|
+
# Resource yaml解析結果
|
20
16
|
#
|
21
|
-
module
|
17
|
+
module Resource
|
22
18
|
#
|
23
|
-
#
|
19
|
+
# Validator yaml解析
|
24
20
|
#
|
25
|
-
|
26
|
-
#
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# @param [Hash<String, Object>] hash 元号セット情報
|
41
|
-
#
|
42
|
-
def initialize(hash:)
|
43
|
-
@id = hash['id']
|
44
|
-
@name = hash['name']
|
45
|
-
@both_last_year = hash['last_year']
|
46
|
-
@both_last_date = hash['last_date']
|
47
|
-
@list = hash['list']
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# 検証する
|
52
|
-
#
|
53
|
-
# @return [Array<String>] 不正メッセージ
|
54
|
-
#
|
55
|
-
def validate
|
56
|
-
failed = []
|
57
|
-
failed.push("invalid id. #{@id}") unless id?
|
58
|
-
|
59
|
-
failed.push("invalid name. #{@name}") unless name?
|
60
|
-
|
61
|
-
failed |= validate_both_last_year
|
62
|
-
|
63
|
-
failed |= validate_both_last_date
|
64
|
-
|
65
|
-
failed |= validate_list
|
66
|
-
failed
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# IDを検証する
|
71
|
-
#
|
72
|
-
# @return [True] 正しい
|
73
|
-
# @return [False] 正しくない
|
74
|
-
#
|
75
|
-
def id?
|
76
|
-
return false unless @id
|
77
|
-
|
78
|
-
@id.is_a?(Integer)
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# 元号セット名を検証する
|
83
|
-
#
|
84
|
-
# @return [True] 正しい
|
85
|
-
# @return [False] 正しくない
|
86
|
-
#
|
87
|
-
def name?
|
88
|
-
return false unless @name
|
89
|
-
|
90
|
-
@name.is_a?(String)
|
91
|
-
end
|
92
|
-
|
93
|
-
#
|
94
|
-
# 終了年を検証する
|
95
|
-
#
|
96
|
-
# @return [Array<String>] 不正メッセージ
|
97
|
-
#
|
98
|
-
def validate_both_last_year
|
99
|
-
Both::Year.new(hash: @both_last_year).validate
|
100
|
-
end
|
101
|
-
|
102
|
-
#
|
103
|
-
# 終了日を検証する
|
104
|
-
#
|
105
|
-
# @return [Array<String>] 不正メッセージ
|
106
|
-
#
|
107
|
-
def validate_both_last_date
|
108
|
-
Both::Date.new(hash: @both_last_date).validate
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# 元号情報を検証する
|
113
|
-
#
|
114
|
-
# @return [True] 正しい
|
115
|
-
# @return [False] 正しくない
|
116
|
-
#
|
117
|
-
def list?
|
118
|
-
return false unless @list
|
119
|
-
|
120
|
-
@list.is_a?(Array)
|
121
|
-
end
|
122
|
-
|
123
|
-
#
|
124
|
-
# 元号情報を検証する
|
125
|
-
#
|
126
|
-
# @return [Array<String>] 不正メッセージ
|
127
|
-
#
|
128
|
-
def validate_list
|
129
|
-
return ["invalid list. #{@list.class}"] unless list?
|
130
|
-
|
131
|
-
failed = []
|
132
|
-
list.each_with_index do |li, index|
|
133
|
-
failed |= Gengou.new(hash: li, index: index).validate
|
134
|
-
end
|
135
|
-
failed
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
#
|
140
|
-
# Gengou 元号情報
|
141
|
-
#
|
142
|
-
class Gengou
|
143
|
-
# @return [Integer] 要素位置
|
144
|
-
attr_reader :index
|
145
|
-
# @return [String] 元号名
|
146
|
-
attr_reader :name
|
147
|
-
# @return [Hash<String, String>] 開始年
|
148
|
-
attr_reader :both_start_year
|
149
|
-
# @return [Hash<String, String>] 開始日
|
150
|
-
attr_reader :both_start_date
|
151
|
-
|
152
|
-
#
|
153
|
-
# 初期化
|
154
|
-
#
|
155
|
-
# @param [Hash<String, Strin>] hash 元号情報
|
156
|
-
# @param [Integer] index (元号セット内での)元号の要素位置
|
157
|
-
#
|
158
|
-
def initialize(hash:, index:)
|
159
|
-
@index = index
|
160
|
-
@name = hash['name']
|
161
|
-
@both_start_year = hash['start_year']
|
162
|
-
@both_start_date = hash['start_date']
|
163
|
-
end
|
164
|
-
|
165
|
-
#
|
166
|
-
# 検証する
|
167
|
-
#
|
168
|
-
# @return [Array<String>] 不正メッセージ
|
169
|
-
#
|
170
|
-
def validate
|
171
|
-
prefix = "list[#{index}]. "
|
172
|
-
failed = []
|
173
|
-
|
174
|
-
failed.push(prefix + "invalid name. #{@name}") unless name?
|
175
|
-
|
176
|
-
failed |= validate_both_start_year
|
177
|
-
|
178
|
-
failed |= validate_both_start_date
|
179
|
-
|
180
|
-
failed
|
181
|
-
end
|
182
|
-
|
183
|
-
#
|
184
|
-
# 元号名を検証する
|
185
|
-
#
|
186
|
-
# @return [True] 正しい
|
187
|
-
# @return [False] 正しくない
|
188
|
-
#
|
189
|
-
def name?
|
190
|
-
return false unless @name
|
191
|
-
|
192
|
-
@name.is_a?(String)
|
193
|
-
end
|
194
|
-
|
195
|
-
#
|
196
|
-
# 開始年を検証する
|
197
|
-
#
|
198
|
-
# @return [Array<String>] 不正メッセージ
|
199
|
-
#
|
200
|
-
def validate_both_start_year
|
201
|
-
Both::Year.new(hash: @both_start_year).validate
|
202
|
-
end
|
203
|
-
|
204
|
-
#
|
205
|
-
# 開始日を検証する
|
206
|
-
#
|
207
|
-
# @return [Array<String>] 不正メッセージ
|
208
|
-
#
|
209
|
-
def validate_both_start_date
|
210
|
-
Both::Date.new(hash: @both_start_date).validate
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
#
|
215
|
-
# 和暦/西暦
|
216
|
-
#
|
217
|
-
module Both
|
218
|
-
#
|
219
|
-
# Year 年
|
220
|
-
#
|
221
|
-
class Year
|
222
|
-
# @return [String] 和暦元号年
|
223
|
-
attr_reader :japan
|
224
|
-
# @return [String] 西暦年
|
225
|
-
attr_reader :western
|
21
|
+
module Validator
|
22
|
+
#
|
23
|
+
# Set 元号セット情報の検証/展開
|
24
|
+
#
|
25
|
+
class Set
|
26
|
+
# @return [String] 元号セットID
|
27
|
+
attr_reader :id
|
28
|
+
# @return [String] 元号セット名
|
29
|
+
attr_reader :name
|
30
|
+
# @return [Hash<String, String>] 終了年
|
31
|
+
attr_reader :both_last_year
|
32
|
+
# @return [Hash<String, String>] 終了日
|
33
|
+
attr_reader :both_last_date
|
34
|
+
# @return [Array<Hash<String, String>>] 元号情報
|
35
|
+
attr_reader :list
|
226
36
|
|
227
37
|
#
|
228
38
|
# 初期化
|
229
39
|
#
|
230
|
-
# @param [Hash<String,
|
40
|
+
# @param [Hash<String, Object>] hash 元号セット情報
|
231
41
|
#
|
232
42
|
def initialize(hash:)
|
233
|
-
@
|
234
|
-
@
|
43
|
+
@id = hash['id']
|
44
|
+
@name = hash['name']
|
45
|
+
@both_last_year = hash['last_year']
|
46
|
+
@both_last_date = hash['last_date']
|
47
|
+
@list = hash['list']
|
235
48
|
end
|
236
49
|
|
237
50
|
#
|
@@ -241,56 +54,112 @@ module Zakuro
|
|
241
54
|
#
|
242
55
|
def validate
|
243
56
|
failed = []
|
57
|
+
failed.push("invalid id. #{@id}") unless id?
|
244
58
|
|
245
|
-
failed.push("invalid
|
59
|
+
failed.push("invalid name. #{@name}") unless name?
|
246
60
|
|
247
|
-
failed
|
61
|
+
failed |= validate_both_last_year
|
248
62
|
|
63
|
+
failed |= validate_both_last_date
|
64
|
+
|
65
|
+
failed |= validate_list
|
249
66
|
failed
|
250
67
|
end
|
251
68
|
|
252
69
|
#
|
253
|
-
#
|
70
|
+
# IDを検証する
|
254
71
|
#
|
255
72
|
# @return [True] 正しい
|
256
73
|
# @return [False] 正しくない
|
257
74
|
#
|
258
|
-
def
|
259
|
-
return false unless @
|
75
|
+
def id?
|
76
|
+
return false unless @id
|
260
77
|
|
261
|
-
@
|
78
|
+
@id.is_a?(Integer)
|
262
79
|
end
|
263
80
|
|
264
81
|
#
|
265
|
-
#
|
82
|
+
# 元号セット名を検証する
|
266
83
|
#
|
267
84
|
# @return [True] 正しい
|
268
85
|
# @return [False] 正しくない
|
269
86
|
#
|
270
|
-
def
|
271
|
-
return false unless @
|
87
|
+
def name?
|
88
|
+
return false unless @name
|
272
89
|
|
273
|
-
@
|
90
|
+
@name.is_a?(String)
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# 終了年を検証する
|
95
|
+
#
|
96
|
+
# @return [Array<String>] 不正メッセージ
|
97
|
+
#
|
98
|
+
def validate_both_last_year
|
99
|
+
Both::Year.new(hash: @both_last_year).validate
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# 終了日を検証する
|
104
|
+
#
|
105
|
+
# @return [Array<String>] 不正メッセージ
|
106
|
+
#
|
107
|
+
def validate_both_last_date
|
108
|
+
Both::Date.new(hash: @both_last_date).validate
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# 元号情報を検証する
|
113
|
+
#
|
114
|
+
# @return [True] 正しい
|
115
|
+
# @return [False] 正しくない
|
116
|
+
#
|
117
|
+
def list?
|
118
|
+
return false unless @list
|
119
|
+
|
120
|
+
@list.is_a?(Array)
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# 元号情報を検証する
|
125
|
+
#
|
126
|
+
# @return [Array<String>] 不正メッセージ
|
127
|
+
#
|
128
|
+
def validate_list
|
129
|
+
return ["invalid list. #{@list.class}"] unless list?
|
130
|
+
|
131
|
+
failed = []
|
132
|
+
list.each_with_index do |li, index|
|
133
|
+
failed |= Gengou.new(hash: li, index: index).validate
|
134
|
+
end
|
135
|
+
failed
|
274
136
|
end
|
275
137
|
end
|
276
138
|
|
277
139
|
#
|
278
|
-
#
|
140
|
+
# Gengou 元号情報
|
279
141
|
#
|
280
|
-
class
|
281
|
-
# @return [
|
282
|
-
attr_reader :
|
283
|
-
# @return [String]
|
284
|
-
attr_reader :
|
142
|
+
class Gengou
|
143
|
+
# @return [Integer] 要素位置
|
144
|
+
attr_reader :index
|
145
|
+
# @return [String] 元号名
|
146
|
+
attr_reader :name
|
147
|
+
# @return [Hash<String, String>] 開始年
|
148
|
+
attr_reader :both_start_year
|
149
|
+
# @return [Hash<String, String>] 開始日
|
150
|
+
attr_reader :both_start_date
|
285
151
|
|
286
152
|
#
|
287
153
|
# 初期化
|
288
154
|
#
|
289
|
-
# @param [Hash<String, Strin>] hash
|
155
|
+
# @param [Hash<String, Strin>] hash 元号情報
|
156
|
+
# @param [Integer] index (元号セット内での)元号の要素位置
|
290
157
|
#
|
291
|
-
def initialize(hash:)
|
292
|
-
@
|
293
|
-
@
|
158
|
+
def initialize(hash:, index:)
|
159
|
+
@index = index
|
160
|
+
@name = hash['name']
|
161
|
+
@both_start_year = hash['start_year']
|
162
|
+
@both_start_date = hash['start_date']
|
294
163
|
end
|
295
164
|
|
296
165
|
#
|
@@ -299,46 +168,178 @@ module Zakuro
|
|
299
168
|
# @return [Array<String>] 不正メッセージ
|
300
169
|
#
|
301
170
|
def validate
|
171
|
+
prefix = "list[#{index}]. "
|
302
172
|
failed = []
|
303
173
|
|
304
|
-
failed.push("invalid
|
174
|
+
failed.push(prefix + "invalid name. #{@name}") unless name?
|
175
|
+
|
176
|
+
failed |= validate_both_start_year
|
305
177
|
|
306
|
-
failed
|
178
|
+
failed |= validate_both_start_date
|
307
179
|
|
308
180
|
failed
|
309
181
|
end
|
310
182
|
|
311
183
|
#
|
312
|
-
#
|
184
|
+
# 元号名を検証する
|
313
185
|
#
|
314
186
|
# @return [True] 正しい
|
315
187
|
# @return [False] 正しくない
|
316
188
|
#
|
317
|
-
def
|
318
|
-
|
189
|
+
def name?
|
190
|
+
return false unless @name
|
191
|
+
|
192
|
+
@name.is_a?(String)
|
319
193
|
end
|
320
194
|
|
321
195
|
#
|
322
|
-
#
|
196
|
+
# 開始年を検証する
|
323
197
|
#
|
324
|
-
# @return [
|
325
|
-
#
|
198
|
+
# @return [Array<String>] 不正メッセージ
|
199
|
+
#
|
200
|
+
def validate_both_start_year
|
201
|
+
Both::Year.new(hash: @both_start_year).validate
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# 開始日を検証する
|
326
206
|
#
|
327
|
-
|
328
|
-
|
207
|
+
# @return [Array<String>] 不正メッセージ
|
208
|
+
#
|
209
|
+
def validate_both_start_date
|
210
|
+
Both::Date.new(hash: @both_start_date).validate
|
329
211
|
end
|
330
212
|
end
|
331
|
-
end
|
332
213
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
214
|
+
#
|
215
|
+
# 和暦/西暦
|
216
|
+
#
|
217
|
+
module Both
|
218
|
+
#
|
219
|
+
# Year 年
|
220
|
+
#
|
221
|
+
class Year
|
222
|
+
# @return [String] 和暦元号年
|
223
|
+
attr_reader :japan
|
224
|
+
# @return [String] 西暦年
|
225
|
+
attr_reader :western
|
226
|
+
|
227
|
+
#
|
228
|
+
# 初期化
|
229
|
+
#
|
230
|
+
# @param [Hash<String, Strin>] hash 年情報
|
231
|
+
#
|
232
|
+
def initialize(hash:)
|
233
|
+
@japan = hash['japan']
|
234
|
+
@western = hash['western']
|
235
|
+
end
|
236
|
+
|
237
|
+
#
|
238
|
+
# 検証する
|
239
|
+
#
|
240
|
+
# @return [Array<String>] 不正メッセージ
|
241
|
+
#
|
242
|
+
def validate
|
243
|
+
failed = []
|
244
|
+
|
245
|
+
failed.push("invalid japan year. #{@japan}") unless japan?
|
246
|
+
|
247
|
+
failed.push("invalid western year. #{@western}") unless western?
|
248
|
+
|
249
|
+
failed
|
250
|
+
end
|
251
|
+
|
252
|
+
#
|
253
|
+
# 和暦元号年を検証する
|
254
|
+
#
|
255
|
+
# @return [True] 正しい
|
256
|
+
# @return [False] 正しくない
|
257
|
+
#
|
258
|
+
def japan?
|
259
|
+
return false unless @japan
|
260
|
+
|
261
|
+
@japan.is_a?(Integer)
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
# 和暦元号年を検証する
|
266
|
+
#
|
267
|
+
# @return [True] 正しい
|
268
|
+
# @return [False] 正しくない
|
269
|
+
#
|
270
|
+
def western?
|
271
|
+
return false unless @western
|
272
|
+
|
273
|
+
@western.is_a?(Integer)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
#
|
278
|
+
# Date 日
|
279
|
+
#
|
280
|
+
class Date
|
281
|
+
# @return [String] 和暦日
|
282
|
+
attr_reader :japan
|
283
|
+
# @return [String] 西暦日
|
284
|
+
attr_reader :western
|
285
|
+
|
286
|
+
#
|
287
|
+
# 初期化
|
288
|
+
#
|
289
|
+
# @param [Hash<String, Strin>] hash 日情報
|
290
|
+
#
|
291
|
+
def initialize(hash:)
|
292
|
+
@japan = hash['japan']
|
293
|
+
@western = hash['western']
|
294
|
+
end
|
295
|
+
|
296
|
+
#
|
297
|
+
# 検証する
|
298
|
+
#
|
299
|
+
# @return [Array<String>] 不正メッセージ
|
300
|
+
#
|
301
|
+
def validate
|
302
|
+
failed = []
|
303
|
+
|
304
|
+
failed.push("invalid japan date. #{@japan}") unless japan?
|
305
|
+
|
306
|
+
failed.push("invalid western date. #{@western}") unless western?
|
307
|
+
|
308
|
+
failed
|
309
|
+
end
|
310
|
+
|
311
|
+
#
|
312
|
+
# 和暦日を検証する
|
313
|
+
#
|
314
|
+
# @return [True] 正しい
|
315
|
+
# @return [False] 正しくない
|
316
|
+
#
|
317
|
+
def japan?
|
318
|
+
Japan::Calendar.valid_date_string(text: @japan)
|
319
|
+
end
|
320
|
+
|
321
|
+
#
|
322
|
+
# 西暦日を検証する
|
323
|
+
#
|
324
|
+
# @return [True] 正しい
|
325
|
+
# @return [False] 正しくない
|
326
|
+
#
|
327
|
+
def western?
|
328
|
+
Western::Calendar.valid_date_string(text: @western)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
#
|
334
|
+
# 検証する
|
335
|
+
#
|
336
|
+
# @param [Hash<String, Object>] yaml_hash yaml取得結果
|
337
|
+
#
|
338
|
+
# @return [Array<String>] 不正メッセージ
|
339
|
+
#
|
340
|
+
def self.run(yaml_hash:)
|
341
|
+
Set.new(hash: yaml_hash).validate
|
342
|
+
end
|
342
343
|
end
|
343
344
|
end
|
344
345
|
end
|
@@ -4,29 +4,30 @@ require_relative './resource/parser'
|
|
4
4
|
|
5
5
|
# :nodoc:
|
6
6
|
module Zakuro
|
7
|
-
#
|
8
|
-
# Japan 和暦
|
9
|
-
#
|
7
|
+
# :nodoc:
|
10
8
|
module Japan
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
9
|
+
# :nodoc:
|
10
|
+
module Gengou
|
11
|
+
#
|
12
|
+
# Resource yaml解析結果
|
13
|
+
#
|
14
|
+
module Resource
|
15
|
+
# @return [Array<Set>] 元号セット情報リスト
|
16
|
+
LIST = [
|
17
|
+
Parser.run(filepath: File.expand_path(
|
18
|
+
'./resource/yaml/set-001-until-south.yaml',
|
19
|
+
__dir__
|
20
|
+
)),
|
21
|
+
Parser.run(filepath: File.expand_path(
|
22
|
+
'./resource/yaml/set-002-from-north.yaml',
|
23
|
+
__dir__
|
24
|
+
)),
|
25
|
+
Parser.run(filepath: File.expand_path(
|
26
|
+
'./resource/yaml/set-003-modern.yaml',
|
27
|
+
__dir__
|
28
|
+
))
|
29
|
+
].freeze
|
30
|
+
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -36,31 +36,16 @@ module Zakuro
|
|
36
36
|
end
|
37
37
|
|
38
38
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# @param [Western::Calendar] start_date 開始日
|
42
|
-
# @param [Western::Calendar] last_date 終了日
|
43
|
-
#
|
44
|
-
# @return [Array<LinearGengou>] 1行目元号
|
45
|
-
#
|
46
|
-
def self.first_line(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
47
|
-
Alignment.get(
|
48
|
-
line: FIRST_LINE, start_date: start_date, last_date: last_date
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# 2行目元号を取得する
|
39
|
+
# 該当行の元号を取得する(元号名)
|
54
40
|
#
|
41
|
+
# @param [Integer] line 行番号
|
55
42
|
# @param [Western::Calendar] start_date 開始日
|
56
43
|
# @param [Western::Calendar] last_date 終了日
|
57
44
|
#
|
58
|
-
# @return [Array<LinearGengou>]
|
45
|
+
# @return [Array<LinearGengou>] 該当行の元号
|
59
46
|
#
|
60
|
-
def self.
|
61
|
-
Alignment.
|
62
|
-
line: SECOND_LINE, start_date: start_date, last_date: last_date
|
63
|
-
)
|
47
|
+
def self.line_by_name(line: FIRST_LINE, name:)
|
48
|
+
Alignment.get_by_name(line: line, name: name)
|
64
49
|
end
|
65
50
|
end
|
66
51
|
end
|