zakuro 0.7.0 → 0.9.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 +48 -13
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/csv/month.csv +100 -79
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/day.rb +52 -0
- 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 +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/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 +40 -38
- data/lib/zakuro/calculation/monthly/month.rb +17 -17
- 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/abstract_full_range.rb +40 -25
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +111 -109
- data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
- 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/summary/internal/month.rb +32 -11
- 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 +145 -118
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +57 -50
- 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 -119
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +63 -56
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +142 -92
- 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 +8 -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 -34
- data/lib/zakuro/era/japan/gengou/resource/type.rb +45 -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 +104 -88
- data/lib/zakuro/exception/case/pattern.rb +39 -3
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +17 -15
- data/lib/zakuro/exception/zakuro_error.rb +19 -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 +3 -3
- data/lib/zakuro/gateway/single.rb +14 -3
- data/lib/zakuro/merchant.rb +79 -9
- data/lib/zakuro/operation/month/parser.rb +252 -249
- 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/operation/yaml/month.yaml +955 -281
- data/lib/zakuro/output/response.rb +107 -141
- 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 +9 -1
- 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 +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 +7 -1
- 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 +27 -7
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
- data/lib/zakuro/result/operation/operation.rb +0 -44
- data/lib/zakuro/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -53,11 +53,11 @@ module Zakuro
|
|
53
53
|
# @return [Gengou] 元号情報
|
54
54
|
#
|
55
55
|
def create
|
56
|
-
|
57
|
-
|
56
|
+
start_year = Both::YearParser.new(hash: both_start_year).create
|
57
|
+
start_date = Both::DateParser.new(hash: both_start_date).create
|
58
58
|
|
59
|
-
Gengou.new(name:
|
60
|
-
both_start_date:
|
59
|
+
Gengou.new(name: name, both_start_year: start_year,
|
60
|
+
both_start_date: start_date)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -95,10 +95,10 @@ module Zakuro
|
|
95
95
|
# @return [Set] 元号セット情報
|
96
96
|
#
|
97
97
|
def create
|
98
|
-
|
98
|
+
last_date = Both::DateParser.new(hash: both_last_date).create
|
99
99
|
list = create_list
|
100
100
|
Set.new(
|
101
|
-
id:
|
101
|
+
id: id, name: name, both_last_date: last_date, list: list
|
102
102
|
)
|
103
103
|
end
|
104
104
|
|
@@ -111,7 +111,7 @@ module Zakuro
|
|
111
111
|
#
|
112
112
|
def create_list
|
113
113
|
result = []
|
114
|
-
|
114
|
+
list.each_with_index do |li, index|
|
115
115
|
gengou = GengouParser.new(hash: li, index: index).create
|
116
116
|
next_index = index + 1
|
117
117
|
gengou = calc_last_date_on_gengou_data(next_index: next_index,
|
@@ -122,24 +122,20 @@ module Zakuro
|
|
122
122
|
result
|
123
123
|
end
|
124
124
|
|
125
|
-
# :reek:TooManyStatements { max_statements: 6 }
|
126
|
-
|
127
125
|
#
|
128
126
|
# 次の元号の開始日から、元号の終了日に変換する
|
129
127
|
#
|
130
128
|
# @param [Integer] next_index 次の元号の要素位置
|
131
|
-
# @param [
|
129
|
+
# @param [GengouParser] gengou 元号
|
132
130
|
#
|
133
131
|
# @return [Gengou] 元号情報
|
134
132
|
#
|
135
133
|
def calc_last_date_on_gengou_data(next_index:, gengou:)
|
136
|
-
if next_index >=
|
137
|
-
gengou
|
138
|
-
last_date = Western::Calendar.parse(text: @both_last_date['western'])
|
139
|
-
gengou.write_last_date(last_date: last_date)
|
134
|
+
if next_index >= list.size
|
135
|
+
last_gengou_data(gengou: gengou)
|
140
136
|
return gengou
|
141
137
|
end
|
142
|
-
next_item =
|
138
|
+
next_item = list[next_index]
|
143
139
|
gengou.convert_next_start_year_to_last_year(
|
144
140
|
next_start_year: next_item['start_year']['western']
|
145
141
|
)
|
@@ -148,6 +144,19 @@ module Zakuro
|
|
148
144
|
)
|
149
145
|
gengou
|
150
146
|
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
#
|
151
|
+
# 最後の元号の終了日を設定する
|
152
|
+
#
|
153
|
+
# @param [GengouParser] gengou 元号
|
154
|
+
#
|
155
|
+
def last_gengou_data(gengou:)
|
156
|
+
gengou.write_last_year(last_year: both_last_year['western'])
|
157
|
+
last_date = Western::Calendar.parse(text: both_last_date['western'])
|
158
|
+
gengou.write_last_date(last_date: last_date)
|
159
|
+
end
|
151
160
|
end
|
152
161
|
|
153
162
|
#
|
@@ -179,10 +188,12 @@ module Zakuro
|
|
179
188
|
# @return [Both::Year] 年情報
|
180
189
|
#
|
181
190
|
def create
|
182
|
-
|
183
|
-
|
191
|
+
japan_year = japan.to_i
|
192
|
+
western_year = western.to_i
|
184
193
|
|
185
|
-
Japan::Gengou::Resource::Both::Year.new(
|
194
|
+
Japan::Gengou::Resource::Both::Year.new(
|
195
|
+
japan: japan_year, western: western_year
|
196
|
+
)
|
186
197
|
end
|
187
198
|
end
|
188
199
|
|
@@ -211,30 +222,36 @@ module Zakuro
|
|
211
222
|
# @return [Both::Date] 日情報
|
212
223
|
#
|
213
224
|
def create
|
214
|
-
|
215
|
-
|
225
|
+
japan_date = Japan::Calendar.parse(text: japan)
|
226
|
+
western_date = Western::Calendar.parse(text: western)
|
216
227
|
|
217
|
-
Japan::Gengou::Resource::Both::Date.new(
|
228
|
+
Japan::Gengou::Resource::Both::Date.new(
|
229
|
+
japan: japan_date, western: western_date
|
230
|
+
)
|
218
231
|
end
|
219
232
|
end
|
220
233
|
end
|
221
234
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
235
|
+
class << self
|
236
|
+
#
|
237
|
+
# 解析/展開する
|
238
|
+
#
|
239
|
+
# @param [String] filepath 元号セットファイルパス
|
240
|
+
#
|
241
|
+
# @return [Set] 元号セット情報
|
242
|
+
#
|
243
|
+
# @raise [ArgumentError] 引数エラー
|
244
|
+
#
|
245
|
+
def run(filepath: '')
|
246
|
+
yaml = YAML.load_file(filepath)
|
231
247
|
|
232
|
-
|
248
|
+
failed = Validator.run(yaml_hash: yaml)
|
233
249
|
|
234
|
-
|
250
|
+
raise ArgumentError, failed.join("\n") unless failed.empty?
|
235
251
|
|
236
|
-
|
237
|
-
|
252
|
+
parser = SetParser.new(hash: yaml)
|
253
|
+
parser.create
|
254
|
+
end
|
238
255
|
end
|
239
256
|
end
|
240
257
|
end
|
@@ -54,6 +54,8 @@ module Zakuro
|
|
54
54
|
#
|
55
55
|
# @param [Integer] last_year 終了年
|
56
56
|
#
|
57
|
+
# @raise [ArgumentError] 引数エラー
|
58
|
+
#
|
57
59
|
def write_last_year(last_year:)
|
58
60
|
unless Gengou.valid_year(year: last_year)
|
59
61
|
raise ArgumentError, "invalid year format. [#{last_year}]"
|
@@ -67,6 +69,8 @@ module Zakuro
|
|
67
69
|
#
|
68
70
|
# @param [Western::Calendar] last_date 終了日
|
69
71
|
#
|
72
|
+
# @raise [ArgumentError] 引数エラー
|
73
|
+
#
|
70
74
|
def write_last_date(last_date:)
|
71
75
|
unless Gengou.valid_date(date: last_date)
|
72
76
|
raise ArgumentError, "invalid date format. [#{last_date}]"
|
@@ -76,41 +80,13 @@ module Zakuro
|
|
76
80
|
nil
|
77
81
|
end
|
78
82
|
|
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
83
|
#
|
108
84
|
# 次の元号の開始年から、元号の終了年に変換する
|
109
85
|
#
|
110
86
|
# @param [Integer] next_start_year 次回開始年
|
111
87
|
#
|
112
88
|
def convert_next_start_year_to_last_year(next_start_year:)
|
113
|
-
if
|
89
|
+
if both_start_year.western >= next_start_year
|
114
90
|
@last_year = next_start_year
|
115
91
|
return
|
116
92
|
end
|
@@ -125,6 +101,8 @@ module Zakuro
|
|
125
101
|
#
|
126
102
|
# @param [String] next_start_date 次回開始日
|
127
103
|
#
|
104
|
+
# @raise [ArgumentError] 引数エラー
|
105
|
+
#
|
128
106
|
def convert_next_start_date_to_last_date(next_start_date: '')
|
129
107
|
raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
|
130
108
|
|
@@ -143,7 +121,7 @@ module Zakuro
|
|
143
121
|
# @return [False] 含まれない
|
144
122
|
#
|
145
123
|
def include?(date:)
|
146
|
-
date >=
|
124
|
+
date >= both_start_date.western && date <= last_date
|
147
125
|
end
|
148
126
|
|
149
127
|
#
|
@@ -153,8 +131,8 @@ module Zakuro
|
|
153
131
|
# @return [False] 不正なし
|
154
132
|
#
|
155
133
|
def invalid?
|
156
|
-
|
157
|
-
|
134
|
+
both_start_year.japan == -1 || both_start_year.invalid? ||
|
135
|
+
both_start_date.invalid? || last_date.invalid?
|
158
136
|
end
|
159
137
|
|
160
138
|
#
|
@@ -166,8 +144,38 @@ module Zakuro
|
|
166
144
|
# end
|
167
145
|
|
168
146
|
def to_s
|
169
|
-
"name: #{@name}, both_start_year: #{
|
170
|
-
"both_start_date: #{
|
147
|
+
"name: #{@name}, both_start_year: #{both_start_year.format}, " \
|
148
|
+
"both_start_date: #{both_start_date.format}, last_date: #{last_date.format}"
|
149
|
+
end
|
150
|
+
|
151
|
+
class << self
|
152
|
+
#
|
153
|
+
# 年が不正なしかどうかを確認する
|
154
|
+
#
|
155
|
+
# @param [Integer] year 年
|
156
|
+
#
|
157
|
+
# @return [True] 不正なし
|
158
|
+
# @return [False] 不正
|
159
|
+
#
|
160
|
+
def valid_year(year:)
|
161
|
+
return false unless year
|
162
|
+
|
163
|
+
year.is_a?(Integer)
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# 日付が不正なしかどうかを確認する
|
168
|
+
#
|
169
|
+
# @param [Western::Calendar] date 日付
|
170
|
+
#
|
171
|
+
# @return [True] 不正なし
|
172
|
+
# @return [False] 不正
|
173
|
+
#
|
174
|
+
def valid_date(date:)
|
175
|
+
return false unless date
|
176
|
+
|
177
|
+
date.is_a?(Western::Calendar)
|
178
|
+
end
|
171
179
|
end
|
172
180
|
end
|
173
181
|
|
@@ -213,7 +221,7 @@ module Zakuro
|
|
213
221
|
# @return [Gengou] 元号
|
214
222
|
#
|
215
223
|
def include_item(date:)
|
216
|
-
|
224
|
+
list.each do |item|
|
217
225
|
return item if item.include?(date: date)
|
218
226
|
end
|
219
227
|
|
@@ -258,7 +266,7 @@ module Zakuro
|
|
258
266
|
# @return [False] 不正なし
|
259
267
|
#
|
260
268
|
def invalid?
|
261
|
-
|
269
|
+
japan == INVALID || western == INVALID
|
262
270
|
end
|
263
271
|
end
|
264
272
|
|
@@ -283,7 +291,7 @@ module Zakuro
|
|
283
291
|
# @return [False] 不正なし
|
284
292
|
#
|
285
293
|
def invalid?
|
286
|
-
|
294
|
+
japan.invalid? || western.invalid?
|
287
295
|
end
|
288
296
|
end
|
289
297
|
end
|
@@ -54,9 +54,9 @@ module Zakuro
|
|
54
54
|
#
|
55
55
|
def validate
|
56
56
|
failed = []
|
57
|
-
failed.push("invalid id. #{
|
57
|
+
failed.push("invalid id. #{id}") unless id?
|
58
58
|
|
59
|
-
failed.push("invalid name. #{
|
59
|
+
failed.push("invalid name. #{name}") unless name?
|
60
60
|
|
61
61
|
failed |= validate_both_last_year
|
62
62
|
|
@@ -73,9 +73,9 @@ module Zakuro
|
|
73
73
|
# @return [False] 正しくない
|
74
74
|
#
|
75
75
|
def id?
|
76
|
-
return false unless
|
76
|
+
return false unless id
|
77
77
|
|
78
|
-
|
78
|
+
id.is_a?(Integer)
|
79
79
|
end
|
80
80
|
|
81
81
|
#
|
@@ -87,7 +87,7 @@ module Zakuro
|
|
87
87
|
def name?
|
88
88
|
return false unless @name
|
89
89
|
|
90
|
-
|
90
|
+
name.is_a?(String)
|
91
91
|
end
|
92
92
|
|
93
93
|
#
|
@@ -96,7 +96,7 @@ module Zakuro
|
|
96
96
|
# @return [Array<String>] 不正メッセージ
|
97
97
|
#
|
98
98
|
def validate_both_last_year
|
99
|
-
Both::Year.new(hash:
|
99
|
+
Both::Year.new(hash: both_last_year).validate
|
100
100
|
end
|
101
101
|
|
102
102
|
#
|
@@ -105,7 +105,7 @@ module Zakuro
|
|
105
105
|
# @return [Array<String>] 不正メッセージ
|
106
106
|
#
|
107
107
|
def validate_both_last_date
|
108
|
-
Both::Date.new(hash:
|
108
|
+
Both::Date.new(hash: both_last_date).validate
|
109
109
|
end
|
110
110
|
|
111
111
|
#
|
@@ -115,9 +115,9 @@ module Zakuro
|
|
115
115
|
# @return [False] 正しくない
|
116
116
|
#
|
117
117
|
def list?
|
118
|
-
return false unless
|
118
|
+
return false unless list
|
119
119
|
|
120
|
-
|
120
|
+
list.is_a?(Array)
|
121
121
|
end
|
122
122
|
|
123
123
|
#
|
@@ -126,7 +126,7 @@ module Zakuro
|
|
126
126
|
# @return [Array<String>] 不正メッセージ
|
127
127
|
#
|
128
128
|
def validate_list
|
129
|
-
return ["invalid list. #{
|
129
|
+
return ["invalid list. #{list.class}"] unless list?
|
130
130
|
|
131
131
|
failed = []
|
132
132
|
list.each_with_index do |li, index|
|
@@ -171,7 +171,7 @@ module Zakuro
|
|
171
171
|
prefix = "list[#{index}]. "
|
172
172
|
failed = []
|
173
173
|
|
174
|
-
failed.push(prefix + "invalid name. #{
|
174
|
+
failed.push(prefix + "invalid name. #{name}") unless name?
|
175
175
|
|
176
176
|
failed |= validate_both_start_year
|
177
177
|
|
@@ -187,9 +187,9 @@ module Zakuro
|
|
187
187
|
# @return [False] 正しくない
|
188
188
|
#
|
189
189
|
def name?
|
190
|
-
return false unless
|
190
|
+
return false unless name
|
191
191
|
|
192
|
-
|
192
|
+
name.is_a?(String)
|
193
193
|
end
|
194
194
|
|
195
195
|
#
|
@@ -198,7 +198,7 @@ module Zakuro
|
|
198
198
|
# @return [Array<String>] 不正メッセージ
|
199
199
|
#
|
200
200
|
def validate_both_start_year
|
201
|
-
Both::Year.new(hash:
|
201
|
+
Both::Year.new(hash: both_start_year).validate
|
202
202
|
end
|
203
203
|
|
204
204
|
#
|
@@ -207,7 +207,7 @@ module Zakuro
|
|
207
207
|
# @return [Array<String>] 不正メッセージ
|
208
208
|
#
|
209
209
|
def validate_both_start_date
|
210
|
-
Both::Date.new(hash:
|
210
|
+
Both::Date.new(hash: both_start_date).validate
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
@@ -242,9 +242,9 @@ module Zakuro
|
|
242
242
|
def validate
|
243
243
|
failed = []
|
244
244
|
|
245
|
-
failed.push("invalid japan year. #{
|
245
|
+
failed.push("invalid japan year. #{japan}") unless japan?
|
246
246
|
|
247
|
-
failed.push("invalid western year. #{
|
247
|
+
failed.push("invalid western year. #{western}") unless western?
|
248
248
|
|
249
249
|
failed
|
250
250
|
end
|
@@ -258,7 +258,7 @@ module Zakuro
|
|
258
258
|
def japan?
|
259
259
|
return false unless @japan
|
260
260
|
|
261
|
-
|
261
|
+
japan.is_a?(Integer)
|
262
262
|
end
|
263
263
|
|
264
264
|
#
|
@@ -270,7 +270,7 @@ module Zakuro
|
|
270
270
|
def western?
|
271
271
|
return false unless @western
|
272
272
|
|
273
|
-
|
273
|
+
western.is_a?(Integer)
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
@@ -301,9 +301,9 @@ module Zakuro
|
|
301
301
|
def validate
|
302
302
|
failed = []
|
303
303
|
|
304
|
-
failed.push("invalid japan date. #{
|
304
|
+
failed.push("invalid japan date. #{japan}") unless japan?
|
305
305
|
|
306
|
-
failed.push("invalid western date. #{
|
306
|
+
failed.push("invalid western date. #{western}") unless western?
|
307
307
|
|
308
308
|
failed
|
309
309
|
end
|
@@ -315,7 +315,7 @@ module Zakuro
|
|
315
315
|
# @return [False] 正しくない
|
316
316
|
#
|
317
317
|
def japan?
|
318
|
-
Japan::Calendar.valid_date_string(text:
|
318
|
+
Japan::Calendar.valid_date_string(text: japan)
|
319
319
|
end
|
320
320
|
|
321
321
|
#
|
@@ -325,20 +325,22 @@ module Zakuro
|
|
325
325
|
# @return [False] 正しくない
|
326
326
|
#
|
327
327
|
def western?
|
328
|
-
Western::Calendar.valid_date_string(text:
|
328
|
+
Western::Calendar.valid_date_string(text: western)
|
329
329
|
end
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
333
|
+
class << self
|
334
|
+
#
|
335
|
+
# 検証する
|
336
|
+
#
|
337
|
+
# @param [Hash<String, Object>] yaml_hash yaml取得結果
|
338
|
+
#
|
339
|
+
# @return [Array<String>] 不正メッセージ
|
340
|
+
#
|
341
|
+
def run(yaml_hash:)
|
342
|
+
Set.new(hash: yaml_hash).validate
|
343
|
+
end
|
342
344
|
end
|
343
345
|
end
|
344
346
|
end
|
@@ -19,33 +19,35 @@ module Zakuro
|
|
19
19
|
# @return [Integer] 2行目
|
20
20
|
SECOND_LINE = Alignment::Aligner::SECOND_LINE
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
22
|
+
class << self
|
23
|
+
#
|
24
|
+
# 該当行の元号を取得する
|
25
|
+
#
|
26
|
+
# @param [Integer] line 行番号
|
27
|
+
# @param [Western::Calendar] start_date 開始日
|
28
|
+
# @param [Western::Calendar] last_date 終了日
|
29
|
+
#
|
30
|
+
# @return [Array<LinearGengou>] 該当行の元号
|
31
|
+
#
|
32
|
+
def line(line: FIRST_LINE,
|
33
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
34
|
+
Alignment.get(
|
35
|
+
line: line, start_date: start_date, last_date: last_date
|
36
|
+
)
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
39
|
+
#
|
40
|
+
# 該当行の元号を取得する(元号名)
|
41
|
+
#
|
42
|
+
# @param [Integer] line 行番号
|
43
|
+
# @param [Western::Calendar] start_date 開始日
|
44
|
+
# @param [Western::Calendar] last_date 終了日
|
45
|
+
#
|
46
|
+
# @return [Array<LinearGengou>] 該当行の元号
|
47
|
+
#
|
48
|
+
def line_by_name(line: FIRST_LINE, name:)
|
49
|
+
Alignment.get_by_name(line: line, name: name)
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -125,26 +125,28 @@ module Zakuro
|
|
125
125
|
)
|
126
126
|
].freeze
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
128
|
+
class << self
|
129
|
+
#
|
130
|
+
# 年を基準に暦を引き当てる
|
131
|
+
#
|
132
|
+
# @param [Integer] start_year 開始西暦年
|
133
|
+
# @param [Integer] last_year 終了西暦年
|
134
|
+
#
|
135
|
+
# @return [Array<Range>] 和暦
|
136
|
+
#
|
137
|
+
def ranges_with_year(start_year:, last_year:)
|
138
|
+
result = []
|
138
139
|
|
139
|
-
|
140
|
-
|
140
|
+
LIST.each do |range|
|
141
|
+
next if start_year > range.last_year
|
141
142
|
|
142
|
-
|
143
|
+
next if last_year < range.start_year
|
143
144
|
|
144
|
-
|
145
|
-
|
145
|
+
result.push(range)
|
146
|
+
end
|
146
147
|
|
147
|
-
|
148
|
+
result
|
149
|
+
end
|
148
150
|
end
|
149
151
|
end
|
150
152
|
end
|