zakuro 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/VERSION +1 -1
- data/lib/zakuro/calculation/base/gengou.rb +4 -4
- data/lib/zakuro/calculation/base/linear_gengou.rb +6 -6
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/list.rb +244 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
- data/lib/zakuro/calculation/{gengou → era/gengou}/internal/reserve.rb +6 -6
- data/lib/zakuro/calculation/{gengou → era/gengou}/scroll.rb +44 -95
- data/lib/zakuro/calculation/{version → era/version}/internal/crawler.rb +7 -7
- data/lib/zakuro/calculation/{version → era/version}/internal/range.rb +4 -4
- data/lib/zakuro/calculation/{version → era/version}/version.rb +3 -3
- data/lib/zakuro/calculation/monthly/month.rb +2 -2
- data/lib/zakuro/calculation/range/full_range.rb +18 -19
- data/lib/zakuro/calculation/range/operated_range.rb +3 -4
- data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
- data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +2 -2
- data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
- data/lib/zakuro/calculation/summary/range.rb +120 -0
- data/lib/zakuro/calculation/summary/single.rb +45 -67
- data/lib/zakuro/condition.rb +14 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-001-until-south.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-002-from-north.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-003-modern.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
- data/lib/zakuro/era/japan/gengou.rb +34 -73
- data/lib/zakuro/era/japan/version.rb +18 -18
- data/lib/zakuro/merchant.rb +41 -3
- data/lib/zakuro/operation/month/validator.rb +1 -1
- data/lib/zakuro/result/result.rb +17 -0
- data/lib/zakuro/version/senmyou/README.md +11 -7
- metadata +32 -20
- data/lib/zakuro/calculation/gengou/internal/counter.rb +0 -129
- data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +0 -183
- data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +0 -382
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -237
- data/lib/zakuro/era/japan/gengou/type.rb +0 -285
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -341
@@ -0,0 +1,292 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../western/calendar'
|
4
|
+
|
5
|
+
require_relative '../../calendar'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
#
|
10
|
+
# Japan 和暦
|
11
|
+
#
|
12
|
+
module Japan
|
13
|
+
#
|
14
|
+
# Resource yaml解析結果
|
15
|
+
#
|
16
|
+
module Resource
|
17
|
+
#
|
18
|
+
# Gengou 元号情報
|
19
|
+
#
|
20
|
+
class Gengou
|
21
|
+
# @return [String] 元号名
|
22
|
+
attr_reader :name
|
23
|
+
# @return [Both::Year] 開始年(和暦/西暦)
|
24
|
+
attr_reader :both_start_year
|
25
|
+
# @return [Both::Date] 開始日(和暦/西暦)
|
26
|
+
attr_reader :both_start_date
|
27
|
+
# @return [Integer] 終了年
|
28
|
+
attr_reader :last_year
|
29
|
+
# @return [Western::Calendar] 終了日
|
30
|
+
attr_reader :last_date
|
31
|
+
|
32
|
+
#
|
33
|
+
# 初期化
|
34
|
+
#
|
35
|
+
# @param [String] name 元号名
|
36
|
+
# @param [Both::Year] both_start_year 開始年(和暦/西暦)
|
37
|
+
# @param [Both::Date] both_start_date 開始日(和暦/西暦)
|
38
|
+
# @param [Integer] last_date 終了年
|
39
|
+
# @param [Western::Calendar] last_date 終了日
|
40
|
+
#
|
41
|
+
def initialize(name: '', both_start_year: Both::Year.new,
|
42
|
+
both_start_date: Both::Date.new,
|
43
|
+
last_date: Western::Calendar.new,
|
44
|
+
last_year: Both::Year::INVALID)
|
45
|
+
@name = name
|
46
|
+
@both_start_year = both_start_year
|
47
|
+
@both_start_date = both_start_date
|
48
|
+
@last_year = last_year
|
49
|
+
@last_date = last_date
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# 終了年を更新する
|
54
|
+
#
|
55
|
+
# @param [Integer] last_year 終了年
|
56
|
+
#
|
57
|
+
def write_last_year(last_year:)
|
58
|
+
unless Gengou.valid_year(year: last_year)
|
59
|
+
raise ArgumentError, "invalid year format. [#{last_year}]"
|
60
|
+
end
|
61
|
+
|
62
|
+
@last_year = last_year
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# 終了日を更新する
|
67
|
+
#
|
68
|
+
# @param [Western::Calendar] last_date 終了日
|
69
|
+
#
|
70
|
+
def write_last_date(last_date:)
|
71
|
+
unless Gengou.valid_date(date: last_date)
|
72
|
+
raise ArgumentError, "invalid date format. [#{last_date}]"
|
73
|
+
end
|
74
|
+
|
75
|
+
@last_date = last_date
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# 年が不正なしかどうかを確認する
|
81
|
+
#
|
82
|
+
# @param [Integer] year 年
|
83
|
+
#
|
84
|
+
# @return [True] 不正なし
|
85
|
+
# @return [False] 不正
|
86
|
+
#
|
87
|
+
def self.valid_year(year:)
|
88
|
+
return false unless year
|
89
|
+
|
90
|
+
year.is_a?(Integer)
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# 日付が不正なしかどうかを確認する
|
95
|
+
#
|
96
|
+
# @param [Western::Calendar] date 日付
|
97
|
+
#
|
98
|
+
# @return [True] 不正なし
|
99
|
+
# @return [False] 不正
|
100
|
+
#
|
101
|
+
def self.valid_date(date:)
|
102
|
+
return false unless date
|
103
|
+
|
104
|
+
date.is_a?(Western::Calendar)
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# 次の元号の開始年から、元号の終了年に変換する
|
109
|
+
#
|
110
|
+
# @param [Integer] next_start_year 次回開始年
|
111
|
+
#
|
112
|
+
def convert_next_start_year_to_last_year(next_start_year:)
|
113
|
+
if @both_start_year.western >= next_start_year
|
114
|
+
@last_year = next_start_year
|
115
|
+
return
|
116
|
+
end
|
117
|
+
|
118
|
+
@last_year = next_start_year - 1
|
119
|
+
|
120
|
+
nil
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# 次の元号の開始日から、元号の終了日に変換する
|
125
|
+
#
|
126
|
+
# @param [String] next_start_date 次回開始日
|
127
|
+
#
|
128
|
+
def convert_next_start_date_to_last_date(next_start_date: '')
|
129
|
+
raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
|
130
|
+
|
131
|
+
start_date = Western::Calendar.parse(str: next_start_date)
|
132
|
+
@last_date = start_date - 1
|
133
|
+
|
134
|
+
nil
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# 指定した日が元号に含まれるか
|
139
|
+
#
|
140
|
+
# @param [Western::Calendar] date 日
|
141
|
+
#
|
142
|
+
# @return [True] 含まれる
|
143
|
+
# @return [False] 含まれない
|
144
|
+
#
|
145
|
+
def include?(date:)
|
146
|
+
date >= @both_start_date.western && date <= @last_date
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# 不正か
|
151
|
+
#
|
152
|
+
# @return [True] 不正
|
153
|
+
# @return [False] 不正なし
|
154
|
+
#
|
155
|
+
def invalid?
|
156
|
+
@both_start_year.japan == -1 || @both_start_year.invalid? ||
|
157
|
+
@both_start_date.invalid? || @last_date.invalid?
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# 1元号年を追加する
|
162
|
+
#
|
163
|
+
# def next_year
|
164
|
+
# @year += 1 unless invalid?
|
165
|
+
# nil
|
166
|
+
# end
|
167
|
+
|
168
|
+
def to_s
|
169
|
+
"name: #{@name}, both_start_year: #{@both_start_year.format}, " \
|
170
|
+
"both_start_date: #{@both_start_date.format}, last_date: #{@last_date.format}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
#
|
175
|
+
# Set 元号セット
|
176
|
+
#
|
177
|
+
class Set
|
178
|
+
# @return [Integer] 不正値
|
179
|
+
INVALID = -1
|
180
|
+
# @return [Integer] 元号セットID
|
181
|
+
attr_reader :id
|
182
|
+
# @return [String] 元号セット名
|
183
|
+
attr_reader :name
|
184
|
+
# @return [Both::Date] 元号セットでの終了年
|
185
|
+
attr_reader :both_last_year
|
186
|
+
# @return [Both::Date] 元号セットでの終了日
|
187
|
+
attr_reader :both_last_date
|
188
|
+
# @return [Array<Gengou>] 元号リスト
|
189
|
+
attr_reader :list
|
190
|
+
|
191
|
+
#
|
192
|
+
# 初期化
|
193
|
+
#
|
194
|
+
# @param [Integer] id 元号セットID
|
195
|
+
# @param [String] name 元号セット名
|
196
|
+
# @param [Western::Calendar] last_date 元号セットでの終了日
|
197
|
+
# @param [Array<Gengou>] list 元号リスト
|
198
|
+
#
|
199
|
+
def initialize(id: INVALID, name: '', both_last_year: Both::Year.new,
|
200
|
+
both_last_date: Both::Date.new, list: [])
|
201
|
+
@id = id
|
202
|
+
@name = name
|
203
|
+
@both_last_year = both_last_year
|
204
|
+
@both_last_date = both_last_date
|
205
|
+
@list = list
|
206
|
+
end
|
207
|
+
|
208
|
+
#
|
209
|
+
# 指定した日付を含む元号を返す
|
210
|
+
#
|
211
|
+
# @param [Western::Calendar] date 日
|
212
|
+
#
|
213
|
+
# @return [Gengou] 元号
|
214
|
+
#
|
215
|
+
def include_item(date:)
|
216
|
+
@list.each do |item|
|
217
|
+
return item if item.include?(date: date)
|
218
|
+
end
|
219
|
+
|
220
|
+
Gengou.new
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# 元号セットが不正かどうかを確認する
|
225
|
+
#
|
226
|
+
# @return [True] 正しくない
|
227
|
+
# @return [False] 正しい
|
228
|
+
#
|
229
|
+
def invalid?
|
230
|
+
@id == INVALID
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
#
|
235
|
+
# 和暦/西暦
|
236
|
+
#
|
237
|
+
module Both
|
238
|
+
#
|
239
|
+
# Year 年
|
240
|
+
#
|
241
|
+
class Year
|
242
|
+
# @return [Integer] 不正値
|
243
|
+
INVALID = -1
|
244
|
+
# @return [Integer] 和暦元号年
|
245
|
+
attr_reader :japan
|
246
|
+
# @return [Integer] 西暦年
|
247
|
+
attr_reader :western
|
248
|
+
|
249
|
+
def initialize(japan: INVALID, western: INVALID)
|
250
|
+
@japan = japan
|
251
|
+
@western = western
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# 不正か
|
256
|
+
#
|
257
|
+
# @return [True] 不正
|
258
|
+
# @return [False] 不正なし
|
259
|
+
#
|
260
|
+
def invalid?
|
261
|
+
@japan == INVALID || @western == INVALID
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
#
|
266
|
+
# Date 日
|
267
|
+
#
|
268
|
+
class Date
|
269
|
+
# @return [Japan::Calendar] 和暦日
|
270
|
+
attr_reader :japan
|
271
|
+
# @return [Western::Calendar] 西暦日
|
272
|
+
attr_reader :western
|
273
|
+
|
274
|
+
def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
|
275
|
+
@japan = japan
|
276
|
+
@western = western
|
277
|
+
end
|
278
|
+
|
279
|
+
#
|
280
|
+
# 不正か
|
281
|
+
#
|
282
|
+
# @return [True] 不正
|
283
|
+
# @return [False] 不正なし
|
284
|
+
#
|
285
|
+
def invalid?
|
286
|
+
@japan.invalid? || @western.invalid?
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
@@ -0,0 +1,346 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../japan/calendar'
|
4
|
+
require_relative '../../../western/calendar'
|
5
|
+
require_relative './type'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
module Zakuro
|
10
|
+
#
|
11
|
+
# Japan 和暦
|
12
|
+
#
|
13
|
+
module Japan
|
14
|
+
#
|
15
|
+
# Resource yaml解析結果
|
16
|
+
#
|
17
|
+
module Resource
|
18
|
+
#
|
19
|
+
# Validator yaml解析
|
20
|
+
#
|
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
|
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
|
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(str: @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
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './resource/parser'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
#
|
8
|
+
# Japan 和暦
|
9
|
+
#
|
10
|
+
module Japan
|
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
|
31
|
+
end
|
32
|
+
end
|