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,193 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../../era/western/calendar'
|
4
|
+
|
5
|
+
require_relative './dated_list'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Calculation
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
# :nodoc:
|
14
|
+
module Reserve
|
15
|
+
#
|
16
|
+
# AbstractRange 予約済み計算範囲
|
17
|
+
#
|
18
|
+
class AbstractRange
|
19
|
+
# @return [List] 1行目元号
|
20
|
+
attr_reader :first_list
|
21
|
+
# @return [List] 2行目元号
|
22
|
+
attr_reader :second_list
|
23
|
+
|
24
|
+
#
|
25
|
+
# 初期化
|
26
|
+
#
|
27
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
28
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
29
|
+
#
|
30
|
+
def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
31
|
+
last_date = start_date.clone if last_date.invalid?
|
32
|
+
|
33
|
+
@first_list = DatedList.new(first: true, start_date: start_date, last_date: last_date)
|
34
|
+
@second_list = DatedList.new(first: false, start_date: start_date, last_date: last_date)
|
35
|
+
|
36
|
+
renew(last_date: last_date)
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# 再初期化
|
41
|
+
# 含まれる最初の元号が別の行にまたがっている場合に開始日を前倒しする
|
42
|
+
#
|
43
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
44
|
+
#
|
45
|
+
def renew(last_date: Western::Calendar.new)
|
46
|
+
native_start_date = Western::Calendar.new
|
47
|
+
[@first_list, @second_list].each do |list|
|
48
|
+
next unless list.change_start_date?
|
49
|
+
|
50
|
+
if native_start_date.invalid?
|
51
|
+
native_start_date = list.native_start_date.clone
|
52
|
+
next
|
53
|
+
end
|
54
|
+
|
55
|
+
next if native_start_date <= list.native_start_date
|
56
|
+
|
57
|
+
native_start_date = list.native_start_date.clone
|
58
|
+
end
|
59
|
+
|
60
|
+
return if native_start_date.invalid?
|
61
|
+
|
62
|
+
@first_list = DatedList.new(first: true, start_date: native_start_date,
|
63
|
+
last_date: last_date)
|
64
|
+
@second_list = DatedList.new(first: false, start_date: native_start_date,
|
65
|
+
last_date: last_date)
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# 不正か
|
70
|
+
#
|
71
|
+
# @return [True] 不正
|
72
|
+
# @return [False] 不正なし
|
73
|
+
#
|
74
|
+
def invalid?
|
75
|
+
@first_list.invalid?
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# 範囲内元号(1行目元号)を取得する
|
80
|
+
#
|
81
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
82
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
83
|
+
#
|
84
|
+
# @return [Array<Gengou::Counter>] 範囲内元号(1行目元号)
|
85
|
+
#
|
86
|
+
def collect_first(start_date: Western::Calendar.new,
|
87
|
+
last_date: Western::Calendar.new)
|
88
|
+
@first_list.collect(start_date: start_date, last_date: last_date)
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# 範囲内元号(2行目元号)を取得する
|
93
|
+
#
|
94
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
95
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
96
|
+
#
|
97
|
+
# @return [Array<Gengou::Counter>] 範囲内元号(2行目元号)
|
98
|
+
#
|
99
|
+
def collect_second(start_date: Western::Calendar.new,
|
100
|
+
last_date: Western::Calendar.new)
|
101
|
+
@second_list.collect(start_date: start_date, last_date: last_date)
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# 最古の元号から和暦開始日を取得する
|
106
|
+
#
|
107
|
+
# @return [Japan::Calendar] 和暦開始日
|
108
|
+
#
|
109
|
+
def japan_start_date
|
110
|
+
list = oldest_list
|
111
|
+
|
112
|
+
return Japan::Calendar.new if list.invalid?
|
113
|
+
|
114
|
+
list.japan_start_date
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# 最古の元号から西暦開始日を取得する
|
119
|
+
#
|
120
|
+
# @return [Western::Calendar] 西暦開始日
|
121
|
+
#
|
122
|
+
def western_start_date
|
123
|
+
list = oldest_list
|
124
|
+
|
125
|
+
return Western::Calendar.new if list.invalid?
|
126
|
+
|
127
|
+
list.western_start_date
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# 開始西暦年を取得する
|
132
|
+
#
|
133
|
+
# @return [Integer] 開始西暦年
|
134
|
+
#
|
135
|
+
def western_start_year
|
136
|
+
first_start_year = @first_list.western_start_year
|
137
|
+
second_start_year = @second_list.western_start_year
|
138
|
+
|
139
|
+
return first_start_year if @first_list.invalid?
|
140
|
+
|
141
|
+
return first_start_year if @second_list.invalid?
|
142
|
+
|
143
|
+
return first_start_year if first_start_year < second_start_year
|
144
|
+
|
145
|
+
second_start_year
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# 終了西暦年を取得する
|
150
|
+
#
|
151
|
+
# @return [Integer] 終了西暦年
|
152
|
+
#
|
153
|
+
def western_last_year
|
154
|
+
first_last_year = @first_list.western_last_year
|
155
|
+
second_last_year = @second_list.western_last_year
|
156
|
+
|
157
|
+
return first_last_year if @first_list.invalid?
|
158
|
+
|
159
|
+
return first_last_year if @second_list.invalid?
|
160
|
+
|
161
|
+
return first_last_year if first_last_year > second_last_year
|
162
|
+
|
163
|
+
second_last_year
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
#
|
169
|
+
# 最古の元号を取得する
|
170
|
+
#
|
171
|
+
# @return [List] 最古の元号
|
172
|
+
#
|
173
|
+
def oldest_list
|
174
|
+
return @first_list if @first_list.invalid?
|
175
|
+
|
176
|
+
return @first_list if @second_list.invalid?
|
177
|
+
|
178
|
+
first_western_date = @first_list.western_start_date
|
179
|
+
second_western_date = @second_list.western_start_date
|
180
|
+
|
181
|
+
return @first_list if first_western_date.invalid?
|
182
|
+
|
183
|
+
return @first_list if second_western_date.invalid?
|
184
|
+
|
185
|
+
return @first_list if first_western_date < second_western_date
|
186
|
+
|
187
|
+
@second_list
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './abstract_list'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Calculation
|
9
|
+
# :nodoc:
|
10
|
+
module Gengou
|
11
|
+
# :nodoc:
|
12
|
+
module Reserve
|
13
|
+
# List
|
14
|
+
#
|
15
|
+
# 予約元号一覧
|
16
|
+
#
|
17
|
+
class DatedList < AbstractList
|
18
|
+
#
|
19
|
+
# 初期化
|
20
|
+
#
|
21
|
+
# @param [True, False] first true:1行目元号, false:2行目元号
|
22
|
+
# @param [Western::Calendar] start_date 開始日
|
23
|
+
# @param [Western::Calendar] last_date 終了日
|
24
|
+
#
|
25
|
+
def initialize(first: true, start_date: Western::Calendar.new,
|
26
|
+
last_date: Western::Calendar)
|
27
|
+
@index = parse_index(first: first)
|
28
|
+
@start_date = start_date.clone
|
29
|
+
@last_date = last_date.invalid? ? start_date.clone : last_date.clone
|
30
|
+
super(index: @index, start_date: start_date, last_date: last_date)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# 予約元号一覧を更新する
|
35
|
+
#
|
36
|
+
def update
|
37
|
+
# 開始日の30日前に前の元号がある場合は、前の元号を設定する
|
38
|
+
start_date = @start_date.clone - (MAX_MONTH_DAYS + 1)
|
39
|
+
# 開始日の30日後に次の元号がある場合は、次の元号を設定する
|
40
|
+
last_date = @last_date.clone + (MAX_MONTH_DAYS + 1)
|
41
|
+
|
42
|
+
@list |= line(start_date: start_date, last_date: last_date)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './abstract_range'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Calculation
|
9
|
+
# :nodoc:
|
10
|
+
module Gengou
|
11
|
+
# :nodoc:
|
12
|
+
module Reserve
|
13
|
+
#
|
14
|
+
# DatedRange 予約済み計算範囲
|
15
|
+
#
|
16
|
+
class DatedRange < AbstractRange
|
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
|
+
super(start_date: start_date, last_date: last_date)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,158 @@
|
|
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
|
+
# :nodoc:
|
11
|
+
module Zakuro
|
12
|
+
# :nodoc:
|
13
|
+
module Calculation
|
14
|
+
# :nodoc:
|
15
|
+
module Gengou
|
16
|
+
# :nodoc:
|
17
|
+
module Reserve
|
18
|
+
# EmptyLink
|
19
|
+
#
|
20
|
+
# 空元号連結
|
21
|
+
#
|
22
|
+
# * 開始日と終了日の間は常に元号で満たす必要がある
|
23
|
+
# * もし元号が存在しない期間があれば、空の元号を生成する
|
24
|
+
#
|
25
|
+
module EmptyLink
|
26
|
+
#
|
27
|
+
# 空元号で満たす
|
28
|
+
#
|
29
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
30
|
+
# @param [Western::Calendar] start_date 開始日
|
31
|
+
# @param [Western::Calendar] last_date 終了日
|
32
|
+
#
|
33
|
+
def self.fill(counters:, start_date: Western::Calendar.new,
|
34
|
+
last_date: Western::Calendar.new)
|
35
|
+
if counters.size.zero?
|
36
|
+
counters.push(
|
37
|
+
create_empty_counter(
|
38
|
+
start_date: start_date.clone,
|
39
|
+
last_date: last_date.clone
|
40
|
+
)
|
41
|
+
)
|
42
|
+
return counters
|
43
|
+
end
|
44
|
+
|
45
|
+
fill_both_ends(counters: counters, start_date: start_date, last_date: last_date)
|
46
|
+
|
47
|
+
fill_middle(counters: counters)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# リストの両端を空元号で満たす
|
52
|
+
#
|
53
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
54
|
+
# @param [Western::Calendar] start_date 開始日
|
55
|
+
# @param [Western::Calendar] last_date 終了日
|
56
|
+
#
|
57
|
+
def self.fill_both_ends(counters:, start_date: Western::Calendar.new,
|
58
|
+
last_date: Western::Calendar.new)
|
59
|
+
fill_by_start(counters: counters, start_date: start_date)
|
60
|
+
|
61
|
+
fill_by_last(counters: counters, last_date: last_date)
|
62
|
+
end
|
63
|
+
private_class_method :fill_both_ends
|
64
|
+
|
65
|
+
#
|
66
|
+
# 先頭要素の手前を空元号で満たす
|
67
|
+
#
|
68
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
69
|
+
# @param [Western::Calendar] start_date 開始日
|
70
|
+
#
|
71
|
+
def self.fill_by_start(counters:, start_date:)
|
72
|
+
return unless start_date < counters[0].start_date
|
73
|
+
|
74
|
+
counters.unshift(
|
75
|
+
create_empty_counter(
|
76
|
+
start_date: start_date.clone,
|
77
|
+
last_date: counters[0].start_date.clone - 1
|
78
|
+
)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
private_class_method :fill_by_start
|
82
|
+
|
83
|
+
#
|
84
|
+
# 最終要素の手前を空元号で満たす
|
85
|
+
#
|
86
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
87
|
+
# @param [Western::Calendar] last_date 終了日
|
88
|
+
#
|
89
|
+
def self.fill_by_last(counters:, last_date:)
|
90
|
+
return unless last_date > counters[-1].last_date
|
91
|
+
|
92
|
+
counters.push(
|
93
|
+
create_empty_counter(
|
94
|
+
start_date: counters[-1].last_date.clone + 1,
|
95
|
+
last_date: last_date.clone
|
96
|
+
)
|
97
|
+
)
|
98
|
+
end
|
99
|
+
private_class_method :fill_by_last
|
100
|
+
|
101
|
+
#
|
102
|
+
# 元号間を空元号で満たす
|
103
|
+
#
|
104
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
105
|
+
#
|
106
|
+
def self.fill_middle(counters:)
|
107
|
+
return if counters.size.zero?
|
108
|
+
|
109
|
+
size = counters.size - 1
|
110
|
+
(0..size).reverse_each do |index|
|
111
|
+
break if index <= 0
|
112
|
+
|
113
|
+
insert(counters: counters, index: index)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
private_class_method :fill_middle
|
117
|
+
|
118
|
+
#
|
119
|
+
# 対象要素に空元号を追加する
|
120
|
+
#
|
121
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
122
|
+
# @param [Integer] index 要素番号
|
123
|
+
#
|
124
|
+
def self.insert(counters:, index:)
|
125
|
+
before_last_date = counters[index - 1].last_date.clone
|
126
|
+
current_start_date = counters[index].start_date.clone
|
127
|
+
|
128
|
+
return if (before_last_date.clone + 1) == current_start_date
|
129
|
+
|
130
|
+
counters.insert(
|
131
|
+
index,
|
132
|
+
create_empty_counter(
|
133
|
+
start_date: before_last_date + 1, last_date: current_start_date - 1
|
134
|
+
)
|
135
|
+
)
|
136
|
+
end
|
137
|
+
private_class_method :insert
|
138
|
+
|
139
|
+
#
|
140
|
+
# 空元号を生成する
|
141
|
+
#
|
142
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
143
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
144
|
+
#
|
145
|
+
# @return [Gengou::Counter] 加算元号(空元号)
|
146
|
+
#
|
147
|
+
def self.create_empty_counter(start_date:, last_date:)
|
148
|
+
Gengou::Counter.new(
|
149
|
+
gengou: Japan::Gengou::Resource::Gengou.new,
|
150
|
+
start_date: start_date, last_date: last_date
|
151
|
+
)
|
152
|
+
end
|
153
|
+
private_class_method :create_empty_counter
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './abstract_list'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Calculation
|
9
|
+
# :nodoc:
|
10
|
+
module Gengou
|
11
|
+
# :nodoc:
|
12
|
+
module Reserve
|
13
|
+
# NamedList
|
14
|
+
#
|
15
|
+
# 予約元号一覧(元号名)
|
16
|
+
#
|
17
|
+
class NamedList < AbstractList
|
18
|
+
# @return [String] 不正元号名
|
19
|
+
INVALID_NAME = Japan::Calendar::EMPTY
|
20
|
+
|
21
|
+
#
|
22
|
+
# 初期化
|
23
|
+
#
|
24
|
+
# @param [True, False] first true:1行目元号, false:2行目元号
|
25
|
+
# @param [String] start_name 開始元号名
|
26
|
+
# @param [String] last_name 終了元号名
|
27
|
+
#
|
28
|
+
def initialize(first: true, start_name: INVALID_NAME, last_name: INVALID_NAME)
|
29
|
+
@index = parse_index(first: first)
|
30
|
+
@start_date = Western::Calendar.new
|
31
|
+
@last_date = Western::Calendar.new
|
32
|
+
|
33
|
+
locate(start_name: start_name, last_name: last_name)
|
34
|
+
super(index: @index, start_date: @start_date, last_date: @last_date)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
#
|
40
|
+
# 開始日・終了日を配置する
|
41
|
+
#
|
42
|
+
# @param [String] start_name 開始元号名
|
43
|
+
# @param [String] last_name 終了元号名
|
44
|
+
#
|
45
|
+
def locate(start_name:, last_name:)
|
46
|
+
start = start_name
|
47
|
+
last = last_name
|
48
|
+
last = start if last == INVALID_NAME
|
49
|
+
|
50
|
+
return if start == INVALID_NAME
|
51
|
+
|
52
|
+
[start, last].each do |name|
|
53
|
+
gengou_list = line_by_name(name: name)
|
54
|
+
|
55
|
+
next if gengou_list.size.zero?
|
56
|
+
|
57
|
+
choise_start_date(
|
58
|
+
date: gengou_list[0].start_date.clone
|
59
|
+
)
|
60
|
+
choise_last_date(
|
61
|
+
date: gengou_list[-1].last_date.clone
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# 最古の開始日を選択する
|
68
|
+
#
|
69
|
+
# @param [Western::Calendar] date 西暦日
|
70
|
+
#
|
71
|
+
def choise_start_date(date:)
|
72
|
+
return if date.invalid?
|
73
|
+
|
74
|
+
if @start_date.invalid?
|
75
|
+
@start_date = date
|
76
|
+
return
|
77
|
+
end
|
78
|
+
|
79
|
+
return if date > @start_date
|
80
|
+
|
81
|
+
@start_date = date
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# 最新の終了日を選択する
|
86
|
+
#
|
87
|
+
# @param [Western::Calendar] date 西暦日
|
88
|
+
#
|
89
|
+
def choise_last_date(date:)
|
90
|
+
return if date.invalid?
|
91
|
+
|
92
|
+
if @last_date.invalid?
|
93
|
+
@last_date = date
|
94
|
+
return
|
95
|
+
end
|
96
|
+
|
97
|
+
return if date < @last_date
|
98
|
+
|
99
|
+
@last_date = date
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# 元号を取得する(元号名)
|
104
|
+
#
|
105
|
+
# @param [String] name 元号名
|
106
|
+
#
|
107
|
+
# @return [Array<Japan::Alignment::LinearGengou>] 元号
|
108
|
+
#
|
109
|
+
def line_by_name(name:)
|
110
|
+
Japan::Gengou.line_by_name(line: @index, name: name)
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# 予約元号一覧を更新する
|
115
|
+
#
|
116
|
+
# すでに解決済みの開始日・終了日をそのまま使用する(前後の元号を引き当てない)
|
117
|
+
#
|
118
|
+
def update
|
119
|
+
@list |= line(start_date: start_date, last_date: last_date)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './abstract_range'
|
4
|
+
require_relative './named_list'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Gengou
|
12
|
+
# :nodoc:
|
13
|
+
module Reserve
|
14
|
+
#
|
15
|
+
# NamedRange 予約済み計算範囲(元号名)
|
16
|
+
#
|
17
|
+
class NamedRange < AbstractRange
|
18
|
+
# @return [String] 不正元号名
|
19
|
+
INVALID_NAME = Japan::Calendar::EMPTY
|
20
|
+
|
21
|
+
#
|
22
|
+
# 初期化
|
23
|
+
#
|
24
|
+
# @param [String] start_name 開始元号名
|
25
|
+
# @param [String] last_name 終了元号名
|
26
|
+
#
|
27
|
+
def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME)
|
28
|
+
@first_list = NamedList.new(first: true, start_name: start_name, last_name: last_name)
|
29
|
+
@second_list = NamedList.new(first: false, start_name: start_name, last_name: last_name)
|
30
|
+
|
31
|
+
start_date = western_start_date
|
32
|
+
last_date = western_last_date
|
33
|
+
|
34
|
+
super(start_date: start_date, last_date: last_date)
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# 最新の元号から西暦終了日を取得する
|
39
|
+
#
|
40
|
+
# @return [Western::Calendar] 西暦終了日
|
41
|
+
#
|
42
|
+
def western_last_date
|
43
|
+
list = newest_list
|
44
|
+
|
45
|
+
return Western::Calendar.new if list.invalid?
|
46
|
+
|
47
|
+
list.western_last_date
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# 最新の元号を取得する
|
52
|
+
#
|
53
|
+
# @return [List] 最新の元号
|
54
|
+
#
|
55
|
+
def newest_list
|
56
|
+
return @first_list if @first_list.invalid?
|
57
|
+
|
58
|
+
return @first_list if @second_list.invalid?
|
59
|
+
|
60
|
+
first_western_date = @first_list.western_last_date
|
61
|
+
second_western_date = @second_list.western_last_date
|
62
|
+
|
63
|
+
return @first_list if first_western_date.invalid?
|
64
|
+
|
65
|
+
return @first_list if second_western_date.invalid?
|
66
|
+
|
67
|
+
return @first_list if first_western_date > second_western_date
|
68
|
+
|
69
|
+
@second_list
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/western/calendar'
|
4
|
+
require_relative './reserve/dated_range'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Gengou
|
12
|
+
# Reserve
|
13
|
+
#
|
14
|
+
# 元号に基づき計算範囲を予約する
|
15
|
+
#
|
16
|
+
module Reserve
|
17
|
+
#
|
18
|
+
# 予約結果を取得する
|
19
|
+
#
|
20
|
+
# * 開始日・終了日から計算する範囲を求める
|
21
|
+
# * 開始日・終了日の範囲内にある元号全てが対象となる
|
22
|
+
# * 元号に応じて計算範囲は変化する
|
23
|
+
# * 元号の開始日(改元日)が開始日よりも前であれば、結果開始日は前者になる
|
24
|
+
# * 元号の終了日(改元前日)が終了日よりも後であれば、結果終了日は前者になる
|
25
|
+
# * 南北朝のように複数元号に属する場合、より広い範囲の元号に合わせる
|
26
|
+
# * 属する元号よりもさらに範囲を広げる場合がある
|
27
|
+
# * 開始日が最初の元号の改元後30日以内の場合、さらに前の元号まで対象にする
|
28
|
+
# * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
|
29
|
+
#
|
30
|
+
# @param [Western::Calendar] start_date 開始日
|
31
|
+
# @param [Western::Calendar] last_date 終了日
|
32
|
+
#
|
33
|
+
# @return [Range] 予約済み計算範囲
|
34
|
+
#
|
35
|
+
def self.get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
36
|
+
DatedRange.new(start_date: start_date, last_date: last_date)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './abstract_scroll'
|
4
|
+
require_relative './internal/reserve/named_range'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Gengou
|
12
|
+
# NamedScroll
|
13
|
+
#
|
14
|
+
# 元号スクロール
|
15
|
+
#
|
16
|
+
class NamedScroll < AbstractScroll
|
17
|
+
#
|
18
|
+
# 初期化
|
19
|
+
#
|
20
|
+
# @param [String] start_name 開始元号名
|
21
|
+
# @param [String] last_name 終了元号名
|
22
|
+
#
|
23
|
+
def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME)
|
24
|
+
range = Reserve::NamedRange.new(start_name: start_name, last_name: last_name)
|
25
|
+
super(range: range)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|