zakuro 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -1
  3. data/VERSION +1 -0
  4. data/doc/gengou.md +22 -22
  5. data/doc/operation/csv/month.csv +468 -202
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  8. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  9. data/lib/zakuro/calculation/base/operated_year.rb +104 -0
  10. data/lib/zakuro/calculation/base/year.rb +28 -13
  11. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +29 -29
  12. data/lib/zakuro/calculation/gengou/internal/counter.rb +129 -0
  13. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +183 -0
  14. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +382 -0
  15. data/lib/zakuro/calculation/gengou/internal/reserve.rb +42 -0
  16. data/lib/zakuro/calculation/gengou/scroll.rb +262 -0
  17. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  18. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  19. data/lib/zakuro/calculation/monthly/operated_month.rb +49 -5
  20. data/lib/zakuro/calculation/range/full_range.rb +65 -103
  21. data/lib/zakuro/calculation/range/operated_range.rb +73 -23
  22. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  23. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  24. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  25. data/lib/zakuro/calculation/specifier/single_day.rb +13 -35
  26. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +9 -7
  27. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +19 -0
  28. data/lib/zakuro/calculation/summary/single.rb +5 -2
  29. data/lib/zakuro/calculation/version/internal/crawler.rb +51 -0
  30. data/lib/zakuro/calculation/version/internal/range.rb +39 -0
  31. data/lib/zakuro/calculation/version/version.rb +24 -0
  32. data/lib/zakuro/era/japan/calendar.rb +133 -0
  33. data/lib/zakuro/era/japan/gengou/parser.rb +95 -25
  34. data/lib/zakuro/era/japan/gengou/type.rb +148 -41
  35. data/lib/zakuro/era/japan/gengou/validator.rb +157 -52
  36. data/lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml +1870 -0
  37. data/lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml +810 -0
  38. data/lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml +50 -0
  39. data/lib/zakuro/era/japan/gengou.rb +5 -5
  40. data/lib/zakuro/era/japan/version.rb +151 -0
  41. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  42. data/lib/zakuro/merchant.rb +12 -3
  43. data/lib/zakuro/operation/month/parser.rb +1 -1
  44. data/lib/zakuro/operation/month/type.rb +59 -1
  45. data/lib/zakuro/operation/month/validator.rb +1 -1
  46. data/lib/zakuro/operation/yaml/month.yaml +8512 -0
  47. data/lib/zakuro/output/response.rb +5 -5
  48. data/lib/zakuro/tools/typeconv.rb +38 -0
  49. data/lib/zakuro/tools/typeof.rb +4 -1
  50. data/lib/zakuro/version/context.rb +25 -4
  51. data/lib/zakuro/version/daien/const/number.rb +55 -0
  52. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  53. data/lib/zakuro/version/daien/cycle/remainder.rb +85 -0
  54. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  55. data/lib/zakuro/version/daien/daien.rb +11 -0
  56. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  57. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  58. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  59. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  60. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  61. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  62. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  63. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  64. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  65. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  66. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  67. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  68. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  69. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  70. data/lib/zakuro/version/genka/const/number.rb +43 -0
  71. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  72. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  73. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  74. data/lib/zakuro/version/genka/genka.rb +1 -9
  75. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  76. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  77. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  78. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  79. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  80. data/lib/zakuro/version/gihou/const/remainder.rb +0 -2
  81. data/lib/zakuro/version/gihou/cycle/remainder.rb +27 -6
  82. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  83. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +1 -1
  84. data/lib/zakuro/version/gihou/stella/lunar/location.rb +2 -8
  85. data/lib/zakuro/version/gihou/stella/lunar/value.rb +3 -2
  86. data/lib/zakuro/version/gihou/stella/solar/average.rb +3 -3
  87. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  88. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  89. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  90. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  91. data/lib/zakuro/version/senmyou/const/remainder.rb +0 -2
  92. data/lib/zakuro/version/senmyou/cycle/remainder.rb +27 -6
  93. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
  94. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  95. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +2 -8
  96. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +3 -2
  97. data/lib/zakuro/version/senmyou/stella/solar/average.rb +3 -3
  98. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  99. data/lib/zakuro/version/version_class_resolver.rb +8 -0
  100. data/zakuro.gemspec +1 -3
  101. metadata +50 -14
  102. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  103. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  104. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  105. data/lib/zakuro/era/japan/reki.rb +0 -91
  106. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  107. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  108. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  109. data/lib/zakuro/version/abstract_version.rb +0 -29
  110. data/lib/zakuro/version/taien/taien.rb +0 -19
  111. data/lib/zakuro/version.rb +0 -7
  112. data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,262 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../era/western/calendar'
