zakuro 0.5.0 → 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 +22 -7
- data/VERSION +1 -0
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/gengou.rb +128 -0
- data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
- data/lib/zakuro/calculation/base/operated_year.rb +5 -15
- data/lib/zakuro/calculation/base/year.rb +26 -14
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
- 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 +41 -0
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
- data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
- data/lib/zakuro/calculation/era/version/version.rb +24 -0
- data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
- data/lib/zakuro/calculation/monthly/month.rb +88 -2
- data/lib/zakuro/calculation/monthly/operated_month.rb +3 -3
- data/lib/zakuro/calculation/range/abstract_full_range.rb +172 -0
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +17 -15
- 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 +36 -19
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
- data/lib/zakuro/calculation/summary/internal/month.rb +84 -0
- data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -37
- 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 +15 -2
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +121 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +243 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +293 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
- data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
- data/lib/zakuro/era/japan/gengou.rb +26 -80
- data/lib/zakuro/era/japan/version.rb +151 -0
- data/lib/zakuro/era/{western.rb → 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 +15 -4
- data/lib/zakuro/operation/month/parser.rb +10 -10
- data/lib/zakuro/operation/month/type.rb +32 -32
- data/lib/zakuro/operation/month/validator.rb +51 -51
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +5 -5
- 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 +21 -2
- data/lib/zakuro/tools/typeconv.rb +38 -0
- data/lib/zakuro/tools/typeof.rb +4 -1
- data/lib/zakuro/version/context.rb +24 -3
- data/lib/zakuro/version/daien/daien.rb +1 -26
- data/lib/zakuro/version/genka/genka.rb +1 -26
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
- data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
- data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
- data/lib/zakuro/version/kansei/kansei.rb +1 -9
- data/lib/zakuro/version/senmyou/README.md +11 -7
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/zakuro.gemspec +1 -3
- metadata +74 -22
- data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
- data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
- data/lib/zakuro/calculation/range/full_range.rb +0 -210
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -109
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
- data/lib/zakuro/era/japan/gengou/type.rb +0 -178
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
- data/lib/zakuro/era/japan/reki.rb +0 -91
- data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
- data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
- data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/result/operation.rb +0 -114
- data/lib/zakuro/version/abstract_version.rb +0 -29
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './abstract_scroll'
|
4
|
+
require_relative './internal/reserve/dated_range'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Gengou
|
12
|
+
# DatedScroll
|
13
|
+
#
|
14
|
+
# 元号スクロール
|
15
|
+
#
|
16
|
+
class DatedScroll < AbstractScroll
|
17
|
+
#
|
18
|
+
# 初期化
|
19
|
+
#
|
20
|
+
# @param [Western::Calendar] start_date 西暦開始日(最大範囲)
|
21
|
+
# @param [Western::Calendar] last_date 西暦終了日(最大範囲)
|
22
|
+
#
|
23
|
+
def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
24
|
+
range = Reserve::DatedRange.new(start_date: start_date, last_date: last_date)
|
25
|
+
super(range: range)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/japan/gengou/resource'
|
4
|
+
require_relative '../../../../era/japan/calendar'
|
5
|
+
require_relative '../../../../era/western/calendar'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Calculation
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
#
|
14
|
+
# Connector 元号接続器
|
15
|
+
#
|
16
|
+
# 現在は"明徳"のみを解決している
|
17
|
+
# 元中1年4月28日 元中9年閏10月4日 明徳5年7月4日
|
18
|
+
# 1384-05-18 1392-11-18 1394-8-1
|
19
|
+
# [1] |-------------元中---------------|---------明徳------------|
|
20
|
+
# [2] |---------明徳--------|
|
21
|
+
# 明徳1年3月26日
|
22
|
+
# 1390-04-12
|
23
|
+
#
|
24
|
+
# * 明徳は2行目元号から始まる
|
25
|
+
# * 1392-11-19より1行目元号に移行する
|
26
|
+
# * 移行のタイミングで元号年を引き継げるようにする
|
27
|
+
#
|
28
|
+
class Connector
|
29
|
+
# @return [Array<Counter>] 未解決元号
|
30
|
+
attr_reader :unsolved_list
|
31
|
+
|
32
|
+
#
|
33
|
+
# 初期化
|
34
|
+
#
|
35
|
+
def initialize
|
36
|
+
@unsolved_list = []
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# 元号を更新する
|
41
|
+
#
|
42
|
+
# @param [Array<Array<Counter>>] lines 全行元号
|
43
|
+
#
|
44
|
+
def update(lines: [])
|
45
|
+
lines.each do |line|
|
46
|
+
line.each_with_index do |gengou, index|
|
47
|
+
next unless gengou.changed?
|
48
|
+
|
49
|
+
line[index] = replace(gengou: gengou)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# 元号を年を更新した元号に入れ替える
|
56
|
+
#
|
57
|
+
# @param [Counter] gengou 元号
|
58
|
+
#
|
59
|
+
# @return [Counter] 元号/更新済元号
|
60
|
+
#
|
61
|
+
def replace(gengou:)
|
62
|
+
matched_index = -1
|
63
|
+
@unsolved_list.each_with_index do |unsolved, index|
|
64
|
+
next unless unsolved.name == gengou.name
|
65
|
+
|
66
|
+
matched_index = index
|
67
|
+
break
|
68
|
+
end
|
69
|
+
|
70
|
+
if matched_index == -1
|
71
|
+
@unsolved_list.push(gengou)
|
72
|
+
return gengou
|
73
|
+
end
|
74
|
+
|
75
|
+
matched = @unsolved_list[matched_index]
|
76
|
+
|
77
|
+
result = recreate(gengou: gengou, unsolved: matched)
|
78
|
+
|
79
|
+
@unsolved_list[matched_index] = result
|
80
|
+
|
81
|
+
# 分離した元号の末尾まで到達した
|
82
|
+
@unsolved_list.delete_at(matched_index) unless result.change_last_date?
|
83
|
+
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# 年を更新した元号を生成する
|
89
|
+
#
|
90
|
+
# @param [Counter] gengou 元号
|
91
|
+
# @param [Counter] unsolved 未解決元号
|
92
|
+
#
|
93
|
+
# @return [Counter] 更新済元号
|
94
|
+
#
|
95
|
+
def recreate(gengou:, unsolved:)
|
96
|
+
japan_year = gengou.japan_year
|
97
|
+
japan_year = unsolved.japan_year if unsolved.japan_year > gengou.japan_year
|
98
|
+
|
99
|
+
Counter.new(
|
100
|
+
gengou: gengou.gengou, start_date: gengou.start_date,
|
101
|
+
last_date: gengou.last_date, japan_year: japan_year
|
102
|
+
)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/japan/gengou/resource'
|
4
|
+
require_relative '../../../../era/japan/calendar'
|
5
|
+
require_relative '../../../../era/western/calendar'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Calculation
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
#
|
14
|
+
# Counter 加算元号
|
15
|
+
#
|
16
|
+
class Counter
|
17
|
+
# @return [Integer] 不正値
|
18
|
+
INVALID_YEAR = -1
|
19
|
+
|
20
|
+
# @return [Japan::Resource::Gengou] 元号
|
21
|
+
attr_reader :gengou
|
22
|
+
# @return [Integer] 元号年
|
23
|
+
attr_reader :japan_year
|
24
|
+
# @return [Integer] 西暦年
|
25
|
+
attr_reader :western_year
|
26
|
+
# @return [Western::Calendar] 西暦開始年
|
27
|
+
attr_reader :start_date
|
28
|
+
# @return [Western::Calendar] 西暦終了年
|
29
|
+
attr_reader :last_date
|
30
|
+
|
31
|
+
#
|
32
|
+
# 初期化
|
33
|
+
#
|
34
|
+
# @param [Japan::Resource::Gengou] gengou 元号
|
35
|
+
# @param [Western::Calendar] start_date 西暦開始年
|
36
|
+
# @param [Western::Calendar] last_date 西暦終了年
|
37
|
+
# @param [Integer] japan_year 和暦年
|
38
|
+
#
|
39
|
+
def initialize(gengou: Japan::Resource::Gengou.new,
|
40
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
41
|
+
japan_year: INVALID_YEAR)
|
42
|
+
@gengou = gengou
|
43
|
+
@japan_year = japan_year
|
44
|
+
@japan_year = gengou.both_start_year.japan if @japan_year == INVALID_YEAR
|
45
|
+
@western_year = gengou.both_start_year.western
|
46
|
+
|
47
|
+
@start_date = start_date.clone
|
48
|
+
@last_date = last_date.clone
|
49
|
+
|
50
|
+
select_valid_date
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# 和暦開始日を取得する
|
55
|
+
#
|
56
|
+
# @return [Japan::Calendar] 和暦開始日
|
57
|
+
#
|
58
|
+
def japan_start_date
|
59
|
+
return Japan::Calendar.new if @gengou.invalid?
|
60
|
+
|
61
|
+
@gengou.both_start_date.japan
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# 西暦開始日を取得する
|
66
|
+
#
|
67
|
+
# @return [Western::Calendar] 西暦開始日
|
68
|
+
#
|
69
|
+
def western_start_date
|
70
|
+
return Western::Calendar.new if @gengou.invalid?
|
71
|
+
|
72
|
+
@start_date
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# 西暦終了日を取得する
|
77
|
+
#
|
78
|
+
# @return [Western::Calendar] 西暦終了日
|
79
|
+
#
|
80
|
+
def western_last_date
|
81
|
+
return Western::Calendar.new if @gengou.invalid?
|
82
|
+
|
83
|
+
@last_date
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# 次年にする
|
88
|
+
#
|
89
|
+
# @return [MultiGengou] 自身
|
90
|
+
#
|
91
|
+
def next_year
|
92
|
+
@japan_year += 1
|
93
|
+
@western_year += 1
|
94
|
+
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# 元号名を取得する
|
100
|
+
#
|
101
|
+
# @return [String] 元号名
|
102
|
+
#
|
103
|
+
def name
|
104
|
+
return '' unless @gengou
|
105
|
+
|
106
|
+
@gengou.name
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# 不正か
|
111
|
+
#
|
112
|
+
# @return [True] 不正
|
113
|
+
# @return [False] 不正なし
|
114
|
+
#
|
115
|
+
def invalid?
|
116
|
+
@gengou.invalid? || @japan_year == INVALID_YEAR || @western_year == INVALID_YEAR
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# 指定した日が元号に含まれるか
|
121
|
+
#
|
122
|
+
# @param [Western::Calendar] date 日
|
123
|
+
#
|
124
|
+
# @return [True] 含まれる
|
125
|
+
# @return [False] 含まれない
|
126
|
+
#
|
127
|
+
def include?
|
128
|
+
@gengou.include?
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# 元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?
|
133
|
+
#
|
134
|
+
# @return [True] 存在する
|
135
|
+
# @return [False] 存在しない
|
136
|
+
#
|
137
|
+
def changed?
|
138
|
+
return true if change_start_date?
|
139
|
+
|
140
|
+
return true if change_last_date?
|
141
|
+
|
142
|
+
false
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# 開始日が設定された開始日と異なるか(行が変更されているか)
|
147
|
+
#
|
148
|
+
# @return [True] 異なる
|
149
|
+
# @return [False] 同一
|
150
|
+
#
|
151
|
+
def change_start_date?
|
152
|
+
return false if invalid?
|
153
|
+
|
154
|
+
@start_date != native_start_date
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# 終了日が設定された終了日と異なるか(行が変更されているか)
|
159
|
+
#
|
160
|
+
# @return [True] 異なる
|
161
|
+
# @return [False] 同一
|
162
|
+
#
|
163
|
+
def change_last_date?
|
164
|
+
return false if invalid?
|
165
|
+
|
166
|
+
@last_date != native_last_date
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# ディープコピー
|
171
|
+
#
|
172
|
+
# @param [MultiGengou] obj 自身
|
173
|
+
#
|
174
|
+
def initialize_copy(obj)
|
175
|
+
@gengou = obj.gengou.clone
|
176
|
+
@japan_year = obj.japan_year
|
177
|
+
@western_year = obj.western_year
|
178
|
+
@start_date = obj.start_date.clone
|
179
|
+
@last_date = obj.last_date.clone
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
#
|
185
|
+
# 有効な日付範囲を選択する
|
186
|
+
#
|
187
|
+
def select_valid_date
|
188
|
+
return if @gengou.invalid?
|
189
|
+
|
190
|
+
@start_date = @gengou.both_start_date.western.clone if @start_date.invalid?
|
191
|
+
@last_date = @gengou.last_date.clone if @last_date.invalid?
|
192
|
+
end
|
193
|
+
|
194
|
+
#
|
195
|
+
# 設定された元号の開始日を取得する
|
196
|
+
#
|
197
|
+
# @return [Western::Calendar]設定された元号の開始日
|
198
|
+
#
|
199
|
+
def native_start_date
|
200
|
+
@gengou.both_start_date.western
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# 設定された元号の終了日を取得する
|
205
|
+
#
|
206
|
+
# @return [Western::Calendar] 設定された元号の終了日
|
207
|
+
#
|
208
|
+
def native_last_date
|
209
|
+
@gengou.last_date
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/western/calendar'
|
4
|
+
require_relative '../../../base/linear_gengou'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Gengou
|
12
|
+
# Publisher
|
13
|
+
#
|
14
|
+
# 元号発行
|
15
|
+
#
|
16
|
+
module Publisher
|
17
|
+
#
|
18
|
+
# 発行する
|
19
|
+
#
|
20
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
21
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
22
|
+
# @param [Array<Counter>] first_gengou 1行目元号
|
23
|
+
# @param [Array<Counter>] second_gengou 2行目元号
|
24
|
+
#
|
25
|
+
# @return [Base::Gengou] 元号
|
26
|
+
#
|
27
|
+
def self.run(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
28
|
+
first_gengou: [], second_gengou: [])
|
29
|
+
|
30
|
+
Base::Gengou.new(
|
31
|
+
start_date: start_date,
|
32
|
+
last_date: last_date,
|
33
|
+
first_line: to_linear_gengou(
|
34
|
+
start_date: start_date, last_date: last_date, gengou_list: first_gengou
|
35
|
+
),
|
36
|
+
second_line: to_linear_gengou(
|
37
|
+
start_date: start_date, last_date: last_date, gengou_list: second_gengou
|
38
|
+
)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# 直列元号に変換する
|
44
|
+
#
|
45
|
+
# * 最初の元号:開始日~その元号の終了日
|
46
|
+
# * 中間の元号:その元号の開始日~その元号の終了日
|
47
|
+
# * 最後の元号:その元号の開始日~終了日
|
48
|
+
#
|
49
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
50
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
51
|
+
# @param [Array<Counter>] gengou_list 元号リスト
|
52
|
+
#
|
53
|
+
# @return [Array<Base::LinearGengou>] 元号リスト
|
54
|
+
#
|
55
|
+
def self.to_linear_gengou(start_date:, last_date:, gengou_list: [])
|
56
|
+
return [] if gengou_list.size.zero?
|
57
|
+
|
58
|
+
result = []
|
59
|
+
|
60
|
+
gengou_list.each do |gengou|
|
61
|
+
if gengou.invalid?
|
62
|
+
# 無効元号は無効のままにする
|
63
|
+
result.push(Base::LinearGengou.new)
|
64
|
+
next
|
65
|
+
end
|
66
|
+
|
67
|
+
linear_gengou = to_limited_linear_gengou(
|
68
|
+
start_date: start_date,
|
69
|
+
last_date: last_date,
|
70
|
+
gengou: gengou
|
71
|
+
)
|
72
|
+
result.push(linear_gengou)
|
73
|
+
end
|
74
|
+
|
75
|
+
result
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# 範囲を限定した直列元号に変換する
|
80
|
+
#
|
81
|
+
# * 開始日・終了日により範囲を狭める
|
82
|
+
#
|
83
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
84
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
85
|
+
# @param [Counter] gengou 加算元号
|
86
|
+
#
|
87
|
+
# @return [Base::LinearGengou] 元号
|
88
|
+
#
|
89
|
+
def self.to_limited_linear_gengou(start_date:, last_date:, gengou:)
|
90
|
+
gengou_start_date = gengou.western_start_date.clone
|
91
|
+
gengou_last_date = gengou.western_last_date.clone
|
92
|
+
|
93
|
+
gengou_start_date = start_date.clone if start_date > gengou_start_date
|
94
|
+
gengou_last_date = last_date.clone if last_date < gengou_last_date
|
95
|
+
|
96
|
+
Base::LinearGengou.new(
|
97
|
+
start_date: gengou_start_date, last_date: gengou_last_date,
|
98
|
+
name: gengou.name, year: gengou.japan_year
|
99
|
+
)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../../era/japan/gengou/resource'
|
4
|
+
require_relative '../../../../../era/japan/gengou'
|
5
|
+
require_relative '../../../../../era/japan/calendar'
|
6
|
+
require_relative '../../../../../era/western/calendar'
|
7
|
+
|
8
|
+
require_relative '../counter'
|
9
|
+
|
10
|
+
require_relative './empty_link'
|
11
|
+
|
12
|
+
# :nodoc:
|
13
|
+
module Zakuro
|
14
|
+
# :nodoc:
|
15
|
+
module Calculation
|
16
|
+
# :nodoc:
|
17
|
+
module Gengou
|
18
|
+
# :nodoc:
|
19
|
+
module Reserve
|
20
|
+
# AbstractList
|
21
|
+
#
|
22
|
+
# 抽象予約元号一覧
|
23
|
+
#
|
24
|
+
class AbstractList
|
25
|
+
# @return [Integer] 不正年
|
26
|
+
INVALID_YEAR = -1
|
27
|
+
# @return [Integer] 最大月日数
|
28
|
+
MAX_MONTH_DAYS = 30
|
29
|
+
|
30
|
+
# @return [Symbol] 行番号
|
31
|
+
attr_reader :index
|
32
|
+
# @return [Western::Calendar] 開始日
|
33
|
+
attr_reader :start_date
|
34
|
+
# @return [Western::Calendar] 終了日
|
35
|
+
attr_reader :last_date
|
36
|
+
# @return [Array<Japan::Alignment::LinearGengou>] 予約元号一覧
|
37
|
+
attr_reader :list
|
38
|
+
|
39
|
+
#
|
40
|
+
# 初期化
|
41
|
+
#
|
42
|
+
# @param [Integer] index n行目元号
|
43
|
+
# @param [Western::Calendar] start_date 開始日
|
44
|
+
# @param [Western::Calendar] last_date 終了日
|
45
|
+
#
|
46
|
+
def initialize(index:, start_date: Western::Calendar.new,
|
47
|
+
last_date: Western::Calendar)
|
48
|
+
@index = index
|
49
|
+
@start_date = start_date.clone
|
50
|
+
@last_date = last_date.clone
|
51
|
+
@list = []
|
52
|
+
|
53
|
+
update
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# 元号を取得する
|
58
|
+
#
|
59
|
+
# @param [Western::Calendar] western_date 西暦日
|
60
|
+
#
|
61
|
+
# @return [Gengou::Counter] 加算元号
|
62
|
+
#
|
63
|
+
def get(western_date: Western::Calendar.new)
|
64
|
+
@list.each do |linear_gengou|
|
65
|
+
next if linear_gengou.out?(start_date: western_date, last_date: western_date)
|
66
|
+
|
67
|
+
Gengou::Counter.new(gengou: linear_gengou.gengou).clone
|
68
|
+
end
|
69
|
+
|
70
|
+
Gengou::Counter.new
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# 範囲内元号を取得する
|
75
|
+
#
|
76
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
77
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
78
|
+
#
|
79
|
+
# @return [Array<Gengou::Counter>] 範囲内元号
|
80
|
+
#
|
81
|
+
def collect(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
82
|
+
result = []
|
83
|
+
|
84
|
+
@list.each do |linear_gengou|
|
85
|
+
next if linear_gengou.out?(start_date: start_date, last_date: last_date)
|
86
|
+
|
87
|
+
result.push(
|
88
|
+
Gengou::Counter.new(
|
89
|
+
gengou: linear_gengou.gengou.clone,
|
90
|
+
start_date: linear_gengou.start_date.clone,
|
91
|
+
last_date: linear_gengou.last_date.clone
|
92
|
+
)
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
EmptyLink.fill(counters: result, start_date: start_date, last_date: last_date)
|
97
|
+
|
98
|
+
result
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# 和暦開始日を取得する
|
103
|
+
#
|
104
|
+
# @return [Japan::Calendar] 和暦開始日
|
105
|
+
#
|
106
|
+
def japan_start_date
|
107
|
+
return Japan::Calendar.new if invalid?
|
108
|
+
|
109
|
+
@list[0].gengou.both_start_date.japan.clone
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# 西暦開始日を取得する
|
114
|
+
#
|
115
|
+
# @return [Western::Calendar] 西暦開始日
|
116
|
+
#
|
117
|
+
def western_start_date
|
118
|
+
return Western::Calendar.new if invalid?
|
119
|
+
|
120
|
+
@list[0].gengou.both_start_date.western.clone
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# 西暦終了日を取得する
|
125
|
+
#
|
126
|
+
# @return [Western::Calendar] 西暦開始日
|
127
|
+
#
|
128
|
+
def western_last_date
|
129
|
+
return Western::Calendar.new if invalid?
|
130
|
+
|
131
|
+
@list[-1].gengou.last_date.clone
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# 西暦開始年を取得する
|
136
|
+
#
|
137
|
+
# @return [Integer] 西暦開始年
|
138
|
+
#
|
139
|
+
def western_start_year
|
140
|
+
return INVALID_YEAR if invalid?
|
141
|
+
|
142
|
+
@list[0].gengou.both_start_year.western.clone
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# 西暦終了年を取得する
|
147
|
+
#
|
148
|
+
# @return [Integer] 西暦終了年
|
149
|
+
#
|
150
|
+
def western_last_year
|
151
|
+
return INVALID_YEAR if invalid?
|
152
|
+
|
153
|
+
return INVALID_YEAR if @list.size.zero?
|
154
|
+
|
155
|
+
@list[-1].gengou.last_year
|
156
|
+
end
|
157
|
+
|
158
|
+
#
|
159
|
+
# 不正か
|
160
|
+
#
|
161
|
+
# @return [True] 不正
|
162
|
+
# @return [False] 不正なし
|
163
|
+
#
|
164
|
+
def invalid?
|
165
|
+
return true unless @list
|
166
|
+
|
167
|
+
return true if @list.size.zero?
|
168
|
+
|
169
|
+
false
|
170
|
+
end
|
171
|
+
|
172
|
+
#
|
173
|
+
# 設定された元号の開始日を取得する
|
174
|
+
#
|
175
|
+
# @return [Western::Calendar]設定された元号の開始日
|
176
|
+
#
|
177
|
+
def native_start_date
|
178
|
+
return Western::Calendar.new if @list.size.zero?
|
179
|
+
|
180
|
+
@list[0].native_start_date
|
181
|
+
end
|
182
|
+
|
183
|
+
#
|
184
|
+
# 開始日が設定された開始日と異なるか(行が変更されているか)
|
185
|
+
#
|
186
|
+
# @return [True] 異なる
|
187
|
+
# @return [False] 同一
|
188
|
+
#
|
189
|
+
def change_start_date?
|
190
|
+
return false if @list.size.zero?
|
191
|
+
|
192
|
+
@list[0].change_start_date?
|
193
|
+
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
#
|
198
|
+
# 予約元号一覧を更新する
|
199
|
+
#
|
200
|
+
def update
|
201
|
+
# override
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# 元号を取得する
|
206
|
+
#
|
207
|
+
# @param [Western::Calendar] start_date 開始日
|
208
|
+
# @param [Western::Calendar] last_date 終了日
|
209
|
+
#
|
210
|
+
# @return [Array<Japan::Alignment::LinearGengou>] 元号
|
211
|
+
#
|
212
|
+
def line(start_date:, last_date:)
|
213
|
+
Japan::Gengou.line(line: @index, start_date: start_date, last_date: last_date)
|
214
|
+
end
|
215
|
+
|
216
|
+
#
|
217
|
+
# 行番号に変換する
|
218
|
+
#
|
219
|
+
# @param [True, False] first 1行目/2行目
|
220
|
+
#
|
221
|
+
# @return [<Integer] 行番号
|
222
|
+
#
|
223
|
+
def parse_index(first: true)
|
224
|
+
first ? Japan::Gengou::FIRST_LINE : Japan::Gengou::SECOND_LINE
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|