zakuro 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/VERSION +1 -1
- data/lib/zakuro/calculation/base/gengou.rb +4 -4
- data/lib/zakuro/calculation/base/linear_gengou.rb +6 -6
- 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/list.rb +244 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
- data/lib/zakuro/calculation/{gengou → era/gengou}/internal/reserve.rb +6 -6
- data/lib/zakuro/calculation/{gengou → era/gengou}/scroll.rb +44 -95
- data/lib/zakuro/calculation/{version → era/version}/internal/crawler.rb +7 -7
- data/lib/zakuro/calculation/{version → era/version}/internal/range.rb +4 -4
- data/lib/zakuro/calculation/{version → era/version}/version.rb +3 -3
- data/lib/zakuro/calculation/monthly/month.rb +2 -2
- data/lib/zakuro/calculation/range/full_range.rb +18 -19
- data/lib/zakuro/calculation/range/operated_range.rb +3 -4
- data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
- data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +2 -2
- data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
- data/lib/zakuro/calculation/summary/range.rb +120 -0
- data/lib/zakuro/calculation/summary/single.rb +45 -67
- data/lib/zakuro/condition.rb +14 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-001-until-south.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-002-from-north.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-003-modern.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
- data/lib/zakuro/era/japan/gengou.rb +34 -73
- data/lib/zakuro/era/japan/version.rb +18 -18
- data/lib/zakuro/merchant.rb +41 -3
- data/lib/zakuro/operation/month/validator.rb +1 -1
- data/lib/zakuro/result/result.rb +17 -0
- data/lib/zakuro/version/senmyou/README.md +11 -7
- metadata +32 -20
- data/lib/zakuro/calculation/gengou/internal/counter.rb +0 -129
- data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +0 -183
- data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +0 -382
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -237
- data/lib/zakuro/era/japan/gengou/type.rb +0 -285
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -341
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../specifier/multiple_day'
|
|
4
|
+
|
|
5
|
+
require_relative '../range/operated_range'
|
|
6
|
+
|
|
7
|
+
require_relative '../range/full_range'
|
|
8
|
+
|
|
9
|
+
require_relative './internal/operation'
|
|
10
|
+
|
|
11
|
+
# :nodoc:
|
|
12
|
+
module Zakuro
|
|
13
|
+
# :nodoc:
|
|
14
|
+
module Calculation
|
|
15
|
+
# :nodoc:
|
|
16
|
+
module Summary
|
|
17
|
+
#
|
|
18
|
+
# Range 期間
|
|
19
|
+
#
|
|
20
|
+
module Range
|
|
21
|
+
#
|
|
22
|
+
# 生成する
|
|
23
|
+
#
|
|
24
|
+
# @param [Context] context 暦コンテキスト
|
|
25
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
|
26
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
|
27
|
+
#
|
|
28
|
+
# @return [Result::Range] 期間検索結果(和暦日)
|
|
29
|
+
#
|
|
30
|
+
def self.get(context:, start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
|
31
|
+
years = get_full_range_years(
|
|
32
|
+
context: context, start_date: start_date, last_date: last_date
|
|
33
|
+
)
|
|
34
|
+
operated_years = get_operated_range_years(
|
|
35
|
+
context: context, years: years, start_date: start_date, last_date: last_date
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
dates = Specifier::MultipleDay.get(
|
|
39
|
+
years: years, start_date: start_date, last_date: last_date
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
operated_dates = Specifier::MultipleDay.get(
|
|
43
|
+
years: operated_years, start_date: start_date, last_date: last_date
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
list = create_result_list(dates: dates, operated_dates: operated_dates)
|
|
47
|
+
|
|
48
|
+
Result::Range.new(list: list)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# 完全範囲を取得する
|
|
53
|
+
#
|
|
54
|
+
# @param [Context] context 暦コンテキスト
|
|
55
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
|
56
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
|
57
|
+
#
|
|
58
|
+
# @return [Array<Base::Year>] 完全範囲
|
|
59
|
+
#
|
|
60
|
+
def self.get_full_range_years(context:, start_date: Western::Calendar.new,
|
|
61
|
+
last_date: Western::Calendar.new)
|
|
62
|
+
full_range = Calculation::Range::FullRange.new(
|
|
63
|
+
context: context, start_date: start_date, last_date: last_date
|
|
64
|
+
)
|
|
65
|
+
full_range.get
|
|
66
|
+
end
|
|
67
|
+
private_class_method :get_full_range_years
|
|
68
|
+
|
|
69
|
+
#
|
|
70
|
+
# 運用結果範囲を取得する
|
|
71
|
+
#
|
|
72
|
+
# @param [Context] context 暦コンテキスト
|
|
73
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
|
74
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
|
75
|
+
# @param [Western::Calendar] date 西暦日
|
|
76
|
+
#
|
|
77
|
+
# @return [Array<Base::OperatedYear>] 運用結果範囲
|
|
78
|
+
#
|
|
79
|
+
def self.get_operated_range_years(context:, years:, start_date: Western::Calendar.new,
|
|
80
|
+
last_date: Western::Calendar.new)
|
|
81
|
+
operated_range = Calculation::Range::OperatedRange.new(
|
|
82
|
+
context: context, start_date: start_date, last_date: last_date, years: years
|
|
83
|
+
)
|
|
84
|
+
operated_range.get
|
|
85
|
+
end
|
|
86
|
+
private_class_method :get_operated_range_years
|
|
87
|
+
|
|
88
|
+
#
|
|
89
|
+
# 結果リストを生成する
|
|
90
|
+
#
|
|
91
|
+
# @param [Array<Result::Data::SingleDay>] dates 検索結果(計算値)
|
|
92
|
+
# @param [Array<Result::Data::SingleDay>] operated_dates 検索結果(運用値)
|
|
93
|
+
#
|
|
94
|
+
# @return [Array<Result::Single>] 結果リスト
|
|
95
|
+
#
|
|
96
|
+
def self.create_result_list(dates:, operated_dates:)
|
|
97
|
+
result = []
|
|
98
|
+
|
|
99
|
+
return result if dates.size != operated_dates.size
|
|
100
|
+
|
|
101
|
+
(0..(dates.size - 1)).each do |index|
|
|
102
|
+
data = operated_dates[index]
|
|
103
|
+
|
|
104
|
+
date = dates[index]
|
|
105
|
+
operation = Operation.create(calc_date: date)
|
|
106
|
+
|
|
107
|
+
result.push(
|
|
108
|
+
Result::Single.new(
|
|
109
|
+
data: data,
|
|
110
|
+
operation: operation
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
result
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -6,6 +6,8 @@ require_relative '../range/operated_range'
|
|
|
6
6
|
|
|
7
7
|
require_relative '../range/full_range'
|
|
8
8
|
|
|
9
|
+
require_relative './internal/operation'
|
|
10
|
+
|
|
9
11
|
# :nodoc:
|
|
10
12
|
module Zakuro
|
|
11
13
|
# :nodoc:
|
|
@@ -25,107 +27,83 @@ module Zakuro
|
|
|
25
27
|
# @return [Result::Single] 一日検索結果(和暦日)
|
|
26
28
|
#
|
|
27
29
|
def self.get(context:, date: Western::Calendar.new)
|
|
28
|
-
|
|
29
|
-
years = full_range.get
|
|
30
|
+
years = get_full_range_years(context: context, date: date)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
years: years, date: date
|
|
33
|
-
)
|
|
32
|
+
data = get_data(context: context, years: years, date: date)
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
context: context, start_date: date, years: years
|
|
37
|
-
)
|
|
38
|
-
operated_years = operated_range.get
|
|
34
|
+
operation = get_operation(years: years, date: date)
|
|
39
35
|
|
|
40
36
|
Result::Single.new(
|
|
41
|
-
data:
|
|
42
|
-
|
|
43
|
-
),
|
|
44
|
-
operation: create_operation(calc_date: calc_date)
|
|
37
|
+
data: data,
|
|
38
|
+
operation: operation
|
|
45
39
|
)
|
|
46
40
|
end
|
|
47
41
|
|
|
48
42
|
#
|
|
49
|
-
#
|
|
43
|
+
# 完全範囲を取得する
|
|
50
44
|
#
|
|
51
|
-
# @param [
|
|
45
|
+
# @param [Context] context 暦コンテキスト
|
|
46
|
+
# @param [Western::Calendar] date 西暦日
|
|
52
47
|
#
|
|
53
|
-
# @return [
|
|
48
|
+
# @return [Array<Base::Year>] 完全範囲
|
|
54
49
|
#
|
|
55
|
-
def self.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
operation_month = create_operation_month(operation_history: operation_history)
|
|
60
|
-
|
|
61
|
-
Result::Operation::Bundle.new(
|
|
62
|
-
operated: !operation_history.invalid?, month: operation_month, original: calc_date
|
|
63
|
-
)
|
|
50
|
+
def self.get_full_range_years(context:, date: Western::Calendar.new)
|
|
51
|
+
full_range = Calculation::Range::FullRange.new(context: context, start_date: date)
|
|
52
|
+
full_range.get
|
|
64
53
|
end
|
|
65
|
-
private_class_method :
|
|
54
|
+
private_class_method :get_full_range_years
|
|
66
55
|
|
|
67
56
|
#
|
|
68
|
-
#
|
|
57
|
+
# 運用結果範囲を取得する
|
|
69
58
|
#
|
|
70
|
-
# @param [
|
|
59
|
+
# @param [Context] context 暦コンテキスト
|
|
60
|
+
# @param [Array<Base::Year>] years 完全範囲
|
|
61
|
+
# @param [Western::Calendar] date 西暦日
|
|
71
62
|
#
|
|
72
|
-
# @return [
|
|
63
|
+
# @return [Array<Base::OperatedYear>] 運用結果範囲
|
|
73
64
|
#
|
|
74
|
-
def self.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
parent_operation_history = Operation.specify_history_by_id(
|
|
78
|
-
id: operation_history.parent_id
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
Result::Operation::Month::Bundle.new(
|
|
82
|
-
current: create_operation_month_history(operation_history: operation_history),
|
|
83
|
-
parent: create_operation_month_history(operation_history: parent_operation_history)
|
|
65
|
+
def self.get_operated_range_years(context:, years:, date: Western::Calendar.new)
|
|
66
|
+
operated_range = Calculation::Range::OperatedRange.new(
|
|
67
|
+
context: context, start_date: date, years: years
|
|
84
68
|
)
|
|
69
|
+
operated_range.get
|
|
85
70
|
end
|
|
86
|
-
private_class_method :
|
|
71
|
+
private_class_method :get_operated_range_years
|
|
87
72
|
|
|
88
73
|
#
|
|
89
|
-
#
|
|
74
|
+
# 1日を取得する
|
|
90
75
|
#
|
|
91
|
-
# @param [
|
|
76
|
+
# @param [Context] context 暦コンテキスト
|
|
77
|
+
# @param [Array<Base::Year>] years 完全範囲
|
|
78
|
+
# @param [Western::Calendar] date 西暦日
|
|
92
79
|
#
|
|
93
|
-
# @return [
|
|
80
|
+
# @return [Data::SingleDay] 1日
|
|
94
81
|
#
|
|
95
|
-
def self.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
annotations = create_annnotations(operation_history: operation_history)
|
|
82
|
+
def self.get_data(context:, years:, date: Western::Calendar.new)
|
|
83
|
+
operated_years = get_operated_range_years(context: context, years: years, date: date)
|
|
99
84
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
id: operation_history.id, western_date: operation_history.western_date.format,
|
|
103
|
-
page: reference.page, number: reference.number, annotations: annotations
|
|
85
|
+
Calculation::Specifier::SingleDay.get(
|
|
86
|
+
years: operated_years, date: date
|
|
104
87
|
)
|
|
105
88
|
end
|
|
106
|
-
private_class_method :
|
|
89
|
+
private_class_method :get_data
|
|
107
90
|
|
|
108
91
|
#
|
|
109
|
-
#
|
|
92
|
+
# 完全範囲を取得する
|
|
110
93
|
#
|
|
111
|
-
# @param [
|
|
94
|
+
# @param [Context] context 暦コンテキスト
|
|
95
|
+
# @param [Western::Calendar] date 西暦日
|
|
112
96
|
#
|
|
113
|
-
# @return [Array<
|
|
97
|
+
# @return [Array<Base::Year>] 完全範囲
|
|
114
98
|
#
|
|
115
|
-
def self.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
Result::Operation::Month::Annotation.new(
|
|
120
|
-
description: annotation.description,
|
|
121
|
-
note: annotation.note
|
|
122
|
-
)
|
|
123
|
-
)
|
|
124
|
-
end
|
|
99
|
+
def self.get_operation(years:, date: Western::Calendar.new)
|
|
100
|
+
calc_date = Calculation::Specifier::SingleDay.get(
|
|
101
|
+
years: years, date: date
|
|
102
|
+
)
|
|
125
103
|
|
|
126
|
-
|
|
104
|
+
Operation.create(calc_date: calc_date)
|
|
127
105
|
end
|
|
128
|
-
private_class_method :
|
|
106
|
+
private_class_method :get_operation
|
|
129
107
|
end
|
|
130
108
|
end
|
|
131
109
|
end
|
data/lib/zakuro/condition.rb
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../../western/calendar'
|
|
4
|
+
|
|
5
|
+
require_relative './line'
|
|
6
|
+
|
|
7
|
+
# :nodoc:
|
|
8
|
+
module Zakuro
|
|
9
|
+
#
|
|
10
|
+
# Japan 和暦
|
|
11
|
+
#
|
|
12
|
+
module Japan
|
|
13
|
+
#
|
|
14
|
+
# Alignment 整列
|
|
15
|
+
#
|
|
16
|
+
module Alignment
|
|
17
|
+
#
|
|
18
|
+
# Aligner 元号整列
|
|
19
|
+
#
|
|
20
|
+
class Aligner
|
|
21
|
+
# @return [Integer] 1行目元号
|
|
22
|
+
FIRST_LINE = 0
|
|
23
|
+
|
|
24
|
+
# @return [Integer] 2行目元号
|
|
25
|
+
SECOND_LINE = 1
|
|
26
|
+
|
|
27
|
+
# @return [Array<Integer>] 元号リスト
|
|
28
|
+
LINE_INDEXES = [FIRST_LINE, SECOND_LINE].freeze
|
|
29
|
+
|
|
30
|
+
# @return [Integer] 行数
|
|
31
|
+
LINE_SIZE = LINE_INDEXES.size
|
|
32
|
+
|
|
33
|
+
# @return [Array<Line>] 行元号
|
|
34
|
+
attr_reader :lines
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# 初期化
|
|
38
|
+
#
|
|
39
|
+
# @param [Array<Set>] resources 元号解析結果
|
|
40
|
+
#
|
|
41
|
+
def initialize(resources: [])
|
|
42
|
+
@lines = []
|
|
43
|
+
(1..LINE_SIZE).each do |_index|
|
|
44
|
+
@lines.push(Line.new)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
save(resources: resources)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#
|
|
51
|
+
# 行元号に追加する
|
|
52
|
+
#
|
|
53
|
+
# @param [Set] set 元号セット
|
|
54
|
+
#
|
|
55
|
+
def push(set:)
|
|
56
|
+
list = set.list
|
|
57
|
+
list.each do |gengou|
|
|
58
|
+
push_gengou(gengou: gengou)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# 指定した範囲内の元号を取得する
|
|
64
|
+
#
|
|
65
|
+
# @param [Integer] line 行
|
|
66
|
+
# @param [Western::Calendar] start_date 開始日
|
|
67
|
+
# @param [Western::Calendar] last_date 終了日
|
|
68
|
+
#
|
|
69
|
+
# @return [Array<LinearGengou>] 元号
|
|
70
|
+
#
|
|
71
|
+
def get(line:, start_date:, last_date:)
|
|
72
|
+
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
|
73
|
+
|
|
74
|
+
@lines[line].get(start_date: start_date, last_date: last_date)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# 保存する
|
|
81
|
+
#
|
|
82
|
+
# @param [Array<Set>] resources 元号解析結果
|
|
83
|
+
#
|
|
84
|
+
def save(resources: [])
|
|
85
|
+
resources.each do |set|
|
|
86
|
+
push(set: set)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
#
|
|
91
|
+
# 元号を追加する
|
|
92
|
+
#
|
|
93
|
+
# @param [Gengou] gengou 元号
|
|
94
|
+
#
|
|
95
|
+
def push_gengou(gengou:)
|
|
96
|
+
rest = [
|
|
97
|
+
LinearGengou.new(gengou: gengou)
|
|
98
|
+
]
|
|
99
|
+
@lines.each do |line|
|
|
100
|
+
rest = line.push(list: rest)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative './linear_gengou'
|
|
4
|
+
|
|
5
|
+
# :nodoc:
|
|
6
|
+
module Zakuro
|
|
7
|
+
# :nodoc:
|
|
8
|
+
module Japan
|
|
9
|
+
# :nodoc:
|
|
10
|
+
module Alignment
|
|
11
|
+
#
|
|
12
|
+
# Division 元号区分
|
|
13
|
+
#
|
|
14
|
+
module Division
|
|
15
|
+
#
|
|
16
|
+
# 重複した範囲を返す
|
|
17
|
+
#
|
|
18
|
+
# @param [LinearGengou] this 残り元号
|
|
19
|
+
# @param [LinearGengou] other 比較元号
|
|
20
|
+
#
|
|
21
|
+
# @return [Array<LinearGengou>] 重複分
|
|
22
|
+
#
|
|
23
|
+
def self.match(this:, other:)
|
|
24
|
+
result = []
|
|
25
|
+
if other.in?(start_date: this.start_date, last_date: this.last_date)
|
|
26
|
+
result.push(this)
|
|
27
|
+
return result
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if other.out?(start_date: this.start_date, last_date: this.last_date)
|
|
31
|
+
# 該当なし
|
|
32
|
+
return result
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if other.covered?(start_date: this.start_date, last_date: this.last_date)
|
|
36
|
+
# 範囲内のみ返す
|
|
37
|
+
result.push(trim_gengou(this: this, other: other))
|
|
38
|
+
return result
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
result.push(narrow_gengou(this: this, other: other))
|
|
42
|
+
|
|
43
|
+
result
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# 範囲が重複しない差分を返す
|
|
48
|
+
#
|
|
49
|
+
# @param [LinearGengou] this 積元号
|
|
50
|
+
# @param [LinearGengou] other 比較元号
|
|
51
|
+
#
|
|
52
|
+
# @return [Array<LinearGengou>] 差分
|
|
53
|
+
#
|
|
54
|
+
def self.mismatch(this:, other:)
|
|
55
|
+
result = []
|
|
56
|
+
if other.in?(start_date: this.start_date, last_date: this.last_date)
|
|
57
|
+
# 該当なし
|
|
58
|
+
return result
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
if other.out?(start_date: this.start_date, last_date: this.last_date)
|
|
62
|
+
result.push(this)
|
|
63
|
+
return result
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
if other.covered?(start_date: this.start_date, last_date: this.last_date)
|
|
67
|
+
result |= split_gengou(this: this, other: other)
|
|
68
|
+
return result
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
result.push(shave_gengou(this: this, other: other))
|
|
72
|
+
result
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
#
|
|
76
|
+
# 比較により分離した元号をつなげる
|
|
77
|
+
#
|
|
78
|
+
# @param [Array<LinearGengou>] list 元号
|
|
79
|
+
#
|
|
80
|
+
# @return [Array<LinearGengou>] 同一元号がつながった元号
|
|
81
|
+
#
|
|
82
|
+
def self.connect(list: []) # rubocop:disable Metrics/MethodLength
|
|
83
|
+
result = []
|
|
84
|
+
list.each do |linear_gengou|
|
|
85
|
+
if result.size.zero?
|
|
86
|
+
result.push(linear_gengou)
|
|
87
|
+
next
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
before = result[-1]
|
|
91
|
+
|
|
92
|
+
if unconnectable?(current: linear_gengou, before: before)
|
|
93
|
+
result.push(linear_gengou)
|
|
94
|
+
next
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
result[-1] = LinearGengou.new(
|
|
98
|
+
start_date: before.start_date, last_date: linear_gengou.last_date,
|
|
99
|
+
gengou: linear_gengou.gengou
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
result
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def self.unconnectable?(current:, before:)
|
|
107
|
+
return true unless current.gengou.name == before.gengou.name
|
|
108
|
+
|
|
109
|
+
return true unless (before.last_date.clone + 1) == current.start_date
|
|
110
|
+
|
|
111
|
+
false
|
|
112
|
+
end
|
|
113
|
+
private_class_method :unconnectable?
|
|
114
|
+
|
|
115
|
+
def self.split_gengou(this:, other:)
|
|
116
|
+
[
|
|
117
|
+
LinearGengou.new(
|
|
118
|
+
start_date: this.start_date.clone, last_date: other.start_date.clone - 1,
|
|
119
|
+
gengou: this.gengou
|
|
120
|
+
),
|
|
121
|
+
LinearGengou.new(
|
|
122
|
+
start_date: other.last_date.clone + 1, last_date: this.last_date.clone,
|
|
123
|
+
gengou: this.gengou
|
|
124
|
+
)
|
|
125
|
+
]
|
|
126
|
+
end
|
|
127
|
+
private_class_method :split_gengou
|
|
128
|
+
|
|
129
|
+
def self.trim_gengou(this:, other:)
|
|
130
|
+
LinearGengou.new(
|
|
131
|
+
start_date: other.start_date, last_date: other.last_date,
|
|
132
|
+
gengou: this.gengou
|
|
133
|
+
)
|
|
134
|
+
end
|
|
135
|
+
private_class_method :trim_gengou
|
|
136
|
+
|
|
137
|
+
def self.narrow_gengou(this:, other:)
|
|
138
|
+
start = this.start_date > other.start_date ? this.start_date : other.start_date
|
|
139
|
+
last = this.last_date < other.last_date ? this.last_date : other.last_date
|
|
140
|
+
|
|
141
|
+
LinearGengou.new(
|
|
142
|
+
start_date: start.clone, last_date: last.clone, gengou: this.gengou
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
private_class_method :narrow_gengou
|
|
146
|
+
|
|
147
|
+
def self.shave_gengou(this:, other:) # rubocop:disable Metrics/AbcSize
|
|
148
|
+
start = this.start_date
|
|
149
|
+
last = this.last_date
|
|
150
|
+
|
|
151
|
+
# 開始日が比較元号の開始日より前の範囲
|
|
152
|
+
last = other.start_date.clone - 1 if this.start_date < other.start_date
|
|
153
|
+
|
|
154
|
+
# 終了日が比較元号の開始日より後の範囲
|
|
155
|
+
start = other.last_date.clone + 1 if this.last_date > other.last_date
|
|
156
|
+
|
|
157
|
+
LinearGengou.new(
|
|
158
|
+
start_date: start.clone, last_date: last.clone, gengou: this.gengou
|
|
159
|
+
)
|
|
160
|
+
end
|
|
161
|
+
private_class_method :shave_gengou
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|