4
+ require_relative '../base/gengou'
5
+ require_relative '../base/linear_gengou'
6
+ require_relative './internal/reserve/interval'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Calculation
12
+ # :nodoc:
13
+ module Gengou
14
+ # Scroll
15
+ #
16
+ # 元号スクロール
17
+ #
18
+ class Scroll
19
+ # @return [Western::Calendar] 月初日
20
+ attr_reader :monthly_start_date
21
+ # @return [Western::Calendar] 月末日
22
+ attr_reader :monthly_end_date
23
+ # @return [Reserve::Interval] 予約範囲
24
+ attr_reader :interval
25
+ # @return [Array<Counte>] 1行目元号
26
+ attr_reader :first_gengou
27
+ # @return [Array<Counte>] 2行目元号
28
+ attr_reader :second_gengou
29
+
30
+ #
31
+ # 初期化
32
+ #
33
+ # @param [Western::Calendar] start_date 西暦開始日(最大範囲)
34
+ # @param [Western::Calendar] end_date 西暦終了日(最大範囲)
35
+ #
36
+ def initialize(start_date: Western::Calendar.new, end_date: Western::Calendar.new)
37
+ @monthly_start_date = Western::Calendar.new
38
+ @monthly_end_date = Western::Calendar.new
39
+ @interval = Reserve::Interval.new(start_date: start_date, end_date: end_date)
40
+ @first_gengou = []
41
+ @second_gengou = []
42
+ @ignited = false
43
+ end
44
+
45
+ #
46
+ # 進める
47
+ #
48
+ # @param [Monthly::Month] month 月
49
+ #
50
+ def run(month:)
51
+ unless @ignited
52
+ # 開始日の検索を行う
53
+ @ignited = ignite(month: month)
54
+ return
55
+ end
56
+
57
+ # 時間を進める
58
+ advance(month: month)
59
+ end
60
+
61
+ #
62
+ # 元号開始を試みる
63
+ #
64
+ # @param [Monthly::Month] month 月
65
+ #
66
+ # @return [True] 開始あり
67
+ # @return [False] 開始なし
68
+ #
69
+ def ignite(month:)
70
+ return false unless ignitable?(month: month)
71
+
72
+ japan_start_date = @interval.japan_start_date
73
+
74
+ western_start_date = @interval.western_start_date
75
+
76
+ # 今月初日(和暦日が1月2日であれば、開始日の1日前が初日)
77
+ @monthly_start_date = western_start_date.clone - japan_start_date.day + 1
78
+
79
+ # 今月末
80
+ @monthly_end_date = @monthly_start_date.clone + month.days - 1
81
+
82
+ update_current_gengou
83
+
84
+ true
85
+ end
86
+
87
+ #
88
+ # 進める
89
+ #
90
+ # @param [Monthly::Month] month 月
91
+ #
92
+ def advance(month:)
93
+ @monthly_start_date = @monthly_end_date.clone + 1
94
+
95
+ @monthly_end_date = @monthly_start_date.clone + month.days - 1
96
+
97
+ next_year if month.number == 1 && !month.leaped?
98
+
99
+ update_current_gengou
100
+ end
101
+
102
+ #
103
+ # 共通の元号に変換する
104
+ #
105
+ # @return [Base::Gengou] 元号
106
+ #
107
+ def to_gengou
108
+ start_date = @monthly_start_date.clone
109
+ end_date = @monthly_end_date.clone
110
+
111
+ Base::Gengou.new(
112
+ start_date: start_date,
113
+ end_date: end_date,
114
+ first_line: to_linear_gengou(
115
+ start_date: start_date, end_date: end_date, gengou_list: @first_gengou
116
+ ),
117
+ second_line: to_linear_gengou(
118
+ start_date: start_date, end_date: end_date, gengou_list: @second_gengou
119
+ )
120
+ )
121
+ end
122
+
123
+ #
124
+ # 開始西暦年を取得する
125
+ #
126
+ # @return [Integer] 開始西暦年
127
+ #
128
+ def western_start_year
129
+ @interval.western_start_year
130
+ end
131
+
132
+ #
133
+ # 終了西暦年を取得する
134
+ #
135
+ # @return [Integer] 終了西暦年
136
+ #
137
+ def western_end_year
138
+ @interval.western_end_year
139
+ end
140
+
141
+ private
142
+
143
+ #
144
+ # 現在月に合わせて元号を更新する
145
+ #
146
+ def update_current_gengou
147
+ start_date = @monthly_start_date
148
+ end_date = @monthly_end_date
149
+ first_gengou = @interval.collect_first_gengou(start_date: start_date, end_date: end_date)
150
+ second_gengou = @interval.collect_second_gengou(start_date: start_date,
151
+ end_date: end_date)
152
+
153
+ @first_gengou = replace_gengou(source: @first_gengou, destination: first_gengou)
154
+ @second_gengou = replace_gengou(source: @second_gengou, destination: second_gengou)
155
+ end
156
+
157
+ #
158
+ # 元号を差し替える
159
+ #
160
+ # @param [Array<Counter>] source 元の元号
161
+ # @param [Array<Counter>] destination 次の元号
162
+ #
163
+ # @return [Array<Counter>] 差し替え結果
164
+ #
165
+ def replace_gengou(source: [], destination: [])
166
+ return destination if destination.size.zero?
167
+
168
+ return destination if source.size.zero?
169
+
170
+ last = source[-1]
171
+ destination[0] = last if destination[0].name == last.name
172
+
173
+ destination
174
+ end
175
+
176
+ #
177
+ # 直列元号に変換する
178
+ #
179
+ # * 最初の元号:開始日~その元号の終了日
180
+ # * 中間の元号:その元号の開始日~その元号の終了日
181
+ # * 最後の元号:その元号の開始日~終了日
182
+ #
183
+ # @param [Western::Calendar] start_date 西暦開始日
184
+ # @param [Western::Calendar] end_date 西暦終了日
185
+ # @param [Array<Counter>] gengou_list 元号リスト
186
+ #
187
+ # @return [Array<Base::Gengou>] 元号リスト
188
+ #
189
+ def to_linear_gengou(start_date:, end_date:, gengou_list: [])
190
+ return [] if gengou_list.size.zero?
191
+
192
+ result = []
193
+
194
+ gengou_list.each do |gengou|
195
+ if gengou.invalid?
196
+ # 無効元号は無効のままにする
197
+ result.push(Base::LinearGengou.new)
198
+ next
199
+ end
200
+
201
+ linear_gengou = to_limited_linear_gengou(
202
+ start_date: start_date,
203
+ end_date: end_date,
204
+ gengou: gengou
205
+ )
206
+ result.push(linear_gengou)
207
+ end
208
+
209
+ result
210
+ end
211
+
212
+ #
213
+ # 範囲を限定した直列元号に変換する
214
+ #
215
+ # * 開始日・終了日により範囲を狭める
216
+ #
217
+ # @param [Western::Calendar] start_date 西暦開始日
218
+ # @param [Western::Calendar] end_date 西暦終了日
219
+ # @param [Counter] gengou 加算元号
220
+ #
221
+ # @return [Base::Gengou] 元号
222
+ #
223
+ def to_limited_linear_gengou(start_date:, end_date:, gengou:)
224
+ gengou_start_date = gengou.western_start_date.clone
225
+ gengou_end_date = gengou.western_end_date.clone
226
+
227
+ gengou_start_date = start_date.clone if start_date > gengou_start_date
228
+ gengou_end_date = end_date.clone if end_date < gengou_end_date
229
+
230
+ Base::LinearGengou.new(
231
+ start_date: gengou_start_date, end_date: gengou_end_date,
232
+ name: gengou.name, year: gengou.japan_year
233
+ )
234
+ end
235
+
236
+ #
237
+ # 開始可能か
238
+ #
239
+ # @param [Monthly::Month] month 月
240
+ #
241
+ # @return [True] 開始可
242
+ # @return [True] 開始不可
243
+ #
244
+ def ignitable?(month:)
245
+ return false unless @monthly_start_date.invalid?
246
+
247
+ japan_start_date = @interval.japan_start_date
248
+
249
+ japan_start_date.same_month?(leaped: month.leaped?, month: month.number)
250
+ end
251
+
252
+ #
253
+ # 次年にする
254
+ #
255
+ def next_year
256
+ @first_gengou.each(&:next_year)
257
+ @second_gengou.each(&:next_year)
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../era/western'
3
+ require_relative '../../era/western/calendar'
4
4
 
