zakuro 0.7.0 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -10
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/operated_year.rb +3 -3
- data/lib/zakuro/calculation/base/year.rb +4 -4
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +5 -3
- data/lib/zakuro/calculation/monthly/initialized_month.rb +1 -1
- data/lib/zakuro/calculation/monthly/month.rb +3 -3
- data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
- 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 +10 -8
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +2 -2
- 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 +2 -2
- 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_terms.rb +9 -9
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +6 -6
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +2 -0
- data/lib/zakuro/calculation/summary/internal/day.rb +40 -0
- data/lib/zakuro/calculation/summary/internal/month.rb +15 -7
- data/lib/zakuro/calculation/summary/internal/option.rb +85 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +15 -9
- data/lib/zakuro/calculation/summary/japan/single.rb +6 -6
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +10 -5
- data/lib/zakuro/calculation/summary/western/range.rb +5 -5
- data/lib/zakuro/calculation/summary/western/single.rb +9 -9
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +15 -10
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +12 -7
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +60 -20
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +117 -0
- data/lib/zakuro/context/version_class_resolver.rb +110 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +2 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +6 -0
- data/lib/zakuro/era/western/calendar.rb +4 -0
- data/lib/zakuro/exception/case/pattern.rb +39 -3
- data/lib/zakuro/exception/exception.rb +3 -3
- data/lib/zakuro/exception/zakuro_error.rb +19 -1
- data/lib/zakuro/gateway/range.rb +2 -2
- data/lib/zakuro/gateway/single.rb +1 -1
- data/lib/zakuro/merchant.rb +78 -8
- data/lib/zakuro/operation/month/parser.rb +2 -0
- data/lib/zakuro/output/response.rb +24 -57
- 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/{operation.rb → bundle.rb} +0 -0
- data/lib/zakuro/result/result.rb +1 -1
- data/lib/zakuro/tools/stringifier.rb +26 -3
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +1 -1
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +2 -0
- data/lib/zakuro/version/daien/stella/lunar/value.rb +2 -0
- data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +1 -1
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +1 -1
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +2 -0
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +2 -0
- 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/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +1 -1
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +2 -0
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +2 -0
- metadata +26 -9
- data/lib/zakuro/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -23,7 +23,7 @@ module Zakuro
|
|
23
23
|
#
|
24
24
|
# 生成する
|
25
25
|
#
|
26
|
-
# @param [Context] context 暦コンテキスト
|
26
|
+
# @param [Context::Context] context 暦コンテキスト
|
27
27
|
# @param [Western::Calendar] date 西暦日
|
28
28
|
#
|
29
29
|
# @return [Result::Single] 一日検索結果(和暦日)
|
@@ -44,10 +44,10 @@ module Zakuro
|
|
44
44
|
#
|
45
45
|
# 完全範囲を取得する
|
46
46
|
#
|
47
|
-
# @param [Context] context 暦コンテキスト
|
47
|
+
# @param [Context::Context] context 暦コンテキスト
|
48
48
|
# @param [Western::Calendar] date 西暦日
|
49
49
|
#
|
50
|
-
# @return [Array<Base::Year>] 完全範囲
|
50
|
+
# @return [Array<Calculation::Base::Year>] 完全範囲
|
51
51
|
#
|
52
52
|
def self.get_full_range_years(context:, date: Western::Calendar.new)
|
53
53
|
full_range = Calculation::Range::DatedFullRange.new(context: context, start_date: date)
|
@@ -58,8 +58,8 @@ module Zakuro
|
|
58
58
|
#
|
59
59
|
# 運用結果範囲を取得する
|
60
60
|
#
|
61
|
-
# @param [Context] context 暦コンテキスト
|
62
|
-
# @param [Array<Base::Year>] years 完全範囲
|
61
|
+
# @param [Context::Context] context 暦コンテキスト
|
62
|
+
# @param [Array<Calculation::Base::Year>] years 完全範囲
|
63
63
|
# @param [Western::Calendar] date 西暦日
|
64
64
|
#
|
65
65
|
# @return [Array<Base::OperatedYear>] 運用結果範囲
|
@@ -75,8 +75,8 @@ module Zakuro
|
|
75
75
|
#
|
76
76
|
# 1日を取得する
|
77
77
|
#
|
78
|
-
# @param [Context] context 暦コンテキスト
|
79
|
-
# @param [Array<Base::Year>] years 完全範囲
|
78
|
+
# @param [Context::Context] context 暦コンテキスト
|
79
|
+
# @param [Array<Calculation::Base::Year>] years 完全範囲
|
80
80
|
# @param [Western::Calendar] date 西暦日
|
81
81
|
#
|
82
82
|
# @return [Data::SingleDay] 1日
|
@@ -93,10 +93,10 @@ module Zakuro
|
|
93
93
|
#
|
94
94
|
# 完全範囲を取得する
|
95
95
|
#
|
96
|
-
# @param [
|
96
|
+
# @param [Array<Calculation::Base::Year>] years 完全範囲
|
97
97
|
# @param [Western::Calendar] date 西暦日
|
98
98
|
#
|
99
|
-
# @return [Array<Base::Year>] 完全範囲
|
99
|
+
# @return [Array<Calculation::Base::Year>] 完全範囲
|
100
100
|
#
|
101
101
|
def self.get_operation(years:, date: Western::Calendar.new)
|
102
102
|
calc_date = Specifier::SingleDay.get(
|
@@ -28,15 +28,18 @@ module Zakuro
|
|
28
28
|
#
|
29
29
|
# 取得する
|
30
30
|
#
|
31
|
-
# @param [
|
31
|
+
# @param [Context::Context] context 暦コンテキスト
|
32
|
+
# @param [Array<Calculation::Base::Year>] years 範囲
|
32
33
|
# @param [Western::Calendar] start_date 西暦開始日
|
33
34
|
# @param [Western::Calendar] last_date 西暦終了日
|
34
35
|
#
|
35
36
|
# @return [Array<Result::Data::SingleDay>] 期間検索結果(和暦日)
|
36
37
|
#
|
37
|
-
def self.get(years: [], start_date: Western::Calendar.new,
|
38
|
+
def self.get(context:, years: [], start_date: Western::Calendar.new,
|
38
39
|
last_date: Western::Calendar.new)
|
39
|
-
months = specify(
|
40
|
+
months = specify(
|
41
|
+
context: context, years: years, start_date: start_date, last_date: last_date
|
42
|
+
)
|
40
43
|
|
41
44
|
result = []
|
42
45
|
months.each do |month|
|
@@ -49,18 +52,19 @@ module Zakuro
|
|
49
52
|
#
|
50
53
|
# 年を特定する
|
51
54
|
#
|
52
|
-
# @param [
|
55
|
+
# @param [Context::Context] context 暦コンテキスト
|
56
|
+
# @param [Array<Calculation::Base::Year>] years 範囲
|
53
57
|
# @param [Western::Calendar] start_date 西暦開始日
|
54
58
|
# @param [Western::Calendar] last_date 西暦終了日
|
55
59
|
#
|
56
60
|
# @return [Array<Month>] 特定月
|
57
61
|
#
|
58
|
-
def self.specify(years: [], start_date: Western::Calendar.new,
|
62
|
+
def self.specify(context:, years: [], start_date: Western::Calendar.new,
|
59
63
|
last_date: Western::Calendar.new)
|
60
64
|
result = []
|
61
65
|
years.each do |year|
|
62
66
|
result |= specify_month(
|
63
|
-
year: year, start_date: start_date, last_date: last_date
|
67
|
+
context: context, year: year, start_date: start_date, last_date: last_date
|
64
68
|
)
|
65
69
|
end
|
66
70
|
|
@@ -73,13 +77,14 @@ module Zakuro
|
|
73
77
|
#
|
74
78
|
# 月を特定する
|
75
79
|
#
|
76
|
-
# @param [
|
80
|
+
# @param [Context::Context] context 暦コンテキスト
|
81
|
+
# @param [Calculation::Base::Year] year 年
|
77
82
|
# @param [Western::Calendar] start_date 西暦開始日
|
78
83
|
# @param [Western::Calendar] last_date 西暦終了日
|
79
84
|
#
|
80
85
|
# @return [Month] 対象月
|
81
86
|
#
|
82
|
-
def self.specify_month(year:, start_date: Western::Calendar.new,
|
87
|
+
def self.specify_month(context:, year:, start_date: Western::Calendar.new,
|
83
88
|
last_date: Western::Calendar.new)
|
84
89
|
months = year.months
|
85
90
|
|
@@ -95,7 +100,7 @@ module Zakuro
|
|
95
100
|
monthly_last_date = last_date.clone if last_date < monthly_last_date
|
96
101
|
|
97
102
|
specify_months.push(
|
98
|
-
Month.new(year: year, month: month,
|
103
|
+
Month.new(context: context, year: year, month: month,
|
99
104
|
start_date: monthly_start_date, last_date: monthly_last_date)
|
100
105
|
)
|
101
106
|
end
|
@@ -107,7 +112,7 @@ module Zakuro
|
|
107
112
|
#
|
108
113
|
# 月が範囲に含まれるか
|
109
114
|
#
|
110
|
-
# @param [Monthly::Month] month 月
|
115
|
+
# @param [Calculation::Monthly::Month] month 月
|
111
116
|
# @param [Western::Calendar] start_date 西暦開始日
|
112
117
|
# @param [Western::Calendar] last_date 西暦終了日
|
113
118
|
#
|
@@ -6,6 +6,9 @@ require_relative '../../../../output/logger'
|
|
6
6
|
|
7
7
|
require_relative '../../../base/year'
|
8
8
|
|
9
|
+
require_relative '../../internal/day'
|
10
|
+
require_relative '../../internal/option'
|
11
|
+
|
9
12
|
# :nodoc:
|
10
13
|
module Zakuro
|
11
14
|
# :nodoc:
|
@@ -26,20 +29,20 @@ module Zakuro
|
|
26
29
|
#
|
27
30
|
# 取得する
|
28
31
|
#
|
29
|
-
# @param [Array<Year>]
|
32
|
+
# @param [Array<Calculation::Base::Year>] years 範囲
|
30
33
|
# @param [Western::Calendar] date 西暦日
|
31
34
|
#
|
32
35
|
# @return [Result::Data::SingleDay] 和暦日
|
33
36
|
#
|
34
37
|
def self.get(years: [], date: Western::Calendar.new)
|
35
38
|
year, month = specify(years: years, date: date)
|
36
|
-
first_date = month.western_date
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
day = Day.get(month: month, date: date)
|
41
|
+
|
42
|
+
options = Option.create(month: month, day: day)
|
43
|
+
|
44
|
+
Output::Response::SingleDay.create(
|
45
|
+
year: year, month: month, day: day, options: options
|
43
46
|
)
|
44
47
|
end
|
45
48
|
|
@@ -52,6 +55,8 @@ module Zakuro
|
|
52
55
|
# @return [Base::Year] 対象年
|
53
56
|
# @return [Monthly::Month] 対象月
|
54
57
|
#
|
58
|
+
# @raise [ArgumentError] 引数エラー
|
59
|
+
#
|
55
60
|
def self.specify(years:, date:)
|
56
61
|
years.each do |year|
|
57
62
|
month = specify_month(year: year, date: date)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Zakuro
|
5
|
+
# :nodoc:
|
6
|
+
module Calculation
|
7
|
+
# :nodoc:
|
8
|
+
module Type
|
9
|
+
#
|
10
|
+
# Optional 参照管理
|
11
|
+
#
|
12
|
+
# * インスタンスのnil操作を避ける
|
13
|
+
# * safe navigation operator を使用しない
|
14
|
+
#
|
15
|
+
class Optional
|
16
|
+
#
|
17
|
+
# 初期化
|
18
|
+
#
|
19
|
+
# @param [Object] obj インスタンス
|
20
|
+
#
|
21
|
+
def initialize(obj: nil)
|
22
|
+
@obj = obj
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# インスタンスを取得する
|
27
|
+
#
|
28
|
+
# @return [Object] インスタンス
|
29
|
+
#
|
30
|
+
def get
|
31
|
+
@obj
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# 不正か
|
36
|
+
#
|
37
|
+
# @return [True] 不正
|
38
|
+
# @return [False] 不正なし
|
39
|
+
#
|
40
|
+
def invalid?
|
41
|
+
@obj.nil?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
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:
|
@@ -29,7 +31,7 @@ module Zakuro
|
|
29
31
|
#
|
30
32
|
# @param [Date] date 日付
|
31
33
|
#
|
32
|
-
# @return [Array<
|
34
|
+
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
33
35
|
#
|
34
36
|
def self.validate(date:)
|
35
37
|
failed = []
|
@@ -37,7 +39,12 @@ module Zakuro
|
|
37
39
|
|
38
40
|
return failed if date.is_a?(Date) || date.is_a?(String)
|
39
41
|
|
40
|
-
failed.push(
|
42
|
+
failed.push(
|
43
|
+
Exception::Case::Preset.new(
|
44
|
+
date.class,
|
45
|
+
template: Exception::Case::Pattern::INVALID_DATE_TYPE
|
46
|
+
)
|
47
|
+
)
|
41
48
|
failed
|
42
49
|
end
|
43
50
|
end
|
@@ -54,7 +61,7 @@ module Zakuro
|
|
54
61
|
#
|
55
62
|
# 初期化
|
56
63
|
#
|
57
|
-
# @param [Hash<Symbol>] hash パラメータ
|
64
|
+
# @param [Hash<Symbol, Object>] hash パラメータ
|
58
65
|
# @option hash [Symbol] :start 開始日
|
59
66
|
# @option hash [Symbol] :start 終了日
|
60
67
|
#
|
@@ -68,16 +75,21 @@ module Zakuro
|
|
68
75
|
#
|
69
76
|
# 検証する
|
70
77
|
#
|
71
|
-
# @param [Hash<Symbol>] hash パラメータ
|
78
|
+
# @param [Hash<Symbol, Object>] hash パラメータ
|
72
79
|
#
|
73
|
-
# @return [Array<
|
80
|
+
# @return [Array<Exception::Case::Preset>] エラープリセット
|
74
81
|
#
|
75
82
|
def self.validate(hash:)
|
76
83
|
failed = []
|
77
84
|
return failed unless hash
|
78
85
|
|
79
86
|
unless hash.is_a?(Hash)
|
80
|
-
failed.push(
|
87
|
+
failed.push(
|
88
|
+
Exception::Case::Preset.new(
|
89
|
+
hash.class,
|
90
|
+
template: Exception::Case::Pattern::INVALID_RANGE_TYPE
|
91
|
+
)
|
92
|
+
)
|
81
93
|
return failed
|
82
94
|
end
|
83
95
|
|
@@ -124,7 +136,7 @@ module Zakuro
|
|
124
136
|
#
|
125
137
|
# @param [Array<String>] columns 列
|
126
138
|
#
|
127
|
-
# @return [Array<
|
139
|
+
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
128
140
|
#
|
129
141
|
def self.validate(columns:)
|
130
142
|
# TODO: 列内容のバリデーション
|
@@ -134,7 +146,12 @@ module Zakuro
|
|
134
146
|
|
135
147
|
return failed if columns.is_a?(Array)
|
136
148
|
|
137
|
-
failed.push(
|
149
|
+
failed.push(
|
150
|
+
Exception::Case::Preset.new(
|
151
|
+
hash.class,
|
152
|
+
template: Exception::Case::Pattern::INVALID_COLUMN_TYPE
|
153
|
+
)
|
154
|
+
)
|
138
155
|
|
139
156
|
failed
|
140
157
|
end
|
@@ -144,8 +161,8 @@ module Zakuro
|
|
144
161
|
# Options オプション
|
145
162
|
# 取得内容を変更する
|
146
163
|
#
|
147
|
-
# *
|
148
|
-
# *
|
164
|
+
# * version: 暦
|
165
|
+
# * dropped_days: 没日あり
|
149
166
|
# * seasons: 四季あり
|
150
167
|
#
|
151
168
|
class Options
|
@@ -155,7 +172,7 @@ module Zakuro
|
|
155
172
|
#
|
156
173
|
# 初期化
|
157
174
|
#
|
158
|
-
# @param [
|
175
|
+
# @param [Hash<Symbol, Object>] options オプション
|
159
176
|
#
|
160
177
|
def initialize(options: [])
|
161
178
|
@options = options
|
@@ -166,9 +183,9 @@ module Zakuro
|
|
166
183
|
#
|
167
184
|
# 検証する
|
168
185
|
#
|
169
|
-
# @param [
|
186
|
+
# @param [Hash<Symbol, Object>] options オプション
|
170
187
|
#
|
171
|
-
# @return [Array<
|
188
|
+
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
172
189
|
#
|
173
190
|
def self.validate(options:)
|
174
191
|
failed = []
|
@@ -176,8 +193,12 @@ module Zakuro
|
|
176
193
|
|
177
194
|
return failed if options.is_a?(Hash)
|
178
195
|
|
179
|
-
failed.push(
|
180
|
-
|
196
|
+
failed.push(
|
197
|
+
Exception::Case::Preset.new(
|
198
|
+
hash.class,
|
199
|
+
template: Exception::Case::Pattern::INVALID_OPTION_TYPE
|
200
|
+
)
|
201
|
+
)
|
181
202
|
failed
|
182
203
|
end
|
183
204
|
end
|
@@ -193,7 +214,7 @@ module Zakuro
|
|
193
214
|
attr_reader :range
|
194
215
|
# @return [Array<String>] 列
|
195
216
|
attr_reader :columns
|
196
|
-
# @return [
|
217
|
+
# @return [Hash<String, Object>] オプション
|
197
218
|
attr_reader :options
|
198
219
|
|
199
220
|
#
|
@@ -203,13 +224,13 @@ module Zakuro
|
|
203
224
|
# @option hash [Date] :date 基準日
|
204
225
|
# @option hash [Hash<Symbol, Date>] :range 範囲
|
205
226
|
# @option hash [Array<String>] :columns 列
|
206
|
-
# @option hash [
|
227
|
+
# @option hash [Hash<String, Object>] :options オプション
|
207
228
|
#
|
208
229
|
def initialize(hash: {})
|
209
230
|
@date = hash[:date]
|
210
231
|
@range = hash[:range]
|
211
232
|
@columns = hash[:columns]
|
212
|
-
@options = hash[:options]
|
233
|
+
@options = hash[:options] || {}
|
213
234
|
end
|
214
235
|
|
215
236
|
# :reek:TooManyStatements { max_statements: 8 }
|
@@ -219,16 +240,35 @@ module Zakuro
|
|
219
240
|
#
|
220
241
|
# @param [Hash<Symbol, Object>] hash パラメータ
|
221
242
|
#
|
222
|
-
# @return [Array<
|
243
|
+
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
223
244
|
#
|
224
245
|
def self.validate(hash:)
|
225
246
|
failed = []
|
226
247
|
|
227
248
|
unless hash.is_a?(Hash)
|
228
|
-
failed.push(
|
249
|
+
failed.push(
|
250
|
+
Exception::Case::Preset.new(
|
251
|
+
hash.class,
|
252
|
+
template: Exception::Case::Pattern::INVALID_CONDITION_TYPE
|
253
|
+
)
|
254
|
+
)
|
229
255
|
return failed
|
230
256
|
end
|
231
257
|
|
258
|
+
failed.concat(validate_hash(hash: hash))
|
259
|
+
|
260
|
+
failed
|
261
|
+
end
|
262
|
+
|
263
|
+
#
|
264
|
+
# ハッシュ内を検証する
|
265
|
+
#
|
266
|
+
# @param [Hash<Symbol, Object>] hash パラメータ
|
267
|
+
#
|
268
|
+
# @return [Array<Exception::Case::Preset>] エラープリセット配列
|
269
|
+
#
|
270
|
+
def self.validate_hash(hash:)
|
271
|
+
failed = []
|
232
272
|
failed.concat(Catalog::BasisDate.validate(date: hash[:date]))
|
233
273
|
failed.concat(Catalog::Range.validate(hash: hash[:range]))
|
234
274
|
failed.concat(Catalog::Columns.validate(columns: hash[:columns]))
|
@@ -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,117 @@
|
|
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
|
+
#
|
86
|
+
# 暦名を返す
|
87
|
+
#
|
88
|
+
# @param [String] version 暦名
|
89
|
+
#
|
90
|
+
# @return [String] 暦名
|
91
|
+
#
|
92
|
+
def self.version(version: INVALID_VERSION_NAME)
|
93
|
+
return INVALID_VERSION_NAME unless version
|
94
|
+
|
95
|
+
return INVALID_VERSION_NAME if version.empty?
|
96
|
+
|
97
|
+
return INVALID_VERSION_NAME unless VERSION_NAMES.include?(version)
|
98
|
+
|
99
|
+
version
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# 有効な暦か
|
104
|
+
#
|
105
|
+
# @param [String] version 暦名
|
106
|
+
#
|
107
|
+
# @return [True] 有効
|
108
|
+
# @return [False] 無効
|
109
|
+
#
|
110
|
+
def self.version?(version: INVALID_VERSION_NAME)
|
111
|
+
return false if version == INVALID_VERSION_NAME
|
112
|
+
|
113
|
+
true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,110 @@
|
|
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
|
+
# @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
|
+
#
|
72
|
+
# 大余小余(暦別)クラスを返す
|
73
|
+
#
|
74
|
+
# @return [Class] 大余小余(暦別)クラス
|
75
|
+
#
|
76
|
+
def remainder
|
77
|
+
VersionClassResolver.get_class(version_name: @version_name, class_name: 'remainder')
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# 二十四節気クラスを返す
|
82
|
+
#
|
83
|
+
# @return [Class] 二十四節気クラス
|
84
|
+
#
|
85
|
+
def solar_term
|
86
|
+
VersionClassResolver.get_class(version_name: @version_name, class_name: 'solar_term')
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# 年間範囲クラスを返す
|
91
|
+
#
|
92
|
+
# @return [Class] 年間範囲クラス
|
93
|
+
#
|
94
|
+
def annual_range
|
95
|
+
VersionClassResolver.get_class(version_name: @version_name, class_name: 'annual_range')
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# 没日引数を返す
|
100
|
+
#
|
101
|
+
# @return [Class] 没日引数クラス
|
102
|
+
#
|
103
|
+
def dropped_date_parameter
|
104
|
+
VersionClassResolver.get_class(
|
105
|
+
version_name: @version_name, class_name: 'dropped_date_parameter'
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|