zakuro 0.4.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -3
- data/VERSION +1 -0
- data/doc/operation/csv/month.csv +21 -0
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/gengou.rb +82 -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/cycle/abstract_remainder.rb +0 -13
- 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/era/gengou/internal/reserve.rb +42 -0
- data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -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 +49 -2
- data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
- data/lib/zakuro/calculation/range/full_range.rb +68 -107
- data/lib/zakuro/calculation/range/operated_range.rb +13 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
- 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/specifier/internal/month.rb +84 -0
- data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
- 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 -64
- data/lib/zakuro/condition.rb +14 -0
- data/lib/zakuro/era/japan/calendar.rb +133 -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/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 +32 -0
- data/lib/zakuro/era/japan/gengou.rb +35 -74
- data/lib/zakuro/era/japan/version.rb +151 -0
- data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
- data/lib/zakuro/merchant.rb +50 -3
- data/lib/zakuro/operation/month/parser.rb +1 -1
- data/lib/zakuro/operation/month/type.rb +1 -1
- data/lib/zakuro/operation/month/validator.rb +2 -2
- data/lib/zakuro/operation/yaml/month.yaml +672 -0
- data/lib/zakuro/output/response.rb +5 -5
- data/lib/zakuro/result/result.rb +17 -0
- 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/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/daien/daien.rb +1 -26
- data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/genka/const/number.rb +43 -0
- data/lib/zakuro/version/genka/const/remainder.rb +33 -0
- data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
- data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
- data/lib/zakuro/version/genka/genka.rb +1 -9
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
- data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
- data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
- data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
- 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/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/lib/zakuro/version/version_class_resolver.rb +4 -0
- data/zakuro.gemspec +1 -3
- metadata +45 -16
- 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/transfer/western_date_allocation.rb +0 -82
- 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/version/abstract_version.rb +0 -29
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../tools/typeconv'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
#
|
8
|
+
# Japan 和暦
|
9
|
+
#
|
10
|
+
module Japan
|
11
|
+
#
|
12
|
+
# Calendar 年月日情報(和暦)
|
13
|
+
#
|
14
|
+
class Calendar
|
15
|
+
# @return [Integer] 無効値
|
16
|
+
INVALID = -1
|
17
|
+
# @return [String] 空文字列
|
18
|
+
EMPTY = ''
|
19
|
+
# @return [String] 閏を示す文字列
|
20
|
+
LEAPED_TEXT = '閏'
|
21
|
+
# @return [Regexp] 和暦日フォーマット
|
22
|
+
FORMAT = /^([一-龥]{2,4})([0-9]+)年(#{LEAPED_TEXT})?([0-9]+)月([0-9]+)日$/.freeze
|
23
|
+
# @return [String] 出力用デフォルトフォーマット
|
24
|
+
DEFAULT_OUTPUT_FORM = '%s%02d年%s%02d月%02d日'
|
25
|
+
|
26
|
+
# @return [String] 元号
|
27
|
+
attr_reader :gengou
|
28
|
+
# @return [Integer] 元号年
|
29
|
+
attr_reader :year
|
30
|
+
# @return [True] 閏あり
|
31
|
+
# @return [False] 閏なし
|
32
|
+
attr_reader :leaped
|
33
|
+
# @return [Integer] 月
|
34
|
+
attr_reader :month
|
35
|
+
# @return [Integer] 日
|
36
|
+
attr_reader :day
|
37
|
+
|
38
|
+
#
|
39
|
+
# 初期化
|
40
|
+
#
|
41
|
+
# @param [String] gengou 元号
|
42
|
+
# @param [Integer] year 元号年
|
43
|
+
# @param [True, False] leaped 閏
|
44
|
+
# @param [Integer] month 月
|
45
|
+
# @param [Integer] day 日
|
46
|
+
#
|
47
|
+
def initialize(gengou: EMPTY, year: INVALID, leaped: false, month: INVALID, day: INVALID)
|
48
|
+
@gengou = gengou
|
49
|
+
@year = year
|
50
|
+
@leaped = leaped
|
51
|
+
@month = month
|
52
|
+
@day = day
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# 無効か
|
57
|
+
#
|
58
|
+
# @return [True] 無効
|
59
|
+
# @return [False] 有効
|
60
|
+
#
|
61
|
+
def invalid?
|
62
|
+
@gengou == EMPTY || @year == INVALID || @month == INVALID || @day == INVALID
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# 文字列にする
|
67
|
+
#
|
68
|
+
# @return [String] 和暦日フォーマット文字列
|
69
|
+
#
|
70
|
+
def format(form: DEFAULT_OUTPUT_FORM)
|
71
|
+
leaped_text = @leaped ? LEAPED_TEXT : ''
|
72
|
+
super(form, @gengou, @year, leaped_text, @month, @day)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# 同月か
|
77
|
+
# 年と日は無視する
|
78
|
+
#
|
79
|
+
# @param [True, False] leaped 閏
|
80
|
+
# @param [Integer] month 月
|
81
|
+
#
|
82
|
+
# @return [True] 同月
|
83
|
+
# @return [True] 同月ではない
|
84
|
+
#
|
85
|
+
def same_month?(leaped:, month:)
|
86
|
+
return false unless @leaped == leaped
|
87
|
+
|
88
|
+
@month == month
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# 年月日情報(和暦)を生成する
|
93
|
+
#
|
94
|
+
# @param [Regexp] regex 正規表現
|
95
|
+
# @param [String] text 和暦日文字列
|
96
|
+
#
|
97
|
+
# @return [Calendar] 年月日情報(和暦)
|
98
|
+
#
|
99
|
+
def self.parse(regex: FORMAT, text: '')
|
100
|
+
return Calendar.new unless valid_date_string(regex: regex, text: text)
|
101
|
+
|
102
|
+
matched = text.match(regex)
|
103
|
+
|
104
|
+
Calendar.new(
|
105
|
+
gengou: matched[1],
|
106
|
+
year: Tools::Typeconv.to_i(text: matched[2], default: INVALID),
|
107
|
+
leaped: matched[3] ? true : false,
|
108
|
+
month: Tools::Typeconv.to_i(text: matched[4], default: INVALID),
|
109
|
+
day: Tools::Typeconv.to_i(text: matched[5], default: INVALID)
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# 日付文字列を検証する
|
115
|
+
#
|
116
|
+
# @param [Regexp] regex 正規表現
|
117
|
+
# @param [String] text 和暦日文字列
|
118
|
+
#
|
119
|
+
# @return [True] 正しい
|
120
|
+
# @return [True] 正しくない
|
121
|
+
#
|
122
|
+
def self.valid_date_string(regex: FORMAT, text: '')
|
123
|
+
return false unless text
|
124
|
+
|
125
|
+
matched = text.match(regex)
|
126
|
+
|
127
|
+
return false unless matched
|
128
|
+
|
129
|
+
matched.size == 6
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -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
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './division'
|
4
|
+
|
5
|
+
require_relative './linear_gengou'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Japan
|
11
|
+
# :nodoc:
|
12
|
+
module Alignment
|
13
|
+
#
|
14
|
+
# Line 行
|
15
|
+
#
|
16
|
+
class Line
|
17
|
+
# @return [Array<LinearGengou>] 元号
|
18
|
+
attr_reader :list
|
19
|
+
|
20
|
+
#
|
21
|
+
# 初期化
|
22
|
+
#
|
23
|
+
def initialize
|
24
|
+
@list = []
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# 追加する
|
29
|
+
#
|
30
|
+
# 下記のパターンが存在し、戻り値は重複分となる
|
31
|
+
#
|
32
|
+
# 1. 完全に範囲外(開始日より前)
|
33
|
+
# [@list]: |-------|-------|
|
34
|
+
# [list]: |---|
|
35
|
+
# 2. 前半のみ範囲外
|
36
|
+
# [@list]: |-------|-------|
|
37
|
+
# [list]: |------|
|
38
|
+
# 3. 範囲内
|
39
|
+
# [@list]: |-------|-------|
|
40
|
+
# [list]: |------|
|
41
|
+
# 4. 後半のみ範囲外
|
42
|
+
# [@list]: |-------|-------|
|
43
|
+
# [list]: |------|
|
44
|
+
# 5. 完全に範囲外(開始日より後)
|
45
|
+
# [@list]: |-------|-------|
|
46
|
+
# [list]: |----|
|
47
|
+
# 6. 両端が範囲外
|
48
|
+
# [@list]: |-------|-------|
|
49
|
+
# [list]: |--------------------|
|
50
|
+
#
|
51
|
+
# @param [Array<LinearGengou>] list 元号
|
52
|
+
#
|
53
|
+
# @return [Array<LinearGengou>] 未登録元号
|
54
|
+
#
|
55
|
+
def push(list: [])
|
56
|
+
rest = rest(list: list)
|
57
|
+
|
58
|
+
insert(list: list)
|
59
|
+
|
60
|
+
rest
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# 範囲内の元号を取得する
|
65
|
+
#
|
66
|
+
# @param [Western::Calendar] start_date 開始日
|
67
|
+
# @param [Western::Calendar] last_date 終了日
|
68
|
+
#
|
69
|
+
# @return [Array<LinearGengou>] 元号
|
70
|
+
#
|
71
|
+
def get(start_date:, last_date:)
|
72
|
+
result = []
|
73
|
+
@list.each do |gengou|
|
74
|
+
next if gengou.out?(start_date: start_date, last_date: last_date)
|
75
|
+
|
76
|
+
# 1日でも範囲内であれば対象とみなす
|
77
|
+
result.push(gengou)
|
78
|
+
end
|
79
|
+
|
80
|
+
result
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
#
|
86
|
+
# 重複分(空きがないため追加できない範囲の元号)を返す
|
87
|
+
#
|
88
|
+
# @param [Array<LinearGengou>] list 元号
|
89
|
+
#
|
90
|
+
# @return [Array<LinearGengou>] 重複分元号
|
91
|
+
#
|
92
|
+
def rest(list: [])
|
93
|
+
result = []
|
94
|
+
|
95
|
+
@list.each do |gengou|
|
96
|
+
result |= and!(rest: list, other: gengou)
|
97
|
+
end
|
98
|
+
|
99
|
+
Division.connect(list: result)
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# 空き範囲に元号を登録する
|
104
|
+
#
|
105
|
+
# @param [Array<LinearGengou>] list 元号
|
106
|
+
#
|
107
|
+
def insert(list: [])
|
108
|
+
surplus_result = list.clone
|
109
|
+
@list.each do |gengou|
|
110
|
+
surplus_result = not!(surplus: surplus_result, other: gengou)
|
111
|
+
end
|
112
|
+
|
113
|
+
surplus_result = Division.connect(list: surplus_result)
|
114
|
+
|
115
|
+
surplus_result.each do |gengou|
|
116
|
+
@list.push(gengou)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# 重複した範囲を返す
|
122
|
+
#
|
123
|
+
# @param [Array<LinearGengou>] rest 残り元号
|
124
|
+
# @param [LinearGengou] other 比較元号
|
125
|
+
#
|
126
|
+
# @return [Array<LinearGengou>] 重複分
|
127
|
+
#
|
128
|
+
def and!(rest:, other:)
|
129
|
+
result = []
|
130
|
+
rest.each do |gengou|
|
131
|
+
result |= Division.match(this: gengou, other: other)
|
132
|
+
end
|
133
|
+
|
134
|
+
result
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# 範囲が重複しない差分を返す
|
139
|
+
#
|
140
|
+
# @param [Array<LinearGengou>] surplus 積元号
|
141
|
+
# @param [LinearGengou] other 比較元号
|
142
|
+
#
|
143
|
+
# @return [Array<LinearGengou>] 差分
|
144
|
+
#
|
145
|
+
def not!(surplus:, other:)
|
146
|
+
result = []
|
147
|
+
surplus.each do |gengou|
|
148
|
+
result |= Division.mismatch(this: gengou, other: other)
|
149
|
+
end
|
150
|
+
|
151
|
+
result
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|