5
5
  # :nodoc:
6
6
  module Zakuro
@@ -23,7 +23,8 @@ module Zakuro
23
23
  # @param [Remainder] remainder 西暦日
24
24
  # @param [Western::Calendar] western_date 大余小余
25
25
  #
26
- def initialize(western_date: Western::Calendar.new, remainder: Remainder.new)
26
+ def initialize(western_date: Western::Calendar.new,
27
+ remainder: Calculation::Cycle::AbstractRemainder.new)
27
28
  # 西暦日
28
29
  @western_date = western_date
29
30
  # 大余小余
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../base/gengou'
3
4
  require_relative './first_day'
4
5
  require_relative './month_label'
5
6
 
@@ -21,6 +22,8 @@ module Zakuro
21
22
  attr_reader :first_day
22
23
  # @return [Array<SolarTerm>] 二十四節気
23
24
  attr_reader :solar_terms
25
+ # @return [Base::Gengou] 元号
26
+ attr_reader :gengou
24
27
 
25
28
  #
26
29
  # 初期化
@@ -29,13 +32,25 @@ module Zakuro
29
32
  # @param [MonthLabel] month_label 月表示名
30
33
  # @param [FirstDay] first_day 月初日(朔日)
31
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
35
+ # @param [Base::Gengou] gengou 元号
32
36
  #
