zakuro 0.9.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +41 -8
- data/VERSION +1 -1
- data/doc/gengou.md +1 -1
- data/doc/operation/csv/month.csv +5 -5
- data/doc/operation/operation.xlsx +0 -0
- data/images/logo-text.png +0 -0
- data/lib/zakuro/calculation/base/gengou.rb +2 -4
- data/lib/zakuro/calculation/base/year.rb +1 -1
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +2 -2
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +1 -1
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +1 -1
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +3 -3
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +1 -1
- data/lib/zakuro/calculation/monthly/internal/date_comparer.rb +78 -0
- data/lib/zakuro/calculation/monthly/{meta → internal/meta}/all_solar_term.rb +1 -1
- data/lib/zakuro/calculation/monthly/{meta → internal/meta}/meta_collector.rb +2 -2
- data/lib/zakuro/calculation/monthly/{first_day.rb → internal/part/first_day.rb} +2 -2
- data/lib/zakuro/calculation/monthly/{meta.rb → internal/part/meta.rb} +1 -1
- data/lib/zakuro/calculation/monthly/internal/solar_term_selector.rb +203 -0
- data/lib/zakuro/calculation/monthly/month.rb +30 -125
- data/lib/zakuro/calculation/monthly/operated_month.rb +5 -2
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +0 -2
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +24 -10
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +3 -3
- data/lib/zakuro/calculation/summary/internal/option/dropped_date.rb +102 -0
- data/lib/zakuro/calculation/summary/internal/option/vanished_date.rb +111 -0
- data/lib/zakuro/calculation/summary/internal/option.rb +4 -137
- data/lib/zakuro/calculation/summary/japan/range.rb +4 -5
- data/lib/zakuro/calculation/summary/western/single.rb +0 -2
- data/lib/zakuro/context/version_class_resolver.rb +5 -5
- data/lib/zakuro/era/japan/calendar.rb +4 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +2 -2
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +2 -2
- data/lib/zakuro/era/japan/gengou/alignment.rb +5 -3
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +17 -16
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +3 -394
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +2 -2
- data/lib/zakuro/era/japan/gengou.rb +3 -3
- data/lib/zakuro/era/japan/type/base/both/date.rb +51 -0
- data/lib/zakuro/era/japan/type/base/both/year.rb +53 -0
- data/lib/zakuro/era/japan/type/base/gengou.rb +177 -0
- data/lib/zakuro/era/japan/type/base/gengou_set.rb +78 -0
- data/lib/zakuro/era/japan/type/base/switch_date.rb +74 -0
- data/lib/zakuro/era/japan/type/base/version_range.rb +189 -0
- data/lib/zakuro/era/japan/type/validation/both/date.rb +99 -0
- data/lib/zakuro/era/japan/type/validation/both/year.rb +75 -0
- data/lib/zakuro/era/japan/type/validation/gengou.rb +93 -0
- data/lib/zakuro/era/japan/type/validation/gengou_set.rb +133 -0
- data/lib/zakuro/era/japan/type/validation/switch_date.rb +73 -0
- data/lib/zakuro/era/japan/type/validation/version_range.rb +109 -0
- data/lib/zakuro/era/japan/type/validation/version_root.rb +102 -0
- data/lib/zakuro/era/japan/version/resource/parser.rb +266 -0
- data/lib/zakuro/era/japan/version/resource/validator.rb +37 -0
- data/lib/zakuro/era/japan/version/resource/yaml/version.yaml +80 -0
- data/lib/zakuro/era/japan/version/resource.rb +22 -0
- data/lib/zakuro/era/japan/version.rb +4 -115
- data/lib/zakuro/era/western/calendar.rb +2 -2
- data/lib/zakuro/exception/zakuro_error.rb +1 -1
- data/lib/zakuro/merchant.rb +5 -5
- data/lib/zakuro/operation/month/parser.rb +2 -2
- data/lib/zakuro/operation/yaml/month.yaml +5 -5
- data/lib/zakuro/output/logger.rb +4 -4
- data/lib/zakuro/parameter/catalog/basis_date.rb +55 -0
- data/lib/zakuro/parameter/catalog/column.rb +57 -0
- data/lib/zakuro/parameter/catalog/option.rb +60 -0
- data/lib/zakuro/parameter/catalog/range.rb +81 -0
- data/lib/zakuro/parameter/condition.rb +108 -0
- data/lib/zakuro/result/core.rb +2 -2
- data/lib/zakuro/{tools → tool}/remainder_comparer.rb +2 -4
- data/lib/zakuro/{tools → tool}/stringifier.rb +3 -3
- data/lib/zakuro/{tools → tool}/typeconv.rb +2 -2
- data/lib/zakuro/{tools → tool}/typeof.rb +2 -2
- data/lib/zakuro/version/daien/const/number.rb +42 -39
- data/lib/zakuro/version/daien/const/remainder.rb +38 -35
- data/lib/zakuro/version/daien/cycle/remainder.rb +77 -74
- data/lib/zakuro/version/daien/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/daien/daien.rb +8 -5
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +67 -64
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +15 -12
- data/lib/zakuro/version/daien/option/vanished_date/parameter.rb +15 -12
- data/lib/zakuro/version/daien/range/annual_range.rb +27 -24
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +209 -206
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +32 -29
- data/lib/zakuro/version/daien/stella/lunar/location.rb +53 -50
- data/lib/zakuro/version/daien/stella/lunar/value.rb +65 -62
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +23 -20
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +42 -39
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +44 -41
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +74 -71
- data/lib/zakuro/version/daien/stella/solar/average.rb +68 -65
- data/lib/zakuro/version/daien/stella/solar/interval.rb +95 -92
- data/lib/zakuro/version/daien/stella/solar/location.rb +41 -38
- data/lib/zakuro/version/daien/stella/solar/value.rb +21 -18
- data/lib/zakuro/version/genka/const/number.rb +31 -28
- data/lib/zakuro/version/genka/const/remainder.rb +20 -17
- data/lib/zakuro/version/genka/cycle/remainder.rb +72 -69
- data/lib/zakuro/version/genka/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/genka/genka.rb +8 -5
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +82 -79
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +13 -10
- data/lib/zakuro/version/genka/option/vanished_date/parameter.rb +13 -10
- data/lib/zakuro/version/genka/range/annual_range.rb +57 -54
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +44 -41
- data/lib/zakuro/version/genka/stella/origin/january.rb +38 -35
- data/lib/zakuro/version/genka/stella/solar/average.rb +24 -21
- data/lib/zakuro/version/gihou/const/number.rb +40 -37
- data/lib/zakuro/version/gihou/const/remainder.rb +32 -29
- data/lib/zakuro/version/gihou/cycle/remainder.rb +38 -35
- data/lib/zakuro/version/gihou/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/gihou/gihou.rb +8 -5
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +68 -65
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +13 -10
- data/lib/zakuro/version/gihou/option/vanished_date/parameter.rb +13 -10
- data/lib/zakuro/version/gihou/range/annual_range.rb +27 -24
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +212 -209
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +32 -29
- data/lib/zakuro/version/gihou/stella/lunar/location.rb +53 -50
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +65 -62
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +23 -20
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +42 -39
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +44 -41
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +74 -71
- data/lib/zakuro/version/gihou/stella/solar/average.rb +67 -64
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +95 -92
- data/lib/zakuro/version/gihou/stella/solar/location.rb +41 -38
- data/lib/zakuro/version/gihou/stella/solar/value.rb +21 -18
- data/lib/zakuro/version/gregorio/gregorio.rb +8 -5
- data/lib/zakuro/version/houryaku/houryaku.rb +8 -5
- data/lib/zakuro/version/joukyou/joukyou.rb +8 -5
- data/lib/zakuro/version/kansei/kansei.rb +8 -5
- data/lib/zakuro/version/senmyou/const/number.rb +40 -37
- data/lib/zakuro/version/senmyou/const/remainder.rb +35 -32
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +74 -71
- data/lib/zakuro/version/senmyou/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +69 -66
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +15 -12
- data/lib/zakuro/version/senmyou/option/vanished_date/parameter.rb +15 -12
- data/lib/zakuro/version/senmyou/range/annual_range.rb +27 -24
- data/lib/zakuro/version/senmyou/senmyou.rb +8 -5
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +206 -203
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +32 -29
- data/lib/zakuro/version/senmyou/stella/lunar/location.rb +60 -57
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -63
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +23 -20
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +42 -39
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +44 -41
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +74 -71
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +67 -64
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +93 -90
- data/lib/zakuro/version/senmyou/stella/solar/location.rb +41 -38
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +23 -20
- data/lib/zakuro/version/tenpou/tenpou.rb +8 -5
- metadata +44 -20
- data/lib/zakuro/condition.rb +0 -306
- data/lib/zakuro/era/japan/gengou/resource/type.rb +0 -356
- data/lib/zakuro/tools/gengou_range_comparer.rb +0 -82
- /data/lib/zakuro/calculation/monthly/{operated_solar_term.rb → internal/operated_solar_term.rb} +0 -0
- /data/lib/zakuro/calculation/monthly/{const.rb → internal/part/const.rb} +0 -0
- /data/lib/zakuro/calculation/monthly/{month_label.rb → internal/part/month_label.rb} +0 -0
data/lib/zakuro/condition.rb
DELETED
@@ -1,306 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './exception/exception'
|
4
|
-
|
5
|
-
require 'date'
|
6
|
-
|
7
|
-
# :nodoc:
|
8
|
-
module Zakuro
|
9
|
-
#
|
10
|
-
# Catalog 目録
|
11
|
-
#
|
12
|
-
module Catalog
|
13
|
-
#
|
14
|
-
# BasisDate 基準日
|
15
|
-
#
|
16
|
-
class BasisDate
|
17
|
-
# @return [Date] 西暦日
|
18
|
-
attr_reader :date
|
19
|
-
|
20
|
-
#
|
21
|
-
# 初期化
|
22
|
-
#
|
23
|
-
# @param [Date, String] date 西暦日/和暦日
|
24
|
-
#
|
25
|
-
def initialize(date:)
|
26
|
-
@date = date
|
27
|
-
end
|
28
|
-
|
29
|
-
class << self
|
30
|
-
#
|
31
|
-
# 検証する
|
32
|
-
#
|
33
|
-
# @param [Date] date 日付
|
34
|
-
#
|
35
|
-
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
36
|
-
#
|
37
|
-
def validate(date:)
|
38
|
-
failed = []
|
39
|
-
return failed unless date
|
40
|
-
|
41
|
-
return failed if date.is_a?(Date) || date.is_a?(String)
|
42
|
-
|
43
|
-
failed.push(
|
44
|
-
Exception::Case::Preset.new(
|
45
|
-
date.class,
|
46
|
-
template: Exception::Case::Pattern::INVALID_DATE_TYPE
|
47
|
-
)
|
48
|
-
)
|
49
|
-
failed
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# Range 範囲(開始日-終了日)
|
56
|
-
#
|
57
|
-
class Range
|
58
|
-
# @return [Date] 開始日
|
59
|
-
attr_reader :start
|
60
|
-
# @return [Date] 終了日
|
61
|
-
attr_reader :last
|
62
|
-
|
63
|
-
#
|
64
|
-
# 初期化
|
65
|
-
#
|
66
|
-
# @param [Hash<Symbol, Object>] hash パラメータ
|
67
|
-
# @option hash [Symbol] :start 開始日
|
68
|
-
# @option hash [Symbol] :start 終了日
|
69
|
-
#
|
70
|
-
def initialize(hash: {})
|
71
|
-
@start = hash[:start]
|
72
|
-
@last = hash[:last]
|
73
|
-
end
|
74
|
-
|
75
|
-
# :reek:TooManyStatements { max_statements: 7 }
|
76
|
-
|
77
|
-
class << self
|
78
|
-
#
|
79
|
-
# 検証する
|
80
|
-
#
|
81
|
-
# @param [Hash<Symbol, Object>] hash パラメータ
|
82
|
-
#
|
83
|
-
# @return [Array<Exception::Case::Preset>] エラープリセット
|
84
|
-
#
|
85
|
-
def validate(hash:)
|
86
|
-
failed = []
|
87
|
-
return failed unless hash
|
88
|
-
|
89
|
-
unless hash.is_a?(Hash)
|
90
|
-
failed.push(
|
91
|
-
Exception::Case::Preset.new(
|
92
|
-
hash.class,
|
93
|
-
template: Exception::Case::Pattern::INVALID_RANGE_TYPE
|
94
|
-
)
|
95
|
-
)
|
96
|
-
return failed
|
97
|
-
end
|
98
|
-
|
99
|
-
failed.concat(BasisDate.validate(date: hash[:start]))
|
100
|
-
failed.concat(BasisDate.validate(date: hash[:last]))
|
101
|
-
|
102
|
-
failed
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
# 不正か
|
108
|
-
#
|
109
|
-
# @return [True] 不正
|
110
|
-
# @return [False] 不正なし
|
111
|
-
#
|
112
|
-
def invalid?
|
113
|
-
return true unless @start
|
114
|
-
|
115
|
-
return true unless @end
|
116
|
-
|
117
|
-
false
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
#
|
122
|
-
# Columns 特定の列(フィールド)
|
123
|
-
# @note 指定された列のみ出力する
|
124
|
-
#
|
125
|
-
class Columns
|
126
|
-
# @return [Array<String>] 列
|
127
|
-
attr_reader :columns
|
128
|
-
|
129
|
-
#
|
130
|
-
# 初期化
|
131
|
-
#
|
132
|
-
# @param [Array<String>] columns 列
|
133
|
-
#
|
134
|
-
def initialize(columns: [])
|
135
|
-
@columns = columns
|
136
|
-
end
|
137
|
-
|
138
|
-
class << self
|
139
|
-
#
|
140
|
-
# 検証する
|
141
|
-
#
|
142
|
-
# @param [Array<String>] columns 列
|
143
|
-
#
|
144
|
-
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
145
|
-
#
|
146
|
-
def validate(columns:)
|
147
|
-
# TODO: 列内容のバリデーション
|
148
|
-
failed = []
|
149
|
-
|
150
|
-
return failed unless columns
|
151
|
-
|
152
|
-
return failed if columns.is_a?(Array)
|
153
|
-
|
154
|
-
failed.push(
|
155
|
-
Exception::Case::Preset.new(
|
156
|
-
hash.class,
|
157
|
-
template: Exception::Case::Pattern::INVALID_COLUMN_TYPE
|
158
|
-
)
|
159
|
-
)
|
160
|
-
|
161
|
-
failed
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
#
|
167
|
-
# Options オプション
|
168
|
-
# 取得内容を変更する
|
169
|
-
#
|
170
|
-
# * version: 暦
|
171
|
-
# * dropped_days: 没日あり
|
172
|
-
# * seasons: 四季あり
|
173
|
-
#
|
174
|
-
class Options
|
175
|
-
# @return [Array<String>] オプション
|
176
|
-
attr_reader :options
|
177
|
-
|
178
|
-
#
|
179
|
-
# 初期化
|
180
|
-
#
|
181
|
-
# @param [Hash<Symbol, Object>] options オプション
|
182
|
-
#
|
183
|
-
def initialize(options: [])
|
184
|
-
@options = options
|
185
|
-
end
|
186
|
-
|
187
|
-
# TODO: オプションキーのバリデーション
|
188
|
-
|
189
|
-
class << self
|
190
|
-
#
|
191
|
-
# 検証する
|
192
|
-
#
|
193
|
-
# @param [Hash<Symbol, Object>] options オプション
|
194
|
-
#
|
195
|
-
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
196
|
-
#
|
197
|
-
def validate(options:)
|
198
|
-
failed = []
|
199
|
-
return failed unless options
|
200
|
-
|
201
|
-
return failed if options.is_a?(Hash)
|
202
|
-
|
203
|
-
failed.push(
|
204
|
-
Exception::Case::Preset.new(
|
205
|
-
hash.class,
|
206
|
-
template: Exception::Case::Pattern::INVALID_OPTION_TYPE
|
207
|
-
)
|
208
|
-
)
|
209
|
-
failed
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
#
|
216
|
-
# Condition 条件
|
217
|
-
#
|
218
|
-
class Condition
|
219
|
-
# @return [Date] 基準日
|
220
|
-
attr_reader :date
|
221
|
-
# @return [Hash<Symbol, Date>] 範囲
|
222
|
-
attr_reader :range
|
223
|
-
# @return [Array<String>] 列
|
224
|
-
attr_reader :columns
|
225
|
-
# @return [Hash<String, Object>] オプション
|
226
|
-
attr_reader :options
|
227
|
-
|
228
|
-
#
|
229
|
-
# 初期化
|
230
|
-
#
|
231
|
-
# @param [Hash<Symbol, Object>] hash パラメータ
|
232
|
-
# @option hash [Date] :date 基準日
|
233
|
-
# @option hash [Hash<Symbol, Date>] :range 範囲
|
234
|
-
# @option hash [Array<String>] :columns 列
|
235
|
-
# @option hash [Hash<String, Object>] :options オプション
|
236
|
-
#
|
237
|
-
def initialize(hash: {})
|
238
|
-
@date = hash[:date]
|
239
|
-
@range = hash[:range]
|
240
|
-
@columns = hash[:columns]
|
241
|
-
@options = hash[:options] || {}
|
242
|
-
end
|
243
|
-
|
244
|
-
# :reek:TooManyStatements { max_statements: 8 }
|
245
|
-
|
246
|
-
class << self
|
247
|
-
#
|
248
|
-
# 検証する
|
249
|
-
#
|
250
|
-
# @param [Hash<Symbol, Object>] hash パラメータ
|
251
|
-
#
|
252
|
-
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
253
|
-
#
|
254
|
-
def validate(hash:)
|
255
|
-
failed = []
|
256
|
-
|
257
|
-
unless hash.is_a?(Hash)
|
258
|
-
failed.push(
|
259
|
-
Exception::Case::Preset.new(
|
260
|
-
hash.class,
|
261
|
-
template: Exception::Case::Pattern::INVALID_CONDITION_TYPE
|
262
|
-
)
|
263
|
-
)
|
264
|
-
return failed
|
265
|
-
end
|
266
|
-
|
267
|
-
failed.concat(validate_hash(hash: hash))
|
268
|
-
|
269
|
-
failed
|
270
|
-
end
|
271
|
-
|
272
|
-
#
|
273
|
-
# ハッシュ内を検証する
|
274
|
-
#
|
275
|
-
# @param [Hash<Symbol, Object>] hash パラメータ
|
276
|
-
#
|
277
|
-
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
278
|
-
#
|
279
|
-
def validate_hash(hash:)
|
280
|
-
failed = []
|
281
|
-
failed.concat(Catalog::BasisDate.validate(date: hash[:date]))
|
282
|
-
failed.concat(Catalog::Range.validate(hash: hash[:range]))
|
283
|
-
failed.concat(Catalog::Columns.validate(columns: hash[:columns]))
|
284
|
-
failed.concat(Catalog::Options.validate(options: hash[:options]))
|
285
|
-
|
286
|
-
failed
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
#
|
291
|
-
# 上書きする
|
292
|
-
#
|
293
|
-
# @param [Hash<Symbol, Object>] hash パラメータ
|
294
|
-
#
|
295
|
-
def rewrite(hash: {})
|
296
|
-
instance_variables.each do |var|
|
297
|
-
key = var.to_s.delete('@')
|
298
|
-
val = hash[key.intern]
|
299
|
-
|
300
|
-
next unless val
|
301
|
-
|
302
|
-
instance_variable_set(var, val)
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|
@@ -1,356 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../../western/calendar'
|
4
|
-
|
5
|
-
require_relative '../../calendar'
|
6
|
-
|
7
|
-
# :nodoc:
|
8
|
-
module Zakuro
|
9
|
-
# :nodoc:
|
10
|
-
module Japan
|
11
|
-
# :nodoc:
|
12
|
-
module Gengou
|
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 :start_year
|
25
|
-
# @return [SwitchDate] 開始日(和暦/西暦)
|
26
|
-
attr_reader :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] start_year 開始年(和暦/西暦)
|
37
|
-
# @param [SwitchDate] start_date 開始日(和暦/西暦)
|
38
|
-
# @param [Integer] last_date 終了年
|
39
|
-
# @param [Western::Calendar] last_date 終了日
|
40
|
-
#
|
41
|
-
def initialize(name: '', start_year: Both::Year.new,
|
42
|
-
start_date: SwitchDate.new,
|
43
|
-
last_date: Western::Calendar.new,
|
44
|
-
last_year: Both::Year::INVALID)
|
45
|
-
@name = name
|
46
|
-
@start_year = start_year
|
47
|
-
@start_date = 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
|
-
# @raise [ArgumentError] 引数エラー
|
58
|
-
#
|
59
|
-
def write_last_year(last_year:)
|
60
|
-
unless Gengou.valid_year(year: last_year)
|
61
|
-
raise ArgumentError, "invalid year format. [#{last_year}]"
|
62
|
-
end
|
63
|
-
|
64
|
-
@last_year = last_year
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
# 終了日を更新する
|
69
|
-
#
|
70
|
-
# @param [Western::Calendar] last_date 終了日
|
71
|
-
#
|
72
|
-
# @raise [ArgumentError] 引数エラー
|
73
|
-
#
|
74
|
-
def write_last_date(last_date:)
|
75
|
-
unless Gengou.valid_date(date: last_date)
|
76
|
-
raise ArgumentError, "invalid date format. [#{last_date}]"
|
77
|
-
end
|
78
|
-
|
79
|
-
@last_date = last_date
|
80
|
-
nil
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# 次の元号の開始年から、元号の終了年に変換する
|
85
|
-
#
|
86
|
-
# @param [Integer] next_start_year 次回開始年
|
87
|
-
#
|
88
|
-
def convert_next_start_year_to_last_year(next_start_year:)
|
89
|
-
if start_year.western >= next_start_year
|
90
|
-
@last_year = next_start_year
|
91
|
-
return
|
92
|
-
end
|
93
|
-
|
94
|
-
@last_year = next_start_year - 1
|
95
|
-
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
|
99
|
-
#
|
100
|
-
# 次の元号の開始日から、元号の終了日に変換する
|
101
|
-
#
|
102
|
-
# @param [Western::Calendar] next_start_date 次回開始日
|
103
|
-
#
|
104
|
-
# @raise [ArgumentError] 引数エラー
|
105
|
-
#
|
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
|
-
|
109
|
-
@last_date = next_start_date.clone - 1
|
110
|
-
|
111
|
-
nil
|
112
|
-
end
|
113
|
-
|
114
|
-
#
|
115
|
-
# 指定した日が元号に含まれるか
|
116
|
-
#
|
117
|
-
# @param [Western::Calendar] date 日
|
118
|
-
#
|
119
|
-
# @return [True] 含まれる
|
120
|
-
# @return [False] 含まれない
|
121
|
-
#
|
122
|
-
def include?(date:)
|
123
|
-
date >= start_date.western && date <= last_date
|
124
|
-
end
|
125
|
-
|
126
|
-
#
|
127
|
-
# 不正か
|
128
|
-
#
|
129
|
-
# @return [True] 不正
|
130
|
-
# @return [False] 不正なし
|
131
|
-
#
|
132
|
-
def invalid?
|
133
|
-
start_year.japan == -1 || start_year.invalid? ||
|
134
|
-
start_date.invalid? || last_date.invalid?
|
135
|
-
end
|
136
|
-
|
137
|
-
#
|
138
|
-
# 1元号年を追加する
|
139
|
-
#
|
140
|
-
# def next_year
|
141
|
-
# @year += 1 unless invalid?
|
142
|
-
# nil
|
143
|
-
# end
|
144
|
-
|
145
|
-
def to_s
|
146
|
-
"name: #{@name}, start_year: #{start_year.format}, " \
|
147
|
-
"start_date: #{start_date.format}, last_date: #{last_date.format}"
|
148
|
-
end
|
149
|
-
|
150
|
-
class << self
|
151
|
-
#
|
152
|
-
# 年が不正なしかどうかを確認する
|
153
|
-
#
|
154
|
-
# @param [Integer] year 年
|
155
|
-
#
|
156
|
-
# @return [True] 不正なし
|
157
|
-
# @return [False] 不正
|
158
|
-
#
|
159
|
-
def valid_year(year:)
|
160
|
-
return false unless year
|
161
|
-
|
162
|
-
year.is_a?(Integer)
|
163
|
-
end
|
164
|
-
|
165
|
-
#
|
166
|
-
# 日付が不正なしかどうかを確認する
|
167
|
-
#
|
168
|
-
# @param [Western::Calendar] date 日付
|
169
|
-
#
|
170
|
-
# @return [True] 不正なし
|
171
|
-
# @return [False] 不正
|
172
|
-
#
|
173
|
-
def valid_date(date:)
|
174
|
-
return false unless date
|
175
|
-
|
176
|
-
date.is_a?(Western::Calendar)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
#
|
182
|
-
# Set 元号セット
|
183
|
-
#
|
184
|
-
class Set
|
185
|
-
# @return [Integer] 不正値
|
186
|
-
INVALID = -1
|
187
|
-
# @return [Integer] 元号セットID
|
188
|
-
attr_reader :id
|
189
|
-
# @return [String] 元号セット名
|
190
|
-
attr_reader :name
|
191
|
-
# @return [Both::Date] 元号セットでの終了年
|
192
|
-
attr_reader :last_year
|
193
|
-
# @return [Both::Date] 元号セットでの終了日
|
194
|
-
attr_reader :last_date
|
195
|
-
# @return [Array<Gengou>] 元号リスト
|
196
|
-
attr_reader :list
|
197
|
-
|
198
|
-
#
|
199
|
-
# 初期化
|
200
|
-
#
|
201
|
-
# @param [Integer] id 元号セットID
|
202
|
-
# @param [String] name 元号セット名
|
203
|
-
# @param [Western::Calendar] last_date 元号セットでの終了日
|
204
|
-
# @param [Array<Gengou>] list 元号リスト
|
205
|
-
#
|
206
|
-
def initialize(id: INVALID, name: '', last_year: Both::Year.new,
|
207
|
-
last_date: Both::Date.new, list: [])
|
208
|
-
@id = id
|
209
|
-
@name = name
|
210
|
-
@last_year = last_year
|
211
|
-
@last_date = last_date
|
212
|
-
@list = list
|
213
|
-
end
|
214
|
-
|
215
|
-
#
|
216
|
-
# 指定した日付を含む元号を返す
|
217
|
-
#
|
218
|
-
# @param [Western::Calendar] date 日
|
219
|
-
#
|
220
|
-
# @return [Gengou] 元号
|
221
|
-
#
|
222
|
-
def include_item(date:)
|
223
|
-
list.each do |item|
|
224
|
-
return item if item.include?(date: date)
|
225
|
-
end
|
226
|
-
|
227
|
-
Gengou.new
|
228
|
-
end
|
229
|
-
|
230
|
-
#
|
231
|
-
# 元号セットが不正かどうかを確認する
|
232
|
-
#
|
233
|
-
# @return [True] 正しくない
|
234
|
-
# @return [False] 正しい
|
235
|
-
#
|
236
|
-
def invalid?
|
237
|
-
@id == INVALID
|
238
|
-
end
|
239
|
-
end
|
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
|
-
|
297
|
-
#
|
298
|
-
# 和暦/西暦
|
299
|
-
#
|
300
|
-
module Both
|
301
|
-
#
|
302
|
-
# Year 年
|
303
|
-
#
|
304
|
-
class Year
|
305
|
-
# @return [Integer] 不正値
|
306
|
-
INVALID = -1
|
307
|
-
# @return [Integer] 和暦元号年
|
308
|
-
attr_reader :japan
|
309
|
-
# @return [Integer] 西暦年
|
310
|
-
attr_reader :western
|
311
|
-
|
312
|
-
def initialize(japan: INVALID, western: INVALID)
|
313
|
-
@japan = japan
|
314
|
-
@western = western
|
315
|
-
end
|
316
|
-
|
317
|
-
#
|
318
|
-
# 不正か
|
319
|
-
#
|
320
|
-
# @return [True] 不正
|
321
|
-
# @return [False] 不正なし
|
322
|
-
#
|
323
|
-
def invalid?
|
324
|
-
japan == INVALID || western == INVALID
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
#
|
329
|
-
# Date 日
|
330
|
-
#
|
331
|
-
class Date
|
332
|
-
# @return [Japan::Calendar] 和暦日
|
333
|
-
attr_reader :japan
|
334
|
-
# @return [Western::Calendar] 西暦日
|
335
|
-
attr_reader :western
|
336
|
-
|
337
|
-
def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
|
338
|
-
@japan = japan
|
339
|
-
@western = western
|
340
|
-
end
|
341
|
-
|
342
|
-
#
|
343
|
-
# 不正か
|
344
|
-
#
|
345
|
-
# @return [True] 不正
|
346
|
-
# @return [False] 不正なし
|
347
|
-
#
|
348
|
-
def invalid?
|
349
|
-
japan.invalid? || western.invalid?
|
350
|
-
end
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|
356
|
-
end
|