zakuro 0.6.1 → 0.8.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 +46 -17
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/gengou.rb +49 -3
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +26 -24
- data/lib/zakuro/calculation/base/year.rb +7 -7
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
- data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
- data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +44 -37
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
- 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 +156 -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 +73 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
- data/lib/zakuro/calculation/era/version/version.rb +12 -10
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
- data/lib/zakuro/calculation/monthly/const.rb +18 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
- data/lib/zakuro/calculation/monthly/month.rb +55 -16
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
- data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
- data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +45 -29
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
- 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/medieval_annual_range.rb +64 -63
- 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_term.rb +220 -0
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
- data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +127 -0
- data/lib/zakuro/calculation/summary/western/single.rb +115 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +143 -94
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +119 -0
- data/lib/zakuro/context/version_class_resolver.rb +112 -0
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
- data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +28 -41
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +104 -88
- data/lib/zakuro/exception/case/pattern.rb +71 -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 +39 -0
- data/lib/zakuro/exception/zakuro_error.rb +46 -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 +81 -0
- data/lib/zakuro/merchant.rb +67 -33
- data/lib/zakuro/operation/month/parser.rb +252 -249
- data/lib/zakuro/operation/month/type.rb +44 -35
- data/lib/zakuro/operation/month/validator.rb +182 -178
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +107 -141
- 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/option/abstract_option.rb +37 -0
- data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
- data/lib/zakuro/result/data/single_day.rb +56 -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/history.rb +54 -0
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +22 -97
- data/lib/zakuro/result/result.rb +6 -4
- data/lib/zakuro/tools/stringifier.rb +67 -42
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
- data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
- data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
- metadata +68 -16
- data/lib/zakuro/calculation/range/operated_range.rb +0 -193
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
- 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/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
data/lib/zakuro/condition.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './exception/exception'
|
4
|
+
|
3
5
|
require 'date'
|
4
6
|
|
5
7
|
# :nodoc:
|
@@ -18,28 +20,34 @@ module Zakuro
|
|
18
20
|
#
|
19
21
|
# 初期化
|
20
22
|
#
|
21
|
-
# @param [Date] date
|
23
|
+
# @param [Date, String] date 西暦日/和暦日
|
22
24
|
#
|
23
25
|
def initialize(date:)
|
24
|
-
# TODO: 和暦日(String)から西暦日(Date)への変換
|
25
26
|
@date = date
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
@@ -55,7 +63,7 @@ module Zakuro
|
|
55
63
|
#
|
56
64
|
# 初期化
|
57
65
|
#
|
58
|
-
# @param [Hash<Symbol>] hash パラメータ
|
66
|
+
# @param [Hash<Symbol, Object>] hash パラメータ
|
59
67
|
# @option hash [Symbol] :start 開始日
|
60
68
|
# @option hash [Symbol] :start 終了日
|
61
69
|
#
|
@@ -66,26 +74,33 @@ module Zakuro
|
|
66
74
|
|
67
75
|
# :reek:TooManyStatements { max_statements: 7 }
|
68
76
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
83
103
|
end
|
84
|
-
|
85
|
-
failed.concat(BasisDate.validate(date: hash[:start]))
|
86
|
-
failed.concat(BasisDate.validate(date: hash[:last]))
|
87
|
-
|
88
|
-
failed
|
89
104
|
end
|
90
105
|
|
91
106
|
#
|
@@ -120,24 +135,31 @@ module Zakuro
|
|
120
135
|
@columns = columns
|
121
136
|
end
|
122
137
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
141
163
|
end
|
142
164
|
end
|
143
165
|
|
@@ -145,8 +167,8 @@ module Zakuro
|
|
145
167
|
# Options オプション
|
146
168
|
# 取得内容を変更する
|
147
169
|
#
|
148
|
-
# *
|
149
|
-
# *
|
170
|
+
# * version: 暦
|
171
|
+
# * dropped_days: 没日あり
|
150
172
|
# * seasons: 四季あり
|
151
173
|
#
|
152
174
|
class Options
|
@@ -156,7 +178,7 @@ module Zakuro
|
|
156
178
|
#
|
157
179
|
# 初期化
|
158
180
|
#
|
159
|
-
# @param [
|
181
|
+
# @param [Hash<Symbol, Object>] options オプション
|
160
182
|
#
|
161
183
|
def initialize(options: [])
|
162
184
|
@options = options
|
@@ -164,22 +186,28 @@ module Zakuro
|
|
164
186
|
|
165
187
|
# TODO: オプションキーのバリデーション
|
166
188
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
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
|
183
211
|
end
|
184
212
|
end
|
185
213
|
end
|
@@ -194,7 +222,7 @@ module Zakuro
|
|
194
222
|
attr_reader :range
|
195
223
|
# @return [Array<String>] 列
|
196
224
|
attr_reader :columns
|
197
|
-
# @return [
|
225
|
+
# @return [Hash<String, Object>] オプション
|
198
226
|
attr_reader :options
|
199
227
|
|
200
228
|
#
|
@@ -204,38 +232,59 @@ module Zakuro
|
|
204
232
|
# @option hash [Date] :date 基準日
|
205
233
|
# @option hash [Hash<Symbol, Date>] :range 範囲
|
206
234
|
# @option hash [Array<String>] :columns 列
|
207
|
-
# @option hash [
|
235
|
+
# @option hash [Hash<String, Object>] :options オプション
|
208
236
|
#
|
209
237
|
def initialize(hash: {})
|
210
238
|
@date = hash[:date]
|
211
239
|
@range = hash[:range]
|
212
240
|
@columns = hash[:columns]
|
213
|
-
@options = hash[:options]
|
241
|
+
@options = hash[:options] || {}
|
214
242
|
end
|
215
243
|
|
216
244
|
# :reek:TooManyStatements { max_statements: 8 }
|
217
245
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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))
|
227
268
|
|
228
|
-
|
229
|
-
failed.push("invalid condition type. #{hash}. should be hash")
|
230
|
-
return failed
|
269
|
+
failed
|
231
270
|
end
|
232
271
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
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]))
|
237
285
|
|
238
|
-
|
286
|
+
failed
|
287
|
+
end
|
239
288
|
end
|
240
289
|
|
241
290
|
#
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './option'
|
4
|
+
|
5
|
+
require_relative './version_class_resolver'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Context
|
11
|
+
#
|
12
|
+
# Context 暦コンテキスト
|
13
|
+
#
|
14
|
+
class Context
|
15
|
+
# @return [Option] オプション
|
16
|
+
attr_reader :option
|
17
|
+
# @return [VersionClassResolver] 暦リゾルバー
|
18
|
+
attr_reader :resolver
|
19
|
+
|
20
|
+
#
|
21
|
+
# 初期化
|
22
|
+
#
|
23
|
+
# @param [Hash<String, Object>] options オプション値
|
24
|
+
#
|
25
|
+
# @raise [ArgumentError] 引数エラー
|
26
|
+
#
|
27
|
+
def initialize(version: Option::INVALID_VERSION_NAME, options: {})
|
28
|
+
@option = Option.new(default_version: version, hash: options)
|
29
|
+
|
30
|
+
@resolver = VersionClassResolver.new(version_name: option.version)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# 不正か
|
35
|
+
#
|
36
|
+
# @return [True] 不正
|
37
|
+
# @return [False] 不正なし
|
38
|
+
#
|
39
|
+
def invalid?
|
40
|
+
!option.version?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Zakuro
|
5
|
+
# :nodoc:
|
6
|
+
module Context
|
7
|
+
#
|
8
|
+
# Option オプション値
|
9
|
+
#
|
10
|
+
class Option
|
11
|
+
# @return [String] 無効暦名
|
12
|
+
INVALID_VERSION_NAME = ''
|
13
|
+
# @return [Array<String>] 暦名
|
14
|
+
VERSION_NAMES = %w[Genka Gihou Daien Senmyou Joukyou Kansei Tenpou Gregorio].freeze
|
15
|
+
|
16
|
+
# @return [String] 没日オプションキー名
|
17
|
+
DROPPED_DATE_KEY = 'dropped_date'
|
18
|
+
|
19
|
+
# @return [Hash<String, Object>] オプション値
|
20
|
+
attr_reader :hash
|
21
|
+
# @return [String] デフォルト暦名
|
22
|
+
attr_reader :default_version
|
23
|
+
|
24
|
+
#
|
25
|
+
# 初期化
|
26
|
+
#
|
27
|
+
# @param [String] default_version デフォルト暦名
|
28
|
+
#
|
29
|
+
# @param [Hash<String, Object>] options オプション値
|
30
|
+
#
|
31
|
+
def initialize(default_version: INVALID_VERSION_NAME, hash: {})
|
32
|
+
@default_version = default_version
|
33
|
+
@hash = hash
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# 暦名を返す
|
38
|
+
#
|
39
|
+
# @return [String] 暦名
|
40
|
+
#
|
41
|
+
def version
|
42
|
+
version = self.class.version(version: @default_version)
|
43
|
+
|
44
|
+
return version if self.class.version?(version: version)
|
45
|
+
|
46
|
+
version = hash['version']
|
47
|
+
|
48
|
+
self.class.version(version: version)
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# 有効なデフォルト暦名か
|
53
|
+
#
|
54
|
+
# @return [True] 有効
|
55
|
+
# @return [False] 無効
|
56
|
+
#
|
57
|
+
def default_version?
|
58
|
+
self.class.version?(version: @default_version)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# 有効な暦名か
|
63
|
+
#
|
64
|
+
# @return [True] 有効
|
65
|
+
# @return [False] 無効
|
66
|
+
#
|
67
|
+
def version?
|
68
|
+
self.class.version?(version: version)
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# 没日か
|
73
|
+
#
|
74
|
+
# @return [True] 没日あり
|
75
|
+
# @return [False] 没日なし
|
76
|
+
#
|
77
|
+
def dropped_date?
|
78
|
+
value = @hash[DROPPED_DATE_KEY]
|
79
|
+
|
80
|
+
return true if value.is_a?(TrueClass)
|
81
|
+
|
82
|
+
false
|
83
|
+
end
|
84
|
+
|
85
|
+
class << self
|
86
|
+
#
|
87
|
+
# 暦名を返す
|
88
|
+
#
|
89
|
+
# @param [String] version 暦名
|
90
|
+
#
|
91
|
+
# @return [String] 暦名
|
92
|
+
#
|
93
|
+
def version(version: INVALID_VERSION_NAME)
|
94
|
+
return INVALID_VERSION_NAME unless version
|
95
|
+
|
96
|
+
return INVALID_VERSION_NAME if version.empty?
|
97
|
+
|
98
|
+
return INVALID_VERSION_NAME unless VERSION_NAMES.include?(version)
|
99
|
+
|
100
|
+
version
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# 有効な暦か
|
105
|
+
#
|
106
|
+
# @param [String] version 暦名
|
107
|
+
#
|
108
|
+
# @return [True] 有効
|
109
|
+
# @return [False] 無効
|
110
|
+
#
|
111
|
+
def version?(version: INVALID_VERSION_NAME)
|
112
|
+
return false if version == INVALID_VERSION_NAME
|
113
|
+
|
114
|
+
true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../version/genka/cycle/remainder'
|
4
|
+
require_relative '../version/genka/cycle/solar_term'
|
5
|
+
require_relative '../version/genka/range/annual_range'
|
6
|
+
require_relative '../version/genka/option/dropped_date/parameter'
|
7
|
+
|
8
|
+
require_relative '../version/gihou/cycle/remainder'
|
9
|
+
require_relative '../version/gihou/cycle/solar_term'
|
10
|
+
require_relative '../version/gihou/range/annual_range'
|
11
|
+
require_relative '../version/gihou/option/dropped_date/parameter'
|
12
|
+
|
13
|
+
require_relative '../version/daien/cycle/remainder'
|
14
|
+
require_relative '../version/daien/cycle/solar_term'
|
15
|
+
require_relative '../version/daien/range/annual_range'
|
16
|
+
require_relative '../version/daien/option/dropped_date/parameter'
|
17
|
+
|
18
|
+
require_relative '../version/senmyou/cycle/remainder'
|
19
|
+
require_relative '../version/senmyou/cycle/solar_term'
|
20
|
+
require_relative '../version/senmyou/range/annual_range'
|
21
|
+
require_relative '../version/senmyou/option/dropped_date/parameter'
|
22
|
+
|
23
|
+
# :nodoc:
|
24
|
+
module Zakuro
|
25
|
+
# :nodoc:
|
26
|
+
module Context
|
27
|
+
#
|
28
|
+
# VersionClassResolver 暦リゾルバー
|
29
|
+
#
|
30
|
+
class VersionClassResolver
|
31
|
+
# @return [String] 暦名
|
32
|
+
attr_reader :version_name
|
33
|
+
|
34
|
+
# @return [Hash<String, String>] 関連
|
35
|
+
CLASSES = {
|
36
|
+
'remainder' => 'Zakuro::$VERSION::Cycle::Remainder',
|
37
|
+
'solar_term' => 'Zakuro::$VERSION::Cycle::SolarTerm',
|
38
|
+
'annual_range' => 'Zakuro::$VERSION::Range::AnnualRange',
|
39
|
+
'dropped_date_parameter' => 'Zakuro::$VERSION::Option::DroppedDate::Parameter'
|
40
|
+
}.freeze
|
41
|
+
|
42
|
+
#
|
43
|
+
# 初期化
|
44
|
+
#
|
45
|
+
# @param [String] version_name 暦名
|
46
|
+
#
|
47
|
+
def initialize(version_name:)
|
48
|
+
@version_name = version_name
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# 大余小余(暦別)クラスを返す
|
53
|
+
#
|
54
|
+
# @return [Class] 大余小余(暦別)クラス
|
55
|
+
#
|
56
|
+
def remainder
|
57
|
+
self.class.get_class(version_name: @version_name, class_name: 'remainder')
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# 二十四節気クラスを返す
|
62
|
+
#
|
63
|
+
# @return [Class] 二十四節気クラス
|
64
|
+
#
|
65
|
+
def solar_term
|
66
|
+
self.class.get_class(version_name: @version_name, class_name: 'solar_term')
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# 年間範囲クラスを返す
|
71
|
+
#
|
72
|
+
# @return [Class] 年間範囲クラス
|
73
|
+
#
|
74
|
+
def annual_range
|
75
|
+
self.class.get_class(version_name: @version_name, class_name: 'annual_range')
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# 没日引数を返す
|
80
|
+
#
|
81
|
+
# @return [Class] 没日引数クラス
|
82
|
+
#
|
83
|
+
def dropped_date_parameter
|
84
|
+
self.class.get_class(
|
85
|
+
version_name: @version_name, class_name: 'dropped_date_parameter'
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
class << self
|
90
|
+
#
|
91
|
+
# 該当の暦のクラスを取得する
|
92
|
+
#
|
93
|
+
# @param [String] version_name 暦名
|
94
|
+
# @param [String] class_name クラス名
|
95
|
+
#
|
96
|
+
# @return [Object] 該当クラス
|
97
|
+
#
|
98
|
+
# @raise [ArgumentError] 引数エラー
|
99
|
+
#
|
100
|
+
def get_class(version_name:, class_name:)
|
101
|
+
constant = CLASSES.fetch(class_name, '')
|
102
|
+
|
103
|
+
raise ArgumentError.new, 'invalid class name' if constant == ''
|
104
|
+
|
105
|
+
resolved_constant = constant.gsub('$VERSION', version_name)
|
106
|
+
|
107
|
+
Object.const_get(resolved_constant)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -88,45 +88,47 @@ module Zakuro
|
|
88
88
|
@month == month
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
91
|
+
class << self
|
92
|
+
#
|
93
|
+
# 年月日情報(和暦)を生成する
|
94
|
+
#
|
95
|
+
# @param [Regexp] regex 正規表現
|
96
|
+
# @param [String] text 和暦日文字列
|
97
|
+
#
|
98
|
+
# @return [Calendar] 年月日情報(和暦)
|
99
|
+
#
|
100
|
+
def parse(regex: FORMAT, text: '')
|
101
|
+
return Calendar.new unless valid_date_string(regex: regex, text: text)
|
101
102
|
|
102
|
-
|
103
|
+
matched = text.match(regex)
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
105
|
+
Calendar.new(
|
106
|
+
gengou: matched[1],
|
107
|
+
year: Tools::Typeconv.to_i(text: matched[2], default: INVALID),
|
108
|
+
leaped: matched[3] ? true : false,
|
109
|
+
month: Tools::Typeconv.to_i(text: matched[4], default: INVALID),
|
110
|
+
day: Tools::Typeconv.to_i(text: matched[5], default: INVALID)
|
111
|
+
)
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
114
|
+
#
|
115
|
+
# 日付文字列を検証する
|
116
|
+
#
|
117
|
+
# @param [Regexp] regex 正規表現
|
118
|
+
# @param [String] text 和暦日文字列
|
119
|
+
#
|
120
|
+
# @return [True] 正しい
|
121
|
+
# @return [True] 正しくない
|
122
|
+
#
|
123
|
+
def valid_date_string(regex: FORMAT, text: '')
|
124
|
+
return false unless text
|
124
125
|
|
125
|
-
|
126
|
+
matched = text.match(regex)
|
126
127
|
|
127
|
-
|
128
|
+
return false unless matched
|
128
129
|
|
129
|
-
|
130
|
+
matched.size == 6
|
131
|
+
end
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|