33
- def initialize(context:, month_label: MonthLabel.new, first_day: FirstDay.new,
34
- solar_terms: [])
37
+ def initialize(context: Context.new, month_label: MonthLabel.new, first_day: FirstDay.new,
38
+ solar_terms: [], gengou: Base::Gengou.new)
35
39
  @context = context
36
40
  @month_label = month_label
37
41
  @first_day = first_day
38
42
  @solar_terms = solar_terms
43
+ @gengou = gengou
44
+ end
45
+
46
+ #
47
+ # 不正か
48
+ #
49
+ # @return [True] 不正
50
+ # @return [False] 不正なし
51
+ #
52
+ def invalid?
53
+ @context.invalid?
39
54
  end
40
55
 
41
56
  #
@@ -181,6 +196,38 @@ module Zakuro
181
196
  def same?(other:)
182
197
  number == other.number && leaped? == other.leaped?
183
198
  end
199
+
200
+ #
201
+ # 月の終了日を返す
202
+ #
203
+ # @return [Western::Calendar] 月の終了日
204
+ #
205
+ def end_date
206
+ return Western::Calendar.new if western_date.invalid?
207
+
208
+ western_date.clone + days - 1
209
+ end
210
+
211
+ #
212
+ # 範囲内か
213
+ #
214
+ # @param [Western::Calendar] date 日付
215
+ #
216
+ # @return [True] 範囲内
217
+ # @return [False] 範囲外
218
+ #
219
+ def include?(date:)
220
+ return false if invalid?
221
+
222
+ start_date = western_date
223
+ return false if start_date.invalid?
224
+
225
+ return false if date < start_date
226
+
227
+ return false if date > end_date
228
+
229
+ true
230
+ end
184
231
  end
