zakuro 0.6.1 → 0.7.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 +6 -4
- data/VERSION +1 -1
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/gengou.rb +46 -0
- data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +6 -8
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +37 -51
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +17 -17
- 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 +158 -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 +75 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +2 -3
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/monthly/month.rb +39 -0
- data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
- data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +5 -4
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +9 -11
- 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/named_full_range.rb +38 -0
- data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -2
- data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +1 -1
- data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -0
- data/lib/zakuro/calculation/summary/western/range.rb +124 -0
- data/lib/zakuro/calculation/summary/western/single.rb +113 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +169 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
- data/lib/zakuro/condition.rb +1 -2
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +89 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +125 -122
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +141 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +171 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +38 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +183 -182
- data/lib/zakuro/era/japan/gengou/resource/type.rb +233 -232
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +255 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +5 -20
- data/lib/zakuro/era/western/calendar.rb +9 -9
- data/lib/zakuro/exception/case/pattern.rb +35 -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 +37 -0
- data/lib/zakuro/exception/zakuro_error.rb +28 -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 +70 -0
- data/lib/zakuro/merchant.rb +8 -44
- data/lib/zakuro/operation/month/parser.rb +9 -9
- data/lib/zakuro/operation/month/type.rb +31 -31
- data/lib/zakuro/operation/month/validator.rb +49 -49
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- 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/single_day.rb +48 -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/bundle.rb +36 -0
- data/lib/zakuro/result/operation/month/history.rb +54 -0
- data/lib/zakuro/result/operation/operation.rb +44 -0
- data/lib/zakuro/result/result.rb +4 -2
- metadata +46 -14
- 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/result/operation.rb +0 -114
@@ -6,284 +6,285 @@ require_relative '../../calendar'
|
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
9
|
-
#
|
10
|
-
# Japan 和暦
|
11
|
-
#
|
9
|
+
# :nodoc:
|
12
10
|
module Japan
|
13
|
-
#
|
14
|
-
|
15
|
-
#
|
16
|
-
module Resource
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# Resource yaml解析結果
|
19
15
|
#
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
module Resource
|
17
|
+
#
|
18
|
+
# Gengou 元号情報
|
19
|
+
#
|
20
|
+
class Gengou
|
21
|
+
# @return [String] 元号名
|
22
|
+
attr_reader :name
|
23
|
+
# @return [Both::Year] 開始年(和暦/西暦)
|
24
|
+
attr_reader :both_start_year
|
25
|
+
# @return [Both::Date] 開始日(和暦/西暦)
|
26
|
+
attr_reader :both_start_date
|
27
|
+
# @return [Integer] 終了年
|
28
|
+
attr_reader :last_year
|
29
|
+
# @return [Western::Calendar] 終了日
|
30
|
+
attr_reader :last_date
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# 終了年を更新する
|
54
|
-
#
|
55
|
-
# @param [Integer] last_year 終了年
|
56
|
-
#
|
57
|
-
def write_last_year(last_year:)
|
58
|
-
unless Gengou.valid_year(year: last_year)
|
59
|
-
raise ArgumentError, "invalid year format. [#{last_year}]"
|
32
|
+
#
|
33
|
+
# 初期化
|
34
|
+
#
|
35
|
+
# @param [String] name 元号名
|
36
|
+
# @param [Both::Year] both_start_year 開始年(和暦/西暦)
|
37
|
+
# @param [Both::Date] both_start_date 開始日(和暦/西暦)
|
38
|
+
# @param [Integer] last_date 終了年
|
39
|
+
# @param [Western::Calendar] last_date 終了日
|
40
|
+
#
|
41
|
+
def initialize(name: '', both_start_year: Both::Year.new,
|
42
|
+
both_start_date: Both::Date.new,
|
43
|
+
last_date: Western::Calendar.new,
|
44
|
+
last_year: Both::Year::INVALID)
|
45
|
+
@name = name
|
46
|
+
@both_start_year = both_start_year
|
47
|
+
@both_start_date = both_start_date
|
48
|
+
@last_year = last_year
|
49
|
+
@last_date = last_date
|
60
50
|
end
|
61
51
|
|
62
|
-
|
63
|
-
|
52
|
+
#
|
53
|
+
# 終了年を更新する
|
54
|
+
#
|
55
|
+
# @param [Integer] last_year 終了年
|
56
|
+
#
|
57
|
+
def write_last_year(last_year:)
|
58
|
+
unless Gengou.valid_year(year: last_year)
|
59
|
+
raise ArgumentError, "invalid year format. [#{last_year}]"
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
# 終了日を更新する
|
67
|
-
#
|
68
|
-
# @param [Western::Calendar] last_date 終了日
|
69
|
-
#
|
70
|
-
def write_last_date(last_date:)
|
71
|
-
unless Gengou.valid_date(date: last_date)
|
72
|
-
raise ArgumentError, "invalid date format. [#{last_date}]"
|
62
|
+
@last_year = last_year
|
73
63
|
end
|
74
64
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
65
|
+
#
|
66
|
+
# 終了日を更新する
|
67
|
+
#
|
68
|
+
# @param [Western::Calendar] last_date 終了日
|
69
|
+
#
|
70
|
+
def write_last_date(last_date:)
|
71
|
+
unless Gengou.valid_date(date: last_date)
|
72
|
+
raise ArgumentError, "invalid date format. [#{last_date}]"
|
73
|
+
end
|
106
74
|
|
107
|
-
|
108
|
-
|
109
|
-
#
|
110
|
-
# @param [Integer] next_start_year 次回開始年
|
111
|
-
#
|
112
|
-
def convert_next_start_year_to_last_year(next_start_year:)
|
113
|
-
if @both_start_year.western >= next_start_year
|
114
|
-
@last_year = next_start_year
|
115
|
-
return
|
75
|
+
@last_date = last_date
|
76
|
+
nil
|
116
77
|
end
|
117
78
|
|
118
|
-
|
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
|
119
89
|
|
120
|
-
|
121
|
-
|
90
|
+
year.is_a?(Integer)
|
91
|
+
end
|
122
92
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
130
103
|
|
131
|
-
|
132
|
-
|
104
|
+
date.is_a?(Western::Calendar)
|
105
|
+
end
|
133
106
|
|
134
|
-
|
135
|
-
|
107
|
+
#
|
108
|
+
# 次の元号の開始年から、元号の終了年に変換する
|
109
|
+
#
|
110
|
+
# @param [Integer] next_start_year 次回開始年
|
111
|
+
#
|
112
|
+
def convert_next_start_year_to_last_year(next_start_year:)
|
113
|
+
if @both_start_year.western >= next_start_year
|
114
|
+
@last_year = next_start_year
|
115
|
+
return
|
116
|
+
end
|
136
117
|
|
137
|
-
|
138
|
-
# 指定した日が元号に含まれるか
|
139
|
-
#
|
140
|
-
# @param [Western::Calendar] date 日
|
141
|
-
#
|
142
|
-
# @return [True] 含まれる
|
143
|
-
# @return [False] 含まれない
|
144
|
-
#
|
145
|
-
def include?(date:)
|
146
|
-
date >= @both_start_date.western && date <= @last_date
|
147
|
-
end
|
118
|
+
@last_year = next_start_year - 1
|
148
119
|
|
149
|
-
|
150
|
-
|
151
|
-
#
|
152
|
-
# @return [True] 不正
|
153
|
-
# @return [False] 不正なし
|
154
|
-
#
|
155
|
-
def invalid?
|
156
|
-
@both_start_year.japan == -1 || @both_start_year.invalid? ||
|
157
|
-
@both_start_date.invalid? || @last_date.invalid?
|
158
|
-
end
|
120
|
+
nil
|
121
|
+
end
|
159
122
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
def to_s
|
169
|
-
"name: #{@name}, both_start_year: #{@both_start_year.format}, " \
|
170
|
-
"both_start_date: #{@both_start_date.format}, last_date: #{@last_date.format}"
|
171
|
-
end
|
172
|
-
end
|
123
|
+
#
|
124
|
+
# 次の元号の開始日から、元号の終了日に変換する
|
125
|
+
#
|
126
|
+
# @param [String] next_start_date 次回開始日
|
127
|
+
#
|
128
|
+
def convert_next_start_date_to_last_date(next_start_date: '')
|
129
|
+
raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
|
173
130
|
|
174
|
-
|
175
|
-
|
176
|
-
#
|
177
|
-
class Set
|
178
|
-
# @return [Integer] 不正値
|
179
|
-
INVALID = -1
|
180
|
-
# @return [Integer] 元号セットID
|
181
|
-
attr_reader :id
|
182
|
-
# @return [String] 元号セット名
|
183
|
-
attr_reader :name
|
184
|
-
# @return [Both::Date] 元号セットでの終了年
|
185
|
-
attr_reader :both_last_year
|
186
|
-
# @return [Both::Date] 元号セットでの終了日
|
187
|
-
attr_reader :both_last_date
|
188
|
-
# @return [Array<Gengou>] 元号リスト
|
189
|
-
attr_reader :list
|
131
|
+
start_date = Western::Calendar.parse(text: next_start_date)
|
132
|
+
@last_date = start_date - 1
|
190
133
|
|
191
|
-
|
192
|
-
|
193
|
-
#
|
194
|
-
# @param [Integer] id 元号セットID
|
195
|
-
# @param [String] name 元号セット名
|
196
|
-
# @param [Western::Calendar] last_date 元号セットでの終了日
|
197
|
-
# @param [Array<Gengou>] list 元号リスト
|
198
|
-
#
|
199
|
-
def initialize(id: INVALID, name: '', both_last_year: Both::Year.new,
|
200
|
-
both_last_date: Both::Date.new, list: [])
|
201
|
-
@id = id
|
202
|
-
@name = name
|
203
|
-
@both_last_year = both_last_year
|
204
|
-
@both_last_date = both_last_date
|
205
|
-
@list = list
|
206
|
-
end
|
134
|
+
nil
|
135
|
+
end
|
207
136
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
137
|
+
#
|
138
|
+
# 指定した日が元号に含まれるか
|
139
|
+
#
|
140
|
+
# @param [Western::Calendar] date 日
|
141
|
+
#
|
142
|
+
# @return [True] 含まれる
|
143
|
+
# @return [False] 含まれない
|
144
|
+
#
|
145
|
+
def include?(date:)
|
146
|
+
date >= @both_start_date.western && date <= @last_date
|
218
147
|
end
|
219
148
|
|
220
|
-
|
221
|
-
|
149
|
+
#
|
150
|
+
# 不正か
|
151
|
+
#
|
152
|
+
# @return [True] 不正
|
153
|
+
# @return [False] 不正なし
|
154
|
+
#
|
155
|
+
def invalid?
|
156
|
+
@both_start_year.japan == -1 || @both_start_year.invalid? ||
|
157
|
+
@both_start_date.invalid? || @last_date.invalid?
|
158
|
+
end
|
222
159
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
160
|
+
#
|
161
|
+
# 1元号年を追加する
|
162
|
+
#
|
163
|
+
# def next_year
|
164
|
+
# @year += 1 unless invalid?
|
165
|
+
# nil
|
166
|
+
# end
|
167
|
+
|
168
|
+
def to_s
|
169
|
+
"name: #{@name}, both_start_year: #{@both_start_year.format}, " \
|
170
|
+
"both_start_date: #{@both_start_date.format}, last_date: #{@last_date.format}"
|
171
|
+
end
|
231
172
|
end
|
232
|
-
end
|
233
173
|
|
234
|
-
#
|
235
|
-
# 和暦/西暦
|
236
|
-
#
|
237
|
-
module Both
|
238
174
|
#
|
239
|
-
#
|
175
|
+
# Set 元号セット
|
240
176
|
#
|
241
|
-
class
|
177
|
+
class Set
|
242
178
|
# @return [Integer] 不正値
|
243
179
|
INVALID = -1
|
244
|
-
# @return [Integer]
|
245
|
-
attr_reader :
|
246
|
-
# @return [
|
247
|
-
attr_reader :
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
180
|
+
# @return [Integer] 元号セットID
|
181
|
+
attr_reader :id
|
182
|
+
# @return [String] 元号セット名
|
183
|
+
attr_reader :name
|
184
|
+
# @return [Both::Date] 元号セットでの終了年
|
185
|
+
attr_reader :both_last_year
|
186
|
+
# @return [Both::Date] 元号セットでの終了日
|
187
|
+
attr_reader :both_last_date
|
188
|
+
# @return [Array<Gengou>] 元号リスト
|
189
|
+
attr_reader :list
|
190
|
+
|
191
|
+
#
|
192
|
+
# 初期化
|
193
|
+
#
|
194
|
+
# @param [Integer] id 元号セットID
|
195
|
+
# @param [String] name 元号セット名
|
196
|
+
# @param [Western::Calendar] last_date 元号セットでの終了日
|
197
|
+
# @param [Array<Gengou>] list 元号リスト
|
198
|
+
#
|
199
|
+
def initialize(id: INVALID, name: '', both_last_year: Both::Year.new,
|
200
|
+
both_last_date: Both::Date.new, list: [])
|
201
|
+
@id = id
|
202
|
+
@name = name
|
203
|
+
@both_last_year = both_last_year
|
204
|
+
@both_last_date = both_last_date
|
205
|
+
@list = list
|
252
206
|
end
|
253
207
|
|
254
208
|
#
|
255
|
-
#
|
209
|
+
# 指定した日付を含む元号を返す
|
256
210
|
#
|
257
|
-
# @
|
258
|
-
#
|
211
|
+
# @param [Western::Calendar] date 日
|
212
|
+
#
|
213
|
+
# @return [Gengou] 元号
|
214
|
+
#
|
215
|
+
def include_item(date:)
|
216
|
+
@list.each do |item|
|
217
|
+
return item if item.include?(date: date)
|
218
|
+
end
|
219
|
+
|
220
|
+
Gengou.new
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# 元号セットが不正かどうかを確認する
|
225
|
+
#
|
226
|
+
# @return [True] 正しくない
|
227
|
+
# @return [False] 正しい
|
259
228
|
#
|
260
229
|
def invalid?
|
261
|
-
@
|
230
|
+
@id == INVALID
|
262
231
|
end
|
263
232
|
end
|
264
233
|
|
265
234
|
#
|
266
|
-
#
|
235
|
+
# 和暦/西暦
|
267
236
|
#
|
268
|
-
|
269
|
-
#
|
270
|
-
|
271
|
-
#
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
@
|
276
|
-
|
237
|
+
module Both
|
238
|
+
#
|
239
|
+
# Year 年
|
240
|
+
#
|
241
|
+
class Year
|
242
|
+
# @return [Integer] 不正値
|
243
|
+
INVALID = -1
|
244
|
+
# @return [Integer] 和暦元号年
|
245
|
+
attr_reader :japan
|
246
|
+
# @return [Integer] 西暦年
|
247
|
+
attr_reader :western
|
248
|
+
|
249
|
+
def initialize(japan: INVALID, western: INVALID)
|
250
|
+
@japan = japan
|
251
|
+
@western = western
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# 不正か
|
256
|
+
#
|
257
|
+
# @return [True] 不正
|
258
|
+
# @return [False] 不正なし
|
259
|
+
#
|
260
|
+
def invalid?
|
261
|
+
@japan == INVALID || @western == INVALID
|
262
|
+
end
|
277
263
|
end
|
278
264
|
|
279
265
|
#
|
280
|
-
#
|
281
|
-
#
|
282
|
-
# @return [True] 不正
|
283
|
-
# @return [False] 不正なし
|
266
|
+
# Date 日
|
284
267
|
#
|
285
|
-
|
286
|
-
@
|
268
|
+
class Date
|
269
|
+
# @return [Japan::Calendar] 和暦日
|
270
|
+
attr_reader :japan
|
271
|
+
# @return [Western::Calendar] 西暦日
|
272
|
+
attr_reader :western
|
273
|
+
|
274
|
+
def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
|
275
|
+
@japan = japan
|
276
|
+
@western = western
|
277
|
+
end
|
278
|
+
|
279
|
+
#
|
280
|
+
# 不正か
|
281
|
+
#
|
282
|
+
# @return [True] 不正
|
283
|
+
# @return [False] 不正なし
|
284
|
+
#
|
285
|
+
def invalid?
|
286
|
+
@japan.invalid? || @western.invalid?
|
287
|
+
end
|
287
288
|
end
|
288
289
|
end
|
289
290
|
end
|