zakuro 0.6.1 → 0.8.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 +46 -17
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/gengou.rb +49 -3
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +26 -24
- data/lib/zakuro/calculation/base/year.rb +7 -7
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
- data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
- data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +44 -37
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
- 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 +156 -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 +73 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
- data/lib/zakuro/calculation/era/version/version.rb +12 -10
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
- data/lib/zakuro/calculation/monthly/const.rb +18 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
- data/lib/zakuro/calculation/monthly/month.rb +55 -16
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
- data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
- data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +45 -29
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
- 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/medieval_annual_range.rb +64 -63
- 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_term.rb +220 -0
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
- data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +127 -0
- data/lib/zakuro/calculation/summary/western/single.rb +115 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +143 -94
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +119 -0
- data/lib/zakuro/context/version_class_resolver.rb +112 -0
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
- data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +28 -41
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +104 -88
- data/lib/zakuro/exception/case/pattern.rb +71 -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 +39 -0
- data/lib/zakuro/exception/zakuro_error.rb +46 -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 +81 -0
- data/lib/zakuro/merchant.rb +67 -33
- data/lib/zakuro/operation/month/parser.rb +252 -249
- data/lib/zakuro/operation/month/type.rb +44 -35
- data/lib/zakuro/operation/month/validator.rb +182 -178
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +107 -141
- 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/option/abstract_option.rb +37 -0
- data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
- data/lib/zakuro/result/data/single_day.rb +56 -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/history.rb +54 -0
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +22 -97
- data/lib/zakuro/result/result.rb +6 -4
- data/lib/zakuro/tools/stringifier.rb +67 -42
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
- data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
- data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
- metadata +68 -16
- data/lib/zakuro/calculation/range/operated_range.rb +0 -193
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
- 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/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -6,98 +6,117 @@ require_relative './line'
|
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
9
|
-
#
|
10
|
-
# Japan 和暦
|
11
|
-
#
|
9
|
+
# :nodoc:
|
12
10
|
module Japan
|
13
|
-
#
|
14
|
-
|
15
|
-
#
|
16
|
-
module Alignment
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# Alignment 整列
|
19
15
|
#
|
20
|
-
|
21
|
-
#
|
22
|
-
|
16
|
+
module Alignment
|
17
|
+
#
|
18
|
+
# Aligner 元号整列
|
19
|
+
#
|
20
|
+
class Aligner
|
21
|
+
# @return [Integer] 1行目元号
|
22
|
+
FIRST_LINE = 0
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# @return [Integer] 2行目元号
|
25
|
+
SECOND_LINE = 1
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# @return [Array<Integer>] 元号リスト
|
28
|
+
LINE_INDEXES = [FIRST_LINE, SECOND_LINE].freeze
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
# @return [Integer] 行数
|
31
|
+
LINE_SIZE = LINE_INDEXES.size
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
# @return [Array<Line>] 行元号
|
34
|
+
attr_reader :lines
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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)
|
45
48
|
end
|
46
49
|
|
47
|
-
|
48
|
-
|
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
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
+
# @raise [ArgumentError] 引数エラー
|
72
|
+
#
|
73
|
+
def get(line:, start_date:, last_date:)
|
74
|
+
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
75
|
+
|
76
|
+
lines[line].get(start_date: start_date, last_date: last_date)
|
59
77
|
end
|
60
|
-
end
|
61
78
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
79
|
+
#
|
80
|
+
# 指定した範囲内の元号を取得する(元号名)
|
81
|
+
#
|
82
|
+
# @param [Integer] line 行
|
83
|
+
# @param [String] name 元号名
|
84
|
+
#
|
85
|
+
# @return [Array<LinearGengou>] 元号
|
86
|
+
#
|
87
|
+
# @raise [ArgumentError] 引数エラー
|
88
|
+
#
|
89
|
+
def get_by_name(line:, name:)
|
90
|
+
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
73
91
|
|
74
|
-
|
75
|
-
|
92
|
+
lines[line].get_by_name(name: name)
|
93
|
+
end
|
76
94
|
|
77
|
-
|
95
|
+
private
|
78
96
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
97
|
+
#
|
98
|
+
# 保存する
|
99
|
+
#
|
100
|
+
# @param [Array<Set>] resources 元号解析結果
|
101
|
+
#
|
102
|
+
def save(resources: [])
|
103
|
+
resources.each do |set|
|
104
|
+
push(set: set)
|
105
|
+
end
|
87
106
|
end
|
88
|
-
end
|
89
107
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
108
|
+
#
|
109
|
+
# 元号を追加する
|
110
|
+
#
|
111
|
+
# @param [Gengou] gengou 元号
|
112
|
+
#
|
113
|
+
def push_gengou(gengou:)
|
114
|
+
rest = [
|
115
|
+
LinearGengou.new(gengou: gengou)
|
116
|
+
]
|
117
|
+
lines.each do |line|
|
118
|
+
rest = line.push(list: rest)
|
119
|
+
end
|
101
120
|
end
|
102
121
|
end
|
103
122
|
end
|
@@ -7,158 +7,160 @@ module Zakuro
|
|
7
7
|
# :nodoc:
|
8
8
|
module Japan
|
9
9
|
# :nodoc:
|
10
|
-
module
|
11
|
-
#
|
12
|
-
|
13
|
-
#
|
14
|
-
module Division
|
10
|
+
module Gengou
|
11
|
+
# :nodoc:
|
12
|
+
module Alignment
|
15
13
|
#
|
16
|
-
#
|
14
|
+
# Division 元号区分
|
17
15
|
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
16
|
+
module Division
|
17
|
+
class << self
|
18
|
+
#
|
19
|
+
# 重複した範囲を返す
|
20
|
+
#
|
21
|
+
# @param [LinearGengou] this 残り元号
|
22
|
+
# @param [LinearGengou] other 比較元号
|
23
|
+
#
|
24
|
+
# @return [Array<LinearGengou>] 重複分
|
25
|
+
#
|
26
|
+
def match(this:, other:)
|
27
|
+
result = []
|
28
|
+
if other.in?(start_date: this.start_date, last_date: this.last_date)
|
29
|
+
result.push(this)
|
30
|
+
return result
|
31
|
+
end
|
32
|
+
|
33
|
+
if other.out?(start_date: this.start_date, last_date: this.last_date)
|
34
|
+
# 該当なし
|
35
|
+
return result
|
36
|
+
end
|
37
|
+
|
38
|
+
if other.covered?(start_date: this.start_date, last_date: this.last_date)
|
39
|
+
# 範囲内のみ返す
|
40
|
+
result.push(trim_gengou(this: this, other: other))
|
41
|
+
return result
|
42
|
+
end
|
43
|
+
|
44
|
+
result.push(narrow_gengou(this: this, other: other))
|
45
|
+
|
46
|
+
result
|
88
47
|
end
|
89
48
|
|
90
|
-
|
49
|
+
#
|
50
|
+
# 範囲が重複しない差分を返す
|
51
|
+
#
|
52
|
+
# @param [LinearGengou] this 積元号
|
53
|
+
# @param [LinearGengou] other 比較元号
|
54
|
+
#
|
55
|
+
# @return [Array<LinearGengou>] 差分
|
56
|
+
#
|
57
|
+
def mismatch(this:, other:)
|
58
|
+
result = []
|
59
|
+
if other.in?(start_date: this.start_date, last_date: this.last_date)
|
60
|
+
# 該当なし
|
61
|
+
return result
|
62
|
+
end
|
63
|
+
|
64
|
+
if other.out?(start_date: this.start_date, last_date: this.last_date)
|
65
|
+
result.push(this)
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
if other.covered?(start_date: this.start_date, last_date: this.last_date)
|
70
|
+
result |= split_gengou(this: this, other: other)
|
71
|
+
return result
|
72
|
+
end
|
73
|
+
|
74
|
+
result.push(shave_gengou(this: this, other: other))
|
75
|
+
result
|
76
|
+
end
|
91
77
|
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
#
|
79
|
+
# 比較により分離した元号をつなげる
|
80
|
+
#
|
81
|
+
# @param [Array<LinearGengou>] list 元号
|
82
|
+
#
|
83
|
+
# @return [Array<LinearGengou>] 同一元号がつながった元号
|
84
|
+
#
|
85
|
+
def connect(list: []) # rubocop:disable Metrics/MethodLength
|
86
|
+
result = []
|
87
|
+
list.each do |linear_gengou|
|
88
|
+
if result.size.zero?
|
89
|
+
result.push(linear_gengou)
|
90
|
+
next
|
91
|
+
end
|
92
|
+
|
93
|
+
before = result[-1]
|
94
|
+
|
95
|
+
if unconnectable?(current: linear_gengou, before: before)
|
96
|
+
result.push(linear_gengou)
|
97
|
+
next
|
98
|
+
end
|
99
|
+
|
100
|
+
result[-1] = LinearGengou.new(
|
101
|
+
start_date: before.start_date, last_date: linear_gengou.last_date,
|
102
|
+
gengou: linear_gengou.gengou
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
result
|
95
107
|
end
|
96
108
|
|
97
|
-
|
98
|
-
start_date: before.start_date, last_date: linear_gengou.last_date,
|
99
|
-
gengou: linear_gengou.gengou
|
100
|
-
)
|
101
|
-
end
|
109
|
+
private
|
102
110
|
|
103
|
-
|
104
|
-
|
111
|
+
def unconnectable?(current:, before:)
|
112
|
+
return true unless current.gengou.name == before.gengou.name
|
105
113
|
|
106
|
-
|
107
|
-
return true unless current.gengou.name == before.gengou.name
|
114
|
+
return true unless (before.last_date.clone + 1) == current.start_date
|
108
115
|
|
109
|
-
|
116
|
+
false
|
117
|
+
end
|
110
118
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
gengou: this.gengou
|
124
|
-
)
|
125
|
-
]
|
126
|
-
end
|
127
|
-
private_class_method :split_gengou
|
119
|
+
def split_gengou(this:, other:)
|
120
|
+
[
|
121
|
+
LinearGengou.new(
|
122
|
+
start_date: this.start_date.clone, last_date: other.start_date.clone - 1,
|
123
|
+
gengou: this.gengou
|
124
|
+
),
|
125
|
+
LinearGengou.new(
|
126
|
+
start_date: other.last_date.clone + 1, last_date: this.last_date.clone,
|
127
|
+
gengou: this.gengou
|
128
|
+
)
|
129
|
+
]
|
130
|
+
end
|
128
131
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
private_class_method :trim_gengou
|
132
|
+
def trim_gengou(this:, other:)
|
133
|
+
LinearGengou.new(
|
134
|
+
start_date: other.start_date, last_date: other.last_date,
|
135
|
+
gengou: this.gengou
|
136
|
+
)
|
137
|
+
end
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
-
|
139
|
+
def narrow_gengou(this:, other:)
|
140
|
+
start = this.start_date > other.start_date ? this.start_date : other.start_date
|
141
|
+
last = this.last_date < other.last_date ? this.last_date : other.last_date
|
140
142
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
private_class_method :narrow_gengou
|
143
|
+
LinearGengou.new(
|
144
|
+
start_date: start.clone, last_date: last.clone, gengou: this.gengou
|
145
|
+
)
|
146
|
+
end
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
148
|
+
def shave_gengou(this:, other:) # rubocop:disable Metrics/AbcSize
|
149
|
+
start = this.start_date
|
150
|
+
last = this.last_date
|
150
151
|
|
151
|
-
|
152
|
-
|
152
|
+
# 開始日が比較元号の開始日より前の範囲
|
153
|
+
last = other.start_date.clone - 1 if this.start_date < other.start_date
|
153
154
|
|
154
|
-
|
155
|
-
|
155
|
+
# 終了日が比較元号の開始日より後の範囲
|
156
|
+
start = other.last_date.clone + 1 if this.last_date > other.last_date
|
156
157
|
|
157
|
-
|
158
|
-
|
159
|
-
|
158
|
+
LinearGengou.new(
|
159
|
+
start_date: start.clone, last_date: last.clone, gengou: this.gengou
|
160
|
+
)
|
161
|
+
end
|
162
|
+
end
|
160
163
|
end
|
161
|
-
private_class_method :shave_gengou
|
162
164
|
end
|
163
165
|
end
|
164
166
|
end
|