185
232
  end
186
233
  end
@@ -9,7 +9,7 @@ module Zakuro
9
9
  module Calculation
10
10
  # :nodoc:
11
11
  module Monthly
12
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
12
+ # :reek:TooManyInstanceVariables { max_instance_variables: 6 }
13
13
 
14
14
  #
15
15
  # OperatedMonth 月情報(運用)
@@ -34,12 +34,13 @@ module Zakuro
34
34
  # @param [Operation::MonthHistory] history 変更履歴(月)
35
35
  #
36
36
  def initialize(context:, operated_solar_terms:, month_label: MonthLabel.new,
37
- first_day: FirstDay.new, solar_terms: [],
37
+ first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
38
38
  history: Operation::MonthHistory.new)
39
39
  super(context: context, month_label: month_label, first_day: first_day,
40
- solar_terms: solar_terms)
40
+ solar_terms: solar_terms, gengou: gengou)
41
41
  @history = history
42
42
  @operated_solar_terms = operated_solar_terms
43
+ @moved = false
43
44
  end
44
45
 
45
46
  # rubocop:enable Metrics/ParameterLists
@@ -99,9 +100,9 @@ module Zakuro
99
100
  end
100
101
 
101
102
  #
102
- # <Description>
103
+ # 運用情報によって改変した二十四節気を作成する
103
104
  #
104
- # @param [<Type>] operated_solar_term <description>
105
+ # @param [<Type>] operated_solar_term 運用情報(二十四節気)
105
106
  # @param [Array<SolarTerm>] solar_terms 二十四節気
106
107
  #
107
108
  # @return [Array<SolarTerm>] 二十四節気
@@ -203,6 +204,49 @@ module Zakuro
203
204
 
204
205
  western_date
205
206
  end
207
+
208
+ #
209
+ # 運用情報では昨年の月か
210
+ #
211
+ # @return [True] 昨年の月
212
+ # @return [False] 今年/来年の月
213
+ #
214
+ def last_year?
215
+ history_month_number.last_year?
216
+ end
217
+
218
+ #
219
+ # 運用情報では来年の月か
220
+ #
221
+ # @return [True] 来年の月
222
+ # @return [False] 今年/昨年の月
223
+ #
224
+ def next_year?
225
+ history_month_number.next_year?
226
+ end
227
+
228
+ #
229
+ # 別の年に移動したか
230
+ #
231
+ # @return [True] 移動済
232
+ # @return [False] 移動なし
233
+ #
234
+ def moved?
235
+ @moved
236
+ end
237
+
238
+ #
239
+ # 移動済とする
240
+ #
241
+ def moved
242
+ @moved = true
243
+ end
244
+
245
+ private
246
+
247
+ def history_month_number
248
+ @history.diffs.month.number
249
+ end
206
250
  end
207
251
  end
208
252
  end
@@ -1,13 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../era/western'
3
+ require_relative '../../version/context'
4
+
5
+ require_relative '../../era/western/calendar'
4
6
  require_relative '../../output/logger'
5
7
 
6
- require_relative '../base/multi_gengou_roller'
8
+ require_relative '../gengou/scroll'
9
+
10
+ require_relative '../base/gengou'
7
11
  require_relative '../base/year'
