zakuro 0.7.2 → 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/README.md +3 -3
- data/VERSION +1 -1
- data/lib/zakuro/calculation/base/gengou.rb +5 -5
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +23 -21
- data/lib/zakuro/calculation/base/year.rb +3 -3
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
- 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/abstract_scroll.rb +38 -29
- 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/abstract_list.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
- 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 +39 -37
- data/lib/zakuro/calculation/monthly/month.rb +15 -15
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- 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 +5 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
- data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
- data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +95 -92
- data/lib/zakuro/calculation/summary/western/single.rb +78 -76
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -124
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/condition.rb +121 -111
- data/lib/zakuro/context/context.rb +1 -1
- data/lib/zakuro/context/option.rb +31 -29
- data/lib/zakuro/context/version_class_resolver.rb +26 -24
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
- data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -36
- data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -37
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
- data/lib/zakuro/era/japan/gengou.rb +28 -26
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +102 -90
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +15 -13
- data/lib/zakuro/exception/zakuro_error.rb +1 -1
- data/lib/zakuro/gateway/locale/date.rb +2 -2
- data/lib/zakuro/gateway/locale/range.rb +3 -3
- data/lib/zakuro/gateway/range.rb +1 -1
- data/lib/zakuro/gateway/single.rb +13 -2
- data/lib/zakuro/merchant.rb +1 -1
- data/lib/zakuro/operation/month/parser.rb +252 -251
- data/lib/zakuro/operation/month/type.rb +17 -8
- data/lib/zakuro/operation/month/validator.rb +148 -144
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/output/response.rb +112 -113
- data/lib/zakuro/result/operation/month/annotation.rb +2 -2
- data/lib/zakuro/result/operation/month/history.rb +2 -2
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +39 -0
- data/lib/zakuro/result/result.rb +3 -3
- data/lib/zakuro/tools/stringifier.rb +66 -64
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
- 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 +2 -2
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- 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/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
- 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/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
- 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 +12 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/bundle.rb +0 -44
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -41,7 +41,7 @@ module Zakuro
|
|
41
41
|
def initialize(resources: [])
|
42
42
|
@lines = []
|
43
43
|
(1..LINE_SIZE).each do |_index|
|
44
|
-
|
44
|
+
lines.push(Line.new)
|
45
45
|
end
|
46
46
|
|
47
47
|
save(resources: resources)
|
@@ -73,7 +73,7 @@ module Zakuro
|
|
73
73
|
def get(line:, start_date:, last_date:)
|
74
74
|
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
75
75
|
|
76
|
-
|
76
|
+
lines[line].get(start_date: start_date, last_date: last_date)
|
77
77
|
end
|
78
78
|
|
79
79
|
#
|
@@ -89,7 +89,7 @@ module Zakuro
|
|
89
89
|
def get_by_name(line:, name:)
|
90
90
|
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
91
91
|
|
92
|
-
|
92
|
+
lines[line].get_by_name(name: name)
|
93
93
|
end
|
94
94
|
|
95
95
|
private
|
@@ -114,7 +114,7 @@ module Zakuro
|
|
114
114
|
rest = [
|
115
115
|
LinearGengou.new(gengou: gengou)
|
116
116
|
]
|
117
|
-
|
117
|
+
lines.each do |line|
|
118
118
|
rest = line.push(list: rest)
|
119
119
|
end
|
120
120
|
end
|
@@ -14,153 +14,152 @@ module Zakuro
|
|
14
14
|
# Division 元号区分
|
15
15
|
#
|
16
16
|
module Division
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if other.out?(start_date: this.start_date, last_date: this.last_date)
|
33
|
-
# 該当なし
|
34
|
-
return result
|
35
|
-
end
|
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
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
33
|
+
if other.out?(start_date: this.start_date, last_date: this.last_date)
|
34
|
+
# 該当なし
|
35
|
+
return result
|
36
|
+
end
|
42
37
|
|
43
|
-
|
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
|
44
43
|
|
45
|
-
|
46
|
-
end
|
44
|
+
result.push(narrow_gengou(this: this, other: other))
|
47
45
|
|
48
|
-
|
49
|
-
# 範囲が重複しない差分を返す
|
50
|
-
#
|
51
|
-
# @param [LinearGengou] this 積元号
|
52
|
-
# @param [LinearGengou] other 比較元号
|
53
|
-
#
|
54
|
-
# @return [Array<LinearGengou>] 差分
|
55
|
-
#
|
56
|
-
def self.mismatch(this:, other:)
|
57
|
-
result = []
|
58
|
-
if other.in?(start_date: this.start_date, last_date: this.last_date)
|
59
|
-
# 該当なし
|
60
|
-
return result
|
46
|
+
result
|
61
47
|
end
|
62
48
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
72
63
|
|
73
|
-
|
74
|
-
|
75
|
-
|
64
|
+
if other.out?(start_date: this.start_date, last_date: this.last_date)
|
65
|
+
result.push(this)
|
66
|
+
return result
|
67
|
+
end
|
76
68
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
# @param [Array<LinearGengou>] list 元号
|
81
|
-
#
|
82
|
-
# @return [Array<LinearGengou>] 同一元号がつながった元号
|
83
|
-
#
|
84
|
-
def self.connect(list: []) # rubocop:disable Metrics/MethodLength
|
85
|
-
result = []
|
86
|
-
list.each do |linear_gengou|
|
87
|
-
if result.size.zero?
|
88
|
-
result.push(linear_gengou)
|
89
|
-
next
|
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
|
90
72
|
end
|
91
73
|
|
92
|
-
|
74
|
+
result.push(shave_gengou(this: this, other: other))
|
75
|
+
result
|
76
|
+
end
|
93
77
|
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
+
)
|
97
104
|
end
|
98
105
|
|
99
|
-
result
|
100
|
-
start_date: before.start_date, last_date: linear_gengou.last_date,
|
101
|
-
gengou: linear_gengou.gengou
|
102
|
-
)
|
106
|
+
result
|
103
107
|
end
|
104
108
|
|
105
|
-
|
106
|
-
end
|
109
|
+
private
|
107
110
|
|
108
|
-
|
109
|
-
|
111
|
+
def unconnectable?(current:, before:)
|
112
|
+
return true unless current.gengou.name == before.gengou.name
|
110
113
|
|
111
|
-
|
114
|
+
return true unless (before.last_date.clone + 1) == current.start_date
|
112
115
|
|
113
|
-
|
114
|
-
|
115
|
-
private_class_method :unconnectable?
|
116
|
+
false
|
117
|
+
end
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
131
|
+
|
132
|
+
def trim_gengou(this:, other:)
|
123
133
|
LinearGengou.new(
|
124
|
-
start_date: other.
|
134
|
+
start_date: other.start_date, last_date: other.last_date,
|
125
135
|
gengou: this.gengou
|
126
136
|
)
|
127
|
-
|
128
|
-
end
|
129
|
-
private_class_method :split_gengou
|
130
|
-
|
131
|
-
def self.trim_gengou(this:, other:)
|
132
|
-
LinearGengou.new(
|
133
|
-
start_date: other.start_date, last_date: other.last_date,
|
134
|
-
gengou: this.gengou
|
135
|
-
)
|
136
|
-
end
|
137
|
-
private_class_method :trim_gengou
|
137
|
+
end
|
138
138
|
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
private_class_method :narrow_gengou
|
143
|
+
LinearGengou.new(
|
144
|
+
start_date: start.clone, last_date: last.clone, gengou: this.gengou
|
145
|
+
)
|
146
|
+
end
|
148
147
|
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
def shave_gengou(this:, other:) # rubocop:disable Metrics/AbcSize
|
149
|
+
start = this.start_date
|
150
|
+
last = this.last_date
|
152
151
|
|
153
|
-
|
154
|
-
|
152
|
+
# 開始日が比較元号の開始日より前の範囲
|
153
|
+
last = other.start_date.clone - 1 if this.start_date < other.start_date
|
155
154
|
|
156
|
-
|
157
|
-
|
155
|
+
# 終了日が比較元号の開始日より後の範囲
|
156
|
+
start = other.last_date.clone + 1 if this.last_date > other.last_date
|
158
157
|
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
LinearGengou.new(
|
159
|
+
start_date: start.clone, last_date: last.clone, gengou: this.gengou
|
160
|
+
)
|
161
|
+
end
|
162
162
|
end
|
163
|
-
private_class_method :shave_gengou
|
164
163
|
end
|
165
164
|
end
|
166
165
|
end
|
@@ -72,7 +72,7 @@ module Zakuro
|
|
72
72
|
#
|
73
73
|
def get(start_date:, last_date:)
|
74
74
|
result = []
|
75
|
-
|
75
|
+
list.each do |gengou|
|
76
76
|
next if gengou.out?(start_date: start_date, last_date: last_date)
|
77
77
|
|
78
78
|
# 1日でも範囲内であれば対象とみなす
|
@@ -91,7 +91,7 @@ module Zakuro
|
|
91
91
|
#
|
92
92
|
def get_by_name(name:)
|
93
93
|
result = []
|
94
|
-
|
94
|
+
list.each do |gengou|
|
95
95
|
result.push(gengou) if gengou.name == name
|
96
96
|
end
|
97
97
|
|
@@ -110,7 +110,8 @@ module Zakuro
|
|
110
110
|
def rest(list: [])
|
111
111
|
result = []
|
112
112
|
|
113
|
-
@list
|
113
|
+
inner_list = @list
|
114
|
+
inner_list.each do |gengou|
|
114
115
|
result |= and!(rest: list, other: gengou)
|
115
116
|
end
|
116
117
|
|
@@ -123,15 +124,16 @@ module Zakuro
|
|
123
124
|
# @param [Array<LinearGengou>] list 元号
|
124
125
|
#
|
125
126
|
def insert(list: [])
|
127
|
+
inner_list = @list
|
126
128
|
surplus_result = list.clone
|
127
|
-
|
129
|
+
inner_list.each do |gengou|
|
128
130
|
surplus_result = not!(surplus: surplus_result, other: gengou)
|
129
131
|
end
|
130
132
|
|
131
133
|
surplus_result = Division.connect(list: surplus_result)
|
132
134
|
|
133
135
|
surplus_result.each do |gengou|
|
134
|
-
|
136
|
+
inner_list.push(gengou)
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
@@ -45,7 +45,7 @@ module Zakuro
|
|
45
45
|
# @return [String] 元号名
|
46
46
|
#
|
47
47
|
def name
|
48
|
-
|
48
|
+
gengou.name
|
49
49
|
end
|
50
50
|
|
51
51
|
#
|
@@ -55,7 +55,7 @@ module Zakuro
|
|
55
55
|
# @return [False] 不正なし
|
56
56
|
#
|
57
57
|
def invalid?
|
58
|
-
|
58
|
+
gengou.invalid?
|
59
59
|
end
|
60
60
|
|
61
61
|
#
|
@@ -69,13 +69,13 @@ module Zakuro
|
|
69
69
|
def include?(date: Western::Calendar.new)
|
70
70
|
return false if invalid?
|
71
71
|
|
72
|
-
return false if
|
72
|
+
return false if start_date.invalid?
|
73
73
|
|
74
|
-
return false if
|
74
|
+
return false if last_date.invalid?
|
75
75
|
|
76
|
-
return false if date <
|
76
|
+
return false if date < start_date
|
77
77
|
|
78
|
-
return false if date >
|
78
|
+
return false if date > last_date
|
79
79
|
|
80
80
|
true
|
81
81
|
end
|
@@ -90,7 +90,9 @@ module Zakuro
|
|
90
90
|
# @return [False] 範囲外あり
|
91
91
|
#
|
92
92
|
def in?(start_date:, last_date:)
|
93
|
-
|
93
|
+
inner_start_date = @start_date
|
94
|
+
inner_last_date = @last_date
|
95
|
+
inner_start_date <= start_date && last_date <= inner_last_date
|
94
96
|
end
|
95
97
|
|
96
98
|
#
|
@@ -103,11 +105,13 @@ module Zakuro
|
|
103
105
|
# @return [False] 範囲内あり
|
104
106
|
#
|
105
107
|
def out?(start_date:, last_date:)
|
108
|
+
inner_start_date = @start_date
|
109
|
+
inner_last_date = @last_date
|
106
110
|
# 範囲より前
|
107
|
-
return true if start_date <
|
111
|
+
return true if start_date < inner_start_date && last_date < inner_start_date
|
108
112
|
|
109
113
|
# 範囲より後
|
110
|
-
return true if
|
114
|
+
return true if inner_last_date < start_date && inner_last_date < last_date
|
111
115
|
|
112
116
|
false
|
113
117
|
end
|
@@ -122,7 +126,9 @@ module Zakuro
|
|
122
126
|
# @return [True] 完全超過せず
|
123
127
|
#
|
124
128
|
def covered?(start_date:, last_date:)
|
125
|
-
|
129
|
+
inner_start_date = @start_date
|
130
|
+
inner_last_date = @last_date
|
131
|
+
start_date < inner_start_date && inner_last_date < last_date
|
126
132
|
end
|
127
133
|
|
128
134
|
#
|
@@ -148,7 +154,7 @@ module Zakuro
|
|
148
154
|
def change_start_date?
|
149
155
|
return false if invalid?
|
150
156
|
|
151
|
-
|
157
|
+
start_date != native_start_date
|
152
158
|
end
|
153
159
|
|
154
160
|
#
|
@@ -160,7 +166,7 @@ module Zakuro
|
|
160
166
|
def change_last_date?
|
161
167
|
return false if invalid?
|
162
168
|
|
163
|
-
|
169
|
+
last_date != native_last_date
|
164
170
|
end
|
165
171
|
|
166
172
|
#
|
@@ -169,7 +175,7 @@ module Zakuro
|
|
169
175
|
# @return [Western::Calendar]設定された元号の開始日
|
170
176
|
#
|
171
177
|
def native_start_date
|
172
|
-
|
178
|
+
gengou.both_start_date.western
|
173
179
|
end
|
174
180
|
|
175
181
|
#
|
@@ -178,7 +184,7 @@ module Zakuro
|
|
178
184
|
# @return [Western::Calendar] 設定された元号の終了日
|
179
185
|
#
|
180
186
|
def native_last_date
|
181
|
-
|
187
|
+
gengou.last_date
|
182
188
|
end
|
183
189
|
end
|
184
190
|
end
|
@@ -23,31 +23,33 @@ module Zakuro
|
|
23
23
|
# @return [Aligner] 整列結果
|
24
24
|
SUMMARY = Aligner.new(resources: Resource::LIST)
|
25
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
|
-
|
50
|
-
|
26
|
+
class << self
|
27
|
+
#
|
28
|
+
# 指定した範囲内の元号を取得する
|
29
|
+
#
|
30
|
+
# @param [Integer] line 行
|
31
|
+
# @param [Western::Calendar] start_date 開始日
|
32
|
+
# @param [Western::Calendar] last_date 終了日
|
33
|
+
#
|
34
|
+
# @return [Array<LinearGengou>] 元号
|
35
|
+
#
|
36
|
+
def get(line: FIRST_LINE,
|
37
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
38
|
+
|
39
|
+
SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# 指定した範囲内の元号を取得する(元号名)
|
44
|
+
#
|
45
|
+
# @param [Integer] line 行
|
46
|
+
# @param [String] name 元号名
|
47
|
+
#
|
48
|
+
# @return [Array<LinearGengou>] 元号
|
49
|
+
#
|
50
|
+
def get_by_name(line: FIRST_LINE, name:)
|
51
|
+
SUMMARY.get_by_name(line: line, name: name)
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -53,11 +53,11 @@ module Zakuro
|
|
53
53
|
# @return [Gengou] 元号情報
|
54
54
|
#
|
55
55
|
def create
|
56
|
-
|
57
|
-
|
56
|
+
start_year = Both::YearParser.new(hash: both_start_year).create
|
57
|
+
start_date = Both::DateParser.new(hash: both_start_date).create
|
58
58
|
|
59
|
-
Gengou.new(name:
|
60
|
-
both_start_date:
|
59
|
+
Gengou.new(name: name, both_start_year: start_year,
|
60
|
+
both_start_date: start_date)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -95,10 +95,10 @@ module Zakuro
|
|
95
95
|
# @return [Set] 元号セット情報
|
96
96
|
#
|
97
97
|
def create
|
98
|
-
|
98
|
+
last_date = Both::DateParser.new(hash: both_last_date).create
|
99
99
|
list = create_list
|
100
100
|
Set.new(
|
101
|
-
id:
|
101
|
+
id: id, name: name, both_last_date: last_date, list: list
|
102
102
|
)
|
103
103
|
end
|
104
104
|
|
@@ -111,7 +111,7 @@ module Zakuro
|
|
111
111
|
#
|
112
112
|
def create_list
|
113
113
|
result = []
|
114
|
-
|
114
|
+
list.each_with_index do |li, index|
|
115
115
|
gengou = GengouParser.new(hash: li, index: index).create
|
116
116
|
next_index = index + 1
|
117
117
|
gengou = calc_last_date_on_gengou_data(next_index: next_index,
|
@@ -122,24 +122,20 @@ module Zakuro
|
|
122
122
|
result
|
123
123
|
end
|
124
124
|
|
125
|
-
# :reek:TooManyStatements { max_statements: 6 }
|
126
|
-
|
127
125
|
#
|
128
126
|
# 次の元号の開始日から、元号の終了日に変換する
|
129
127
|
#
|
130
128
|
# @param [Integer] next_index 次の元号の要素位置
|
131
|
-
# @param [
|
129
|
+
# @param [GengouParser] gengou 元号
|
132
130
|
#
|
133
131
|
# @return [Gengou] 元号情報
|
134
132
|
#
|
135
133
|
def calc_last_date_on_gengou_data(next_index:, gengou:)
|
136
|
-
if next_index >=
|
137
|
-
gengou
|
138
|
-
last_date = Western::Calendar.parse(text: @both_last_date['western'])
|
139
|
-
gengou.write_last_date(last_date: last_date)
|
134
|
+
if next_index >= list.size
|
135
|
+
last_gengou_data(gengou: gengou)
|
140
136
|
return gengou
|
141
137
|
end
|
142
|
-
next_item =
|
138
|
+
next_item = list[next_index]
|
143
139
|
gengou.convert_next_start_year_to_last_year(
|
144
140
|
next_start_year: next_item['start_year']['western']
|
145
141
|
)
|
@@ -148,6 +144,19 @@ module Zakuro
|
|
148
144
|
)
|
149
145
|
gengou
|
150
146
|
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
#
|
151
|
+
# 最後の元号の終了日を設定する
|
152
|
+
#
|
153
|
+
# @param [GengouParser] gengou 元号
|
154
|
+
#
|
155
|
+
def last_gengou_data(gengou:)
|
156
|
+
gengou.write_last_year(last_year: both_last_year['western'])
|
157
|
+
last_date = Western::Calendar.parse(text: both_last_date['western'])
|
158
|
+
gengou.write_last_date(last_date: last_date)
|
159
|
+
end
|
151
160
|
end
|
152
161
|
|
153
162
|
#
|
@@ -179,10 +188,12 @@ module Zakuro
|
|
179
188
|
# @return [Both::Year] 年情報
|
180
189
|
#
|
181
190
|
def create
|
182
|
-
|
183
|
-
|
191
|
+
japan_year = japan.to_i
|
192
|
+
western_year = western.to_i
|
184
193
|
|
185
|
-
Japan::Gengou::Resource::Both::Year.new(
|
194
|
+
Japan::Gengou::Resource::Both::Year.new(
|
195
|
+
japan: japan_year, western: western_year
|
196
|
+
)
|
186
197
|
end
|
187
198
|
end
|
188
199
|
|
@@ -211,32 +222,36 @@ module Zakuro
|
|
211
222
|
# @return [Both::Date] 日情報
|
212
223
|
#
|
213
224
|
def create
|
214
|
-
|
215
|
-
|
225
|
+
japan_date = Japan::Calendar.parse(text: japan)
|
226
|
+
western_date = Western::Calendar.parse(text: western)
|
216
227
|
|
217
|
-
Japan::Gengou::Resource::Both::Date.new(
|
228
|
+
Japan::Gengou::Resource::Both::Date.new(
|
229
|
+
japan: japan_date, western: western_date
|
230
|
+
)
|
218
231
|
end
|
219
232
|
end
|
220
233
|
end
|
221
234
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
235
|
+
class << self
|
236
|
+
#
|
237
|
+
# 解析/展開する
|
238
|
+
#
|
239
|
+
# @param [String] filepath 元号セットファイルパス
|
240
|
+
#
|
241
|
+
# @return [Set] 元号セット情報
|
242
|
+
#
|
243
|
+
# @raise [ArgumentError] 引数エラー
|
244
|
+
#
|
245
|
+
def run(filepath: '')
|
246
|
+
yaml = YAML.load_file(filepath)
|
233
247
|
|
234
|
-
|
248
|
+
failed = Validator.run(yaml_hash: yaml)
|
235
249
|
|
236
|
-
|
250
|
+
raise ArgumentError, failed.join("\n") unless failed.empty?
|
237
251
|
|
238
|
-
|
239
|
-
|
252
|
+
parser = SetParser.new(hash: yaml)
|
253
|
+
parser.create
|
254
|
+
end
|
240
255
|
end
|
241
256
|
end
|
242
257
|
end
|