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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294b07e6f6f82cad6ed7d5332d96a0c147ee1cbcbb842faa745918f1d8fbac2e
|
4
|
+
data.tar.gz: 41341f57aab606cea9a86c75aa4dbef8a8d247421d7428ddf5f1e442afc1b8db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3aee8d972a13e41ae98cb6b600f2032e833380a845513b2a738bf045e7d36a719a2e31161fd90f23194bdee4e0a690dc931934ad30ab0940742f20ea0f7bc7
|
7
|
+
data.tar.gz: 8c8ea9c23b11c28910cbfcdad25dec4720f919a1bbb0551737f8cf82cc62cd59621dcdd4770580d81c7a4a1c8d8859765e3ae7cd39592369a25dd89e1da9932d
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -87,13 +87,15 @@ puts merchant.commit.to_json
|
|
87
87
|
| 項目名 | キー名 | hash内キー名 | データ型 | 備考 |
|
88
88
|
|----------------|---------|--------------|----------|--------------------|
|
89
89
|
| 基準日 | date | | Date | 西暦日 |
|
90
|
-
| | | | String |
|
91
|
-
| 範囲(開始日)
|
92
|
-
|
|
90
|
+
| | | | String | 和暦日/西暦日 |
|
91
|
+
| 範囲(開始日) | range | start | Date | 西暦日 |
|
92
|
+
| | | | String | 和暦日/西暦日 |
|
93
|
+
| 範囲(終了日) | | last | Date | 西暦日 |
|
94
|
+
| | | | String | 和暦日/西暦日 |
|
93
95
|
| 列 | columns | | Array | 取得したい列の列名 |
|
94
96
|
| オプション | options | | Array | 取得オプション |
|
95
97
|
|
96
|
-
現時点では `date`
|
98
|
+
現時点では `date` と `range` のみ対応中です。
|
97
99
|
|
98
100
|
## オプション
|
99
101
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/doc/operation/transfer.rb
CHANGED
@@ -39,25 +39,25 @@ table.each do |row|
|
|
39
39
|
'diffs' => {
|
40
40
|
'month' => {
|
41
41
|
'number' => {
|
42
|
-
'
|
43
|
-
'
|
42
|
+
'src' => month_str_to_number(row['月(計)']),
|
43
|
+
'dest' => month_str_to_number(row['月(実)'])
|
44
44
|
},
|
45
45
|
'leaped' => {
|
46
|
-
'
|
47
|
-
'
|
46
|
+
'src' => month_str_to_leaped(row['月(計)']),
|
47
|
+
'dest' => month_str_to_leaped(row['月(実)'])
|
48
48
|
},
|
49
49
|
'days' => {
|
50
|
-
'
|
51
|
-
'
|
50
|
+
'src' => row['月大小(計)'],
|
51
|
+
'dest' => row['月大小(実)']
|
52
52
|
}
|
53
53
|
},
|
54
54
|
'solar_term' => {
|
55
|
-
'
|
55
|
+
'src' => {
|
56
56
|
'index' => row['中気番号(計)'],
|
57
57
|
'to' => row['中気移動先'],
|
58
58
|
'zodiac_name' => row['中気(計)']
|
59
59
|
},
|
60
|
-
'
|
60
|
+
'dest' => {
|
61
61
|
'index' => row['中気番号(実)'],
|
62
62
|
'from' => row['中気移動元'],
|
63
63
|
'zodiac_name' => row['中気(実)']
|
@@ -67,6 +67,52 @@ module Zakuro
|
|
67
67
|
LinearGengou.new
|
68
68
|
end
|
69
69
|
|
70
|
+
#
|
71
|
+
# 元号を取得する
|
72
|
+
#
|
73
|
+
# @param [String] name 元号名
|
74
|
+
#
|
75
|
+
# @return [LinearGengou] 元号
|
76
|
+
#
|
77
|
+
def match_by_name(name:)
|
78
|
+
result = match_first_line_by_name(name: name)
|
79
|
+
return result unless result.invalid?
|
80
|
+
|
81
|
+
result = match_second_line_by_name(name: name)
|
82
|
+
|
83
|
+
result
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# 1行目元号を取得する
|
88
|
+
#
|
89
|
+
# @param [String] name 元号名
|
90
|
+
#
|
91
|
+
# @return [LinearGengou] 1行目元号
|
92
|
+
#
|
93
|
+
def match_first_line_by_name(name:)
|
94
|
+
@first_line.each do |line|
|
95
|
+
return line.clone if line.name == name
|
96
|
+
end
|
97
|
+
|
98
|
+
LinearGengou.new
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# 2行目元号を取得する
|
103
|
+
#
|
104
|
+
# @param [String] name 元号名
|
105
|
+
#
|
106
|
+
# @return [LinearGengou] 2行目元号
|
107
|
+
#
|
108
|
+
def match_second_line_by_name(name:)
|
109
|
+
@second_line.each do |line|
|
110
|
+
return line.clone if line.name == name
|
111
|
+
end
|
112
|
+
|
113
|
+
LinearGengou.new
|
114
|
+
end
|
115
|
+
|
70
116
|
#
|
71
117
|
# 不正か
|
72
118
|
#
|
@@ -3,7 +3,6 @@
|
|
3
3
|
require_relative '../../../era/western/calendar'
|
4
4
|
require_relative '../../base/gengou'
|
5
5
|
require_relative '../../base/linear_gengou'
|
6
|
-
require_relative './internal/reserve/range'
|
7
6
|
require_relative './internal/connector'
|
8
7
|
require_relative './internal/publisher'
|
9
8
|
|
@@ -13,16 +12,16 @@ module Zakuro
|
|
13
12
|
module Calculation
|
14
13
|
# :nodoc:
|
15
14
|
module Gengou
|
16
|
-
#
|
15
|
+
# AbstractScroll
|
17
16
|
#
|
18
17
|
# 元号スクロール
|
19
18
|
#
|
20
|
-
class
|
19
|
+
class AbstractScroll
|
21
20
|
# @return [Western::Calendar] 月初日
|
22
21
|
attr_reader :monthly_start_date
|
23
22
|
# @return [Western::Calendar] 月末日
|
24
23
|
attr_reader :monthly_last_date
|
25
|
-
# @return [Reserve::
|
24
|
+
# @return [Reserve::AbstractRange] 予約範囲
|
26
25
|
attr_reader :range
|
27
26
|
# @return [Array<Counte>] 1行目元号
|
28
27
|
attr_reader :first_gengou
|
@@ -34,13 +33,12 @@ module Zakuro
|
|
34
33
|
#
|
35
34
|
# 初期化
|
36
35
|
#
|
37
|
-
# @param [
|
38
|
-
# @param [Western::Calendar] last_date 西暦終了日(最大範囲)
|
36
|
+
# @param [Reserve::AbstractRange] range 予約範囲
|
39
37
|
#
|
40
|
-
def initialize(
|
38
|
+
def initialize(range:)
|
41
39
|
@monthly_start_date = Western::Calendar.new
|
42
40
|
@monthly_last_date = Western::Calendar.new
|
43
|
-
@range =
|
41
|
+
@range = range
|
44
42
|
@first_gengou = []
|
45
43
|
@second_gengou = []
|
46
44
|
@ignited = false
|
@@ -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
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal: true
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../../../../era/japan/gengou/resource'
|
4
4
|
require_relative '../../../../../era/japan/gengou'
|
@@ -7,6 +7,8 @@ require_relative '../../../../../era/western/calendar'
|
|
7
7
|
|
8
8
|
require_relative '../counter'
|
9
9
|
|
10
|
+
require_relative './empty_link'
|
11
|
+
|
10
12
|
# :nodoc:
|
11
13
|
module Zakuro
|
12
14
|
# :nodoc:
|
@@ -15,11 +17,11 @@ module Zakuro
|
|
15
17
|
module Gengou
|
16
18
|
# :nodoc:
|
17
19
|
module Reserve
|
18
|
-
#
|
20
|
+
# AbstractList
|
19
21
|
#
|
20
|
-
#
|
22
|
+
# 抽象予約元号一覧
|
21
23
|
#
|
22
|
-
class
|
24
|
+
class AbstractList
|
23
25
|
# @return [Integer] 不正年
|
24
26
|
INVALID_YEAR = -1
|
25
27
|
# @return [Integer] 最大月日数
|
@@ -37,15 +39,15 @@ module Zakuro
|
|
37
39
|
#
|
38
40
|
# 初期化
|
39
41
|
#
|
40
|
-
# @param [
|
42
|
+
# @param [Integer] index n行目元号
|
41
43
|
# @param [Western::Calendar] start_date 開始日
|
42
44
|
# @param [Western::Calendar] last_date 終了日
|
43
45
|
#
|
44
|
-
def initialize(
|
46
|
+
def initialize(index:, start_date: Western::Calendar.new,
|
45
47
|
last_date: Western::Calendar)
|
46
|
-
@index =
|
48
|
+
@index = index
|
47
49
|
@start_date = start_date.clone
|
48
|
-
@last_date = last_date.
|
50
|
+
@last_date = last_date.clone
|
49
51
|
@list = []
|
50
52
|
|
51
53
|
update
|
@@ -91,41 +93,7 @@ module Zakuro
|
|
91
93
|
)
|
92
94
|
end
|
93
95
|
|
94
|
-
|
95
|
-
if result.size.zero?
|
96
|
-
result.push(
|
97
|
-
Gengou::Counter.new(
|
98
|
-
gengou: Japan::Resource::Gengou.new(
|
99
|
-
both_start_date: Japan::Resource::Both::Date.new(
|
100
|
-
western: start_date.clone
|
101
|
-
),
|
102
|
-
last_date: last_date.clone
|
103
|
-
)
|
104
|
-
)
|
105
|
-
)
|
106
|
-
return result
|
107
|
-
end
|
108
|
-
|
109
|
-
# FIXME: 有効元号の前後しか見ていない
|
110
|
-
if start_date < result[0].start_date
|
111
|
-
result.unshift(
|
112
|
-
Gengou::Counter.new(
|
113
|
-
gengou: Japan::Resource::Gengou.new,
|
114
|
-
start_date: start_date.clone,
|
115
|
-
last_date: result[0].start_date.clone - 1
|
116
|
-
)
|
117
|
-
)
|
118
|
-
end
|
119
|
-
|
120
|
-
if last_date > result[-1].last_date
|
121
|
-
result.push(
|
122
|
-
Gengou::Counter.new(
|
123
|
-
gengou: Japan::Resource::Gengou.new,
|
124
|
-
start_date: result[0].last_date.clone + 1,
|
125
|
-
last_date: last_date.clone
|
126
|
-
)
|
127
|
-
)
|
128
|
-
end
|
96
|
+
EmptyLink.fill(counters: result, start_date: start_date, last_date: last_date)
|
129
97
|
|
130
98
|
result
|
131
99
|
end
|
@@ -152,6 +120,17 @@ module Zakuro
|
|
152
120
|
@list[0].gengou.both_start_date.western.clone
|
153
121
|
end
|
154
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
|
+
|
155
134
|
#
|
156
135
|
# 西暦開始年を取得する
|
157
136
|
#
|
@@ -219,24 +198,31 @@ module Zakuro
|
|
219
198
|
# 予約元号一覧を更新する
|
220
199
|
#
|
221
200
|
def update
|
222
|
-
#
|
223
|
-
start_date = @start_date.clone - (MAX_MONTH_DAYS + 1)
|
224
|
-
# 開始日の30日後に次の元号がある場合は、次の元号を設定する
|
225
|
-
last_date = @last_date.clone + (MAX_MONTH_DAYS + 1)
|
226
|
-
|
227
|
-
@list |= line(start_date: start_date, last_date: last_date)
|
201
|
+
# override
|
228
202
|
end
|
229
203
|
|
230
204
|
#
|
231
|
-
#
|
205
|
+
# 元号を取得する
|
232
206
|
#
|
233
|
-
# @param [Western::Calendar]
|
207
|
+
# @param [Western::Calendar] start_date 開始日
|
208
|
+
# @param [Western::Calendar] last_date 終了日
|
234
209
|
#
|
235
210
|
# @return [Array<Japan::Alignment::LinearGengou>] 元号
|
236
211
|
#
|
237
212
|
def line(start_date:, last_date:)
|
238
213
|
Japan::Gengou.line(line: @index, start_date: start_date, last_date: last_date)
|
239
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
|
240
226
|
end
|
241
227
|
end
|
242
228
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative '../../../../../era/western/calendar'
|
4
4
|
|
5
|
-
require_relative './
|
5
|
+
require_relative './dated_list'
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
@@ -13,9 +13,9 @@ module Zakuro
|
|
13
13
|
# :nodoc:
|
14
14
|
module Reserve
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# AbstractRange 予約済み計算範囲
|
17
17
|
#
|
18
|
-
class
|
18
|
+
class AbstractRange
|
19
19
|
# @return [List] 1行目元号
|
20
20
|
attr_reader :first_list
|
21
21
|
# @return [List] 2行目元号
|
@@ -30,8 +30,8 @@ module Zakuro
|
|
30
30
|
def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
31
31
|
last_date = start_date.clone if last_date.invalid?
|
32
32
|
|
33
|
-
@first_list =
|
34
|
-
@second_list =
|
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
35
|
|
36
36
|
renew(last_date: last_date)
|
37
37
|
end
|
@@ -59,10 +59,10 @@ module Zakuro
|
|
59
59
|
|
60
60
|
return if native_start_date.invalid?
|
61
61
|
|
62
|
-
@first_list =
|
63
|
-
|
64
|
-
@second_list =
|
65
|
-
|
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
66
|
end
|
67
67
|
|
68
68
|
#
|
@@ -107,11 +107,11 @@ module Zakuro
|
|
107
107
|
# @return [Japan::Calendar] 和暦開始日
|
108
108
|
#
|
109
109
|
def japan_start_date
|
110
|
-
|
110
|
+
list = oldest_list
|
111
111
|
|
112
|
-
return Japan::Calendar.new if
|
112
|
+
return Japan::Calendar.new if list.invalid?
|
113
113
|
|
114
|
-
|
114
|
+
list.japan_start_date
|
115
115
|
end
|
116
116
|
|
117
117
|
#
|
@@ -120,11 +120,11 @@ module Zakuro
|
|
120
120
|
# @return [Western::Calendar] 西暦開始日
|
121
121
|
#
|
122
122
|
def western_start_date
|
123
|
-
|
123
|
+
list = oldest_list
|
124
124
|
|
125
|
-
return Western::Calendar.new if
|
125
|
+
return Western::Calendar.new if list.invalid?
|
126
126
|
|
127
|
-
|
127
|
+
list.western_start_date
|
128
128
|
end
|
129
129
|
|
130
130
|
#
|
@@ -168,9 +168,9 @@ module Zakuro
|
|
168
168
|
#
|
169
169
|
# 最古の元号を取得する
|
170
170
|
#
|
171
|
-
# @return [
|
171
|
+
# @return [List] 最古の元号
|
172
172
|
#
|
173
|
-
def
|
173
|
+
def oldest_list
|
174
174
|
return @first_list if @first_list.invalid?
|
175
175
|
|
176
176
|
return @first_list if @second_list.invalid?
|
@@ -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
|