zakuro 0.7.2 → 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/README.md +3 -3
- data/VERSION +1 -1
- data/lib/zakuro/calculation/base/gengou.rb +5 -5
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +23 -21
- data/lib/zakuro/calculation/base/year.rb +3 -3
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
- 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/abstract_scroll.rb +38 -29
- 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/abstract_list.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
- 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 +39 -37
- data/lib/zakuro/calculation/monthly/month.rb +15 -15
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- 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 +5 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
- data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
- data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +95 -92
- data/lib/zakuro/calculation/summary/western/single.rb +78 -76
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -124
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/condition.rb +121 -111
- data/lib/zakuro/context/context.rb +1 -1
- data/lib/zakuro/context/option.rb +31 -29
- data/lib/zakuro/context/version_class_resolver.rb +26 -24
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
- data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -36
- data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -37
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
- data/lib/zakuro/era/japan/gengou.rb +28 -26
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +102 -90
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +15 -13
- data/lib/zakuro/exception/zakuro_error.rb +1 -1
- data/lib/zakuro/gateway/locale/date.rb +2 -2
- data/lib/zakuro/gateway/locale/range.rb +3 -3
- data/lib/zakuro/gateway/range.rb +1 -1
- data/lib/zakuro/gateway/single.rb +13 -2
- data/lib/zakuro/merchant.rb +1 -1
- data/lib/zakuro/operation/month/parser.rb +252 -251
- data/lib/zakuro/operation/month/type.rb +17 -8
- data/lib/zakuro/operation/month/validator.rb +148 -144
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/output/response.rb +112 -113
- data/lib/zakuro/result/operation/month/annotation.rb +2 -2
- data/lib/zakuro/result/operation/month/history.rb +2 -2
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +39 -0
- data/lib/zakuro/result/result.rb +3 -3
- data/lib/zakuro/tools/stringifier.rb +66 -64
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
- 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 +2 -2
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- 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/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
- 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/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
- 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 +12 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/bundle.rb +0 -44
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -26,70 +26,72 @@ module Zakuro
|
|
26
26
|
# @return [Output::Logger] ロガー
|
27
27
|
LOGGER = Output::Logger.new(location: 'specifier')
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
Output::Response::SingleDay.create(
|
45
|
-
year: year, month: month, day: day, options: options
|
46
|
-
)
|
47
|
-
end
|
29
|
+
class << self
|
30
|
+
#
|
31
|
+
# 取得する
|
32
|
+
#
|
33
|
+
# @param [Array<Calculation::Base::Year>] years 範囲
|
34
|
+
# @param [Western::Calendar] date 西暦日
|
35
|
+
#
|
36
|
+
# @return [Result::Data::SingleDay] 和暦日
|
37
|
+
#
|
38
|
+
def get(years: [], date: Western::Calendar.new)
|
39
|
+
year, month = specify(years: years, date: date)
|
40
|
+
|
41
|
+
day = Day.get(month: month, date: date)
|
42
|
+
|
43
|
+
options = Option.create(month: month, day: day)
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# @param [Array<Year>] years 範囲
|
53
|
-
# @param [Western::Calendar] date 西暦日
|
54
|
-
#
|
55
|
-
# @return [Base::Year] 対象年
|
56
|
-
# @return [Monthly::Month] 対象月
|
57
|
-
#
|
58
|
-
# @raise [ArgumentError] 引数エラー
|
59
|
-
#
|
60
|
-
def self.specify(years:, date:)
|
61
|
-
years.each do |year|
|
62
|
-
month = specify_month(year: year, date: date)
|
63
|
-
return year, month unless month.invalid?
|
45
|
+
Output::Response::SingleDay.create(
|
46
|
+
year: year, month: month, day: day, options: options
|
47
|
+
)
|
64
48
|
end
|
65
49
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
return month if month.include?(date: date)
|
50
|
+
private
|
51
|
+
|
52
|
+
#
|
53
|
+
# 年を特定する
|
54
|
+
#
|
55
|
+
# @param [Array<Year>] years 範囲
|
56
|
+
# @param [Western::Calendar] date 西暦日
|
57
|
+
#
|
58
|
+
# @return [Base::Year] 対象年
|
59
|
+
# @return [Monthly::Month] 対象月
|
60
|
+
#
|
61
|
+
# @raise [ArgumentError] 引数エラー
|
62
|
+
#
|
63
|
+
def specify(years:, date:)
|
64
|
+
years.each do |year|
|
65
|
+
month = specify_month(year: year, date: date)
|
66
|
+
return year, month unless month.invalid?
|
67
|
+
end
|
68
|
+
|
69
|
+
raise ArgumentError, "invalid year range. date: #{date.format}"
|
88
70
|
end
|
89
71
|
|
90
|
-
|
72
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
73
|
+
|
74
|
+
#
|
75
|
+
# 月を特定する
|
76
|
+
#
|
77
|
+
# @param [Base::Year] year 年
|
78
|
+
# @param [Western::Calendar] date 西暦日
|
79
|
+
#
|
80
|
+
# @return [Monthly::Month] 対象月
|
81
|
+
#
|
82
|
+
def specify_month(year:, date:)
|
83
|
+
months = year.months
|
84
|
+
|
85
|
+
months.each do |month|
|
86
|
+
western_date = month.western_date
|
87
|
+
next if western_date.invalid?
|
88
|
+
|
89
|
+
return month if month.include?(date: date)
|
90
|
+
end
|
91
|
+
|
92
|
+
Monthly::Month.new
|
93
|
+
end
|
91
94
|
end
|
92
|
-
private_class_method :specify_month
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
data/lib/zakuro/condition.rb
CHANGED
@@ -26,26 +26,28 @@ module Zakuro
|
|
26
26
|
@date = date
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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)
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
template: Exception::Case::Pattern::INVALID_DATE_TYPE
|
43
|
+
failed.push(
|
44
|
+
Exception::Case::Preset.new(
|
45
|
+
date.class,
|
46
|
+
template: Exception::Case::Pattern::INVALID_DATE_TYPE
|
47
|
+
)
|
46
48
|
)
|
47
|
-
|
48
|
-
|
49
|
+
failed
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -72,31 +74,33 @@ module Zakuro
|
|
72
74
|
|
73
75
|
# :reek:TooManyStatements { max_statements: 7 }
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
+
)
|
91
95
|
)
|
92
|
-
|
93
|
-
|
94
|
-
end
|
96
|
+
return failed
|
97
|
+
end
|
95
98
|
|
96
|
-
|
97
|
-
|
99
|
+
failed.concat(BasisDate.validate(date: hash[:start]))
|
100
|
+
failed.concat(BasisDate.validate(date: hash[:last]))
|
98
101
|
|
99
|
-
|
102
|
+
failed
|
103
|
+
end
|
100
104
|
end
|
101
105
|
|
102
106
|
#
|
@@ -131,29 +135,31 @@ module Zakuro
|
|
131
135
|
@columns = columns
|
132
136
|
end
|
133
137
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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 = []
|
144
149
|
|
145
|
-
|
150
|
+
return failed unless columns
|
146
151
|
|
147
|
-
|
152
|
+
return failed if columns.is_a?(Array)
|
148
153
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
154
|
+
failed.push(
|
155
|
+
Exception::Case::Preset.new(
|
156
|
+
hash.class,
|
157
|
+
template: Exception::Case::Pattern::INVALID_COLUMN_TYPE
|
158
|
+
)
|
153
159
|
)
|
154
|
-
)
|
155
160
|
|
156
|
-
|
161
|
+
failed
|
162
|
+
end
|
157
163
|
end
|
158
164
|
end
|
159
165
|
|
@@ -180,26 +186,28 @@ module Zakuro
|
|
180
186
|
|
181
187
|
# TODO: オプションキーのバリデーション
|
182
188
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
193
200
|
|
194
|
-
|
201
|
+
return failed if options.is_a?(Hash)
|
195
202
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
203
|
+
failed.push(
|
204
|
+
Exception::Case::Preset.new(
|
205
|
+
hash.class,
|
206
|
+
template: Exception::Case::Pattern::INVALID_OPTION_TYPE
|
207
|
+
)
|
200
208
|
)
|
201
|
-
|
202
|
-
|
209
|
+
failed
|
210
|
+
end
|
203
211
|
end
|
204
212
|
end
|
205
213
|
end
|
@@ -235,46 +243,48 @@ module Zakuro
|
|
235
243
|
|
236
244
|
# :reek:TooManyStatements { max_statements: 8 }
|
237
245
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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
|
+
)
|
253
263
|
)
|
254
|
-
|
255
|
-
|
256
|
-
end
|
264
|
+
return failed
|
265
|
+
end
|
257
266
|
|
258
|
-
|
267
|
+
failed.concat(validate_hash(hash: hash))
|
259
268
|
|
260
|
-
|
261
|
-
|
269
|
+
failed
|
270
|
+
end
|
262
271
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
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
|
278
288
|
end
|
279
289
|
|
280
290
|
#
|
@@ -82,35 +82,37 @@ module Zakuro
|
|
82
82
|
false
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
114
116
|
end
|
115
117
|
end
|
116
118
|
end
|
@@ -48,33 +48,13 @@ module Zakuro
|
|
48
48
|
@version_name = version_name
|
49
49
|
end
|
50
50
|
|
51
|
-
#
|
52
|
-
# 該当の暦のクラスを取得する
|
53
|
-
#
|
54
|
-
# @param [String] version_name 暦名
|
55
|
-
# @param [String] class_name クラス名
|
56
|
-
#
|
57
|
-
# @return [Object] 該当クラス
|
58
|
-
#
|
59
|
-
# @raise [ArgumentError] 引数エラー
|
60
|
-
#
|
61
|
-
def self.get_class(version_name:, class_name:)
|
62
|
-
constant = CLASSES.fetch(class_name, '')
|
63
|
-
|
64
|
-
raise ArgumentError.new, 'invalid class name' if constant == ''
|
65
|
-
|
66
|
-
resolved_constant = constant.gsub('$VERSION', version_name)
|
67
|
-
|
68
|
-
Object.const_get(resolved_constant)
|
69
|
-
end
|
70
|
-
|
71
51
|
#
|
72
52
|
# 大余小余(暦別)クラスを返す
|
73
53
|
#
|
74
54
|
# @return [Class] 大余小余(暦別)クラス
|
75
55
|
#
|
76
56
|
def remainder
|
77
|
-
|
57
|
+
self.class.get_class(version_name: @version_name, class_name: 'remainder')
|
78
58
|
end
|
79
59
|
|
80
60
|
#
|
@@ -83,7 +63,7 @@ module Zakuro
|
|
83
63
|
# @return [Class] 二十四節気クラス
|
84
64
|
#
|
85
65
|
def solar_term
|
86
|
-
|
66
|
+
self.class.get_class(version_name: @version_name, class_name: 'solar_term')
|
87
67
|
end
|
88
68
|
|
89
69
|
#
|
@@ -92,7 +72,7 @@ module Zakuro
|
|
92
72
|
# @return [Class] 年間範囲クラス
|
93
73
|
#
|
94
74
|
def annual_range
|
95
|
-
|
75
|
+
self.class.get_class(version_name: @version_name, class_name: 'annual_range')
|
96
76
|
end
|
97
77
|
|
98
78
|
#
|
@@ -101,10 +81,32 @@ module Zakuro
|
|
101
81
|
# @return [Class] 没日引数クラス
|
102
82
|
#
|
103
83
|
def dropped_date_parameter
|
104
|
-
|
84
|
+
self.class.get_class(
|
105
85
|
version_name: @version_name, class_name: 'dropped_date_parameter'
|
106
86
|
)
|
107
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
|
108
110
|
end
|
109
111
|
end
|
110
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
|