8
12
 
13
+ require_relative '../version/version'
14
+
9
15
  require_relative './transfer/year_boundary'
10
- require_relative './transfer/western_date_allocation'
16
+
17
+ require_relative './transfer/gengou_scroller'
11
18
 
12
19
  # :nodoc:
13
20
  module Zakuro
@@ -37,11 +44,7 @@ module Zakuro
37
44
  # @return [Western::Calendar] 終了日
38
45
  attr_reader :end_date
39
46
  # @return [MultiGengouRoller] 改元処理
40
- attr_reader :multi_gengou_roller
41
- # @return [Western::Calendar] 最過去の元旦
42
- attr_reader :new_year_date
43
- # @return [Integer] 西暦年
44
- attr_reader :western_year
47
+ attr_reader :scroll
45
48
 
46
49
  # @return [Output::Logger] ロガー
47
50
  LOGGER = Output::Logger.new(location: 'full_range')
@@ -58,12 +61,9 @@ module Zakuro
58
61
  @end_date = end_date
59
62
  return if invalid?
60
63
 
64
+ # TODO: 現時点では使用していない。特定の暦を指定できるようになった状態で使用する
61
65
  @context = context
62
- @multi_gengou_roller = Base::MultiGengouRoller.new(
63
- start_date: start_date, end_date: end_date
64
- )
65
- @new_year_date = @multi_gengou_roller.oldest_date.clone
66
- @western_year = @new_year_date.year
66
+ @scroll = Gengou::Scroll.new(start_date: start_date, end_date: end_date)
67
67
  end
68
68
 
69
69
  #
@@ -79,130 +79,92 @@ module Zakuro
79
79
  #
80
80
  # 完全範囲を取得する
81
81
  #
82
- # @return [Array<Year>] 完全範囲
82
+ # @return [Array<Base::Year>] 完全範囲
83
83
  #
84
84
  def get
85
85
  return [] if invalid?
86
86
 
87
- years = Transfer::YearBoundary.get(
88
- context: @context, annual_ranges: annual_ranges
89
- )
90
- years = update_gengou(years: years)
91
-
92
- Transfer::WesternDateAllocation.update_first_day(
93
- context: @context, years: years
94
- )
95
-
96
- years
97
- end
87
+ years = version_ranges
98
88
 
99
- # :reek:TooManyStatements { max_statements: 7 }
100
-
101
- #
102
- # 完全範囲内の年データを取得する
103
- #
104
- # @return [Array<Year>] 年データ(冬至基準)
105
- #
106
- def annual_ranges
107
- oldest_date = @new_year_date
108
- newest_date = @multi_gengou_roller.newest_date
109
- annual_range = context.resolver.annual_range
89
+ years.each(&:commit)
110
90
 
111
- years = []
112
- ((oldest_date.year)..(newest_date.year + 2)).each do |year|
113
- years.push(
114
- annual_range.get(
115
- context: @context, western_year: year
116
- )
117
- )
118
- end
91
+ Transfer::GengouScroller.set(scroll: scroll, years: years)
119
92
 
120
93
  years
121
94
  end
122
95
 
123
- # :reek:TooManyStatements { max_statements: 8 }
96
+ private
124
97
 
125
98
  #
126
- # 完全範囲内の年データの元号を開始年基準で更新する
127
- #
128
- # @param [Array<Year>] years 年データ(元旦基準)
99
+ # 暦別範囲
129
100
  #
130
- # @return [Array<Year>] 元号更新済み年データ(元旦基準)
101
+ # @return [Array<Base::Year>] 完全範囲
131
102
  #
132
- def update_gengou(years:)
133
- updated_years = []
103
+ def version_ranges
104
+ result = []
134
105
 
135
- nearest_end_date = choise_nearest_end_date
106
+ start_year = @scroll.western_start_year
107
+ end_year = @scroll.western_end_year
136
108
 
137
- years.each do |year|
138
- next_year(years: updated_years, year: year)
109
+ versions = Version.get(start_year: start_year, end_year: end_year)
139
110
 
140
- if @new_year_date > nearest_end_date
141
- @multi_gengou_roller.transfer
142
- nearest_end_date = choise_nearest_end_date
143
- end
144
- @multi_gengou_roller.next_year
145
- end
146
-
147
- updated_years
148
- end
111
+ versions.each_with_index do |version, index|
112
+ context = Context.new(version_name: version.name)
113
+ start_year = version.start_year
114
+ end_year = version.end_year
115
+ # 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
116
+ end_year += 1 if (index + 1) == versions.size
149
117
 
150
- private
151
-
152
- #
153
- # 元号処理対象の年を進める
154
- #
155
- # @param [Array<Year>] years 元号処理済み年データ(元旦基準)
156
- # @param [Year] year 元号処理前の年(元旦基準)
157
- #
158
- def next_year(years:, year:)
159
- updated_year = update_year(year: year)
160
-
161
- years.push(updated_year)
162
-
163
- next_new_year_date(total_days: updated_year.total_days)
118
+ years = boundary_resolved_ranges(
119
+ context: context, start_year: start_year, end_year: end_year
120
+ )
121
+ result.concat(years)
122
+ end
164
123
 
165
- nil
124
+ result
166
125
  end
167
126
 
168
127
  #
169
- # 年の元号を更新する
128
+ # 年境界解決済みの範囲
170
129
  #
171
- # @param [Year] year 元号処理前の年(元旦基準)
130
+ # @param [Context] context 暦コンテキスト
131
+ # @param [Integer] start_year 開始西暦年
132
+ # @param [Integer] end_year 終了西暦年
172
133
  #
173
- # @return [Year] 元号処理済の年(元旦基準)
134
+ # @return [Array<Base::Year>] 年境界解決済みの範囲
174
135
  #
175
- def update_year(year:)
176
- multi_gengou = @multi_gengou_roller.multi_gengou.clone
177
-
178
- updated_year = Base::Year.new(
179
- multi_gengou: multi_gengou, new_year_date: @new_year_date.clone,
180
- months: year.months
136
+ def boundary_resolved_ranges(context:, start_year:, end_year:)
137
+ ranges = annual_ranges(
138
+ context: context, start_year: start_year, end_year: end_year
181
139
  )
182
- updated_year.commit
183
140
 
184
- updated_year
141
+ Transfer::YearBoundary.get(
142
+ context: context, annual_ranges: ranges
143
+ )
185
144
  end
186
145
 
187
146
  #
188
- # 次の年に進める
147
+ # 完全範囲内の年データを取得する
189
148
  #
190
- # @param [Integer] total_days 年の日数
149
+ # @param [Context] context 暦コンテキスト
150
+ # @param [Integer] start_year 開始西暦年
151
+ # @param [Integer] end_year 終了西暦年
191
152
  #
192
- def next_new_year_date(total_days:)
193
- @new_year_date += total_days
194
- @multi_gengou_roller.next(days: total_days)
153
+ # @return [Array<Base::Year>] 年データ(冬至基準)
154
+ #
155
+ def annual_ranges(context:, start_year:, end_year:)
156
+ annual_range = context.resolver.annual_range
195
157
 
196
- nil
197
- end
158
+ years = []
159
+ (start_year..(end_year + 1)).each do |year|
160
+ years.push(
161
+ annual_range.get(
162
+ context: context, western_year: year
163
+ )
164
+ )
165
+ end
198
166
 
199
- #
200
- # 現在日からみて直近の未来に対する元号の切替前日を求める
201
- #
202
- # @return [Western::Calendar] 元号の切替前日
203
- #
204
- def choise_nearest_end_date
205
- @multi_gengou_roller.choise_nearest_end_date
167
+ years
206
168
  end
207
169
  end
208
170
  end