zakuro 0.1.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -1
  3. data/doc/gengou.md +22 -22
  4. data/doc/operation/csv/month.csv +468 -202
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/lib/zakuro/calculation/base/operated_year.rb +114 -0
  7. data/lib/zakuro/calculation/base/year.rb +3 -0
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +29 -29
  9. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  10. data/lib/zakuro/calculation/monthly/first_day.rb +1 -1
  11. data/lib/zakuro/calculation/monthly/operated_month.rb +47 -3
  12. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  13. data/lib/zakuro/calculation/range/operated_range.rb +61 -16
  14. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +78 -0
  15. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +71 -0
  16. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  17. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  18. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  19. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  20. data/lib/zakuro/era/japan/reki.rb +1 -1
  21. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +22 -22
  22. data/lib/zakuro/operation/month/type.rb +58 -0
  23. data/lib/zakuro/operation/yaml/month.yaml +8512 -0
  24. data/lib/zakuro/version/context.rb +1 -1
  25. data/lib/zakuro/version/daien/const/number.rb +55 -0
  26. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  27. data/lib/zakuro/version/daien/cycle/remainder.rb +85 -0
  28. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  29. data/lib/zakuro/version/daien/daien.rb +36 -0
  30. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  31. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  32. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  33. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  34. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  35. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  36. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  37. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  38. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  39. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  40. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  41. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  42. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  43. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  44. data/lib/zakuro/version/genka/const/number.rb +43 -0
  45. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  46. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  47. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  48. data/lib/zakuro/version/genka/genka.rb +19 -2
  49. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  50. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  51. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  52. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  53. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  54. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  55. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  56. data/lib/zakuro/version/gihou/cycle/remainder.rb +82 -0
  57. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  58. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  59. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  60. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  61. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  62. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  63. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  64. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  65. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  66. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  67. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  68. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  69. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  70. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  71. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  72. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  73. data/lib/zakuro/version/senmyou/const/number.rb +1 -1
  74. data/lib/zakuro/version/senmyou/const/remainder.rb +7 -3
  75. data/lib/zakuro/version/senmyou/cycle/remainder.rb +27 -6
  76. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +4 -1
  77. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +12 -112
  78. data/lib/zakuro/version/senmyou/range/annual_range.rb +5 -77
  79. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +2 -3
  80. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +13 -34
  81. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +8 -30
  82. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +29 -29
  83. data/lib/zakuro/version/senmyou/stella/solar/average.rb +14 -92
  84. data/lib/zakuro/version/senmyou/stella/solar/location.rb +18 -121
  85. data/lib/zakuro/version/senmyou/stella/solar/value.rb +4 -103
  86. data/lib/zakuro/version/version_class_resolver.rb +12 -0
  87. data/lib/zakuro/version.rb +1 -1
  88. data/lib/zakuro/version_factory.rb +1 -1
  89. metadata +61 -7
  90. data/lib/zakuro/version/taien/taien.rb +0 -19
Binary file
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './year'
4
+ require_relative './multi_gengou'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Base
12
+ #
13
+ # OperatedYear 年(運用)
14
+ #
15
+ class OperatedYear < Year
16
+ #
17
+ # 初期化
18
+ #
19
+ # @param [Gengou] multi_gengou 元号
20
+ # @param [Array<OperatedMonth>] months 年内の全ての月
21
+ # @param [Integer] total_days 年の日数
22
+ # @param [Western::Calendar] new_year_date 元旦
23
+ #
24
+ def initialize(multi_gengou: MultiGengou.new, new_year_date: Western::Calendar.new,
25
+ months: [], total_days: 0)
26
+ super(multi_gengou: multi_gengou, new_year_date: new_year_date,
27
+ months: months, total_days: total_days)
28
+ end
29
+
30
+ def commit
31
+ super
32
+
33
+ return if months.empty?
34
+
35
+ @new_year_date = months[0].first_day.western_date
36
+ end
37
+
38
+ #
39
+ # 引数を月の先頭に加える
40
+ #
41
+ # @param [Array<OperatedMonth>] first_months 先頭の月
42
+ #
43
+ def unshift_months(first_months)
44
+ # 逆順で加える
45
+ first_months.reverse_each do |month|
46
+ month.moved
47
+ months.unshift(month)
48
+ end
49
+ end
50
+
51
+ #
52
+ # 引数を月の最後に加える
53
+ #
54
+ # @param [Array<OperatedMonth>] last_months 最後の月
55
+ #
56
+ def push_months(last_months)
57
+ last_months.each do |month|
58
+ month.moved
59
+ months.push(month)
60
+ end
61
+ end
62
+
63
+ #
64
+ # 昨年に属する月を取り出す
65
+ #
66
+ # @return [Array<OperatedMonth>] 昨年に属する月
67
+ #
68
+ def shift_last_year_months
69
+ result, @months = OperatedYear.devide_with(method: :last_year?, arr: months)
70
+
71
+ result
72
+ end
73
+
74
+ #
75
+ # 来年に属する月を取り出す
76
+ #
77
+ # @return [Array<OperatedMonth>] 来年に属する月
78
+ #
79
+ def pop_next_year_months
80
+ result, @months = OperatedYear.devide_with(method: :next_year?, arr: months)
81
+
82
+ result
83
+ end
84
+
85
+ # :reek:TooManyStatements { max_statements: 8 }
86
+
87
+ #
88
+ # メソッドで配列を分離する
89
+ #
90
+ # @param [Symbol] method 条件メソッド
91
+ # @param [Array<Object>] arr 配列
92
+ #
93
+ # @return [Array<Object>] 一致配列
94
+ # @return [Array<Object>] 不一致配列
95
+ #
96
+ def self.devide_with(method:, arr: [])
97
+ match = []
98
+ unmatch = []
99
+
100
+ arr.each do |item|
101
+ if !item.moved? && item.send(method)
102
+ match.push(item)
103
+ next
104
+ end
105
+
106
+ unmatch.push(item)
107
+ end
108
+
109
+ [match, unmatch]
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -25,6 +25,9 @@ module Zakuro
25
25
  # 初期化
26
26
  #
27
27
  # @param [Gengou] multi_gengou 元号
28
+ # @param [Array<Month>] months 年内の全ての月
29
+ # @param [Integer] total_days 年の日数
30
+ # @param [Western::Calendar] new_year_date 元旦
28
31
  #
29
32
  def initialize(multi_gengou: MultiGengou.new, new_year_date: Western::Calendar.new,
30
33
  months: [], total_days: 0)
@@ -10,6 +10,11 @@ module Zakuro
10
10
  # 大余小余(時刻情報)
11
11
  # @abstract 大余小余計算に必要な処理を行う、暦に依存しない汎用的なクラス
12
12
  #
13
+ # * 十干十二支(60日)を上限とした「日時分秒」の情報で、日付(date)/時刻(time)と部分的に重なる概念
14
+ # * 「15日1012分5秒」のような形式で表される
15
+ # * 分の上限で大余に繰り上げる
16
+ # * 秒の上限で1分に繰り上げる
17
+ #
13
18
  class AbstractRemainder # rubocop:disable Metrics/ClassLength
14
19
  # @return [Integer] 大余上限
15
20
  LIMIT = 60
@@ -224,8 +229,7 @@ module Zakuro
224
229
  # @return [False] より小さい
225
230
  #
226
231
  def >=(other)
227
- up?(other) || \
228
- (@day == other.day && @minute == other.minute && @second == other.second)
232
+ up?(other) || eql?(other)
229
233
  end
230
234
 
231
235
  #
@@ -249,8 +253,7 @@ module Zakuro
249
253
  # @return [False] より大きい
250
254
  #
251
255
  def <=(other)
252
- down?(other) || \
253
- (@day == other.day && @minute == other.minute && @second == other.second)
256
+ down?(other) || eql?(other)
254
257
  end
255
258
 
256
259
  #
@@ -339,10 +342,19 @@ module Zakuro
339
342
  # @return [Integer] 小余(秒切り捨て)
340
343
  #
341
344
  def floor_minute
342
- result = @minute + @second / @base_minute
345
+ result = float_minute
343
346
  result.floor
344
347
  end
345
348
 
349
+ #
350
+ # 秒を含めた小余を返す
351
+ #
352
+ # @return [Float] 小余
353
+ #
354
+ def float_minute
355
+ @minute + @second.to_f / @base_minute
356
+ end
357
+
346
358
  #
347
359
  # 大余に四捨五入した結果を返す(秒は除外する)
348
360
  #
@@ -365,26 +377,18 @@ module Zakuro
365
377
  end
366
378
 
367
379
  #
368
- # 特定の文字フォーマットにして出力する
380
+ # 繰り上げる
369
381
  #
370
- # @param [String] form フォーマット(大余、小余、秒それぞれを%dで指定する)
382
+ # @return [AbstractRemainder] 繰り上げ結果
371
383
  #
372
- # @return [String] フォーマットした結果
373
- #
374
- def format(form: '%d-%d')
375
- return '' if invalid?
384
+ def carry!
385
+ @day, @minute, @second = carry(@day, @minute, @second)
376
386
 
377
- super(form, @day, @minute, @second)
387
+ self
378
388
  end
379
389
 
380
390
  private
381
391
 
382
- def carry!(day, minute, second)
383
- @day, @minute, @second = carry(day, minute, second)
384
-
385
- self
386
- end
387
-
388
392
  # 繰り上げ、繰り下げ
389
393
  def carry(param_day, param_minute, param_second)
390
394
  # NOTE: 計算方法としてマイナスでも徐算・剰余算の結果をプラス同様に扱う
@@ -437,33 +441,29 @@ module Zakuro
437
441
  def up?(other)
438
442
  invalid?(param: other)
439
443
  day = other.day
440
- minute = other.minute
444
+ minute = other.float_minute
445
+
441
446
  return true if @day > day
442
447
  return false if @day < day
443
448
 
444
- return true if @minute > minute
445
- return false if @minute < minute
446
-
447
- @second > other.second
449
+ float_minute > minute
448
450
  end
449
451
 
450
452
  def eql?(other)
451
453
  invalid?(param: other)
452
454
 
453
- (@day == other.day && @minute == other.minute && @second == other.second)
455
+ (@day == other.day && float_minute == other.float_minute)
454
456
  end
455
457
 
456
458
  def down?(other)
457
459
  invalid?(param: other)
458
460
  day = other.day
459
- minute = other.minute
461
+ minute = other.float_minute
462
+
460
463
  return true if @day < day
461
464
  return false if @day > day
462
465
 
463
- return true if @minute < minute
464
- return false if @minute > minute
465
-
466
- @second < other.second
466
+ float_minute < minute
467
467
  end
468
468
  end
469
469
  end
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../output/logger'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Monthly
11
+ #
12
+ # AbstractLunarPhase 月の位相
13
+ #
14
+ class AbstractLunarPhase
15
+ # @return [Output::Logger] ロガー
16
+ LOGGER = Output::Logger.new(location: 'lunar_phase')
17
+
18
+ # @return [Array<String>] 月内の弦
19
+ PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
20
+
21
+ # @return [Cycle::AbstractRemainder] 経
22
+ attr_reader :average_remainder
23
+ # @return [Solar::AbstractLocation] 入定気
24
+ attr_reader :solar_location
25
+ # @return [Lunar::AbstractLocation] 入暦
26
+ attr_reader :lunar_location
27
+ # @return [Integer] 弦の位置
28
+ attr_reader :index
29
+
30
+ #
31
+ # 初期化
32
+ #
33
+ # @param [Cycle::AbstractRemainder] quater 弦
34
+ # @param [Solar::AbstractLocation] average_remainder 経
35
+ # @param [Solar::AbstractLocation] solar_location 入定気
36
+ # @param [Lunar::AbstractLocation] lunar_location 入暦
37
+ #
38
+ def initialize(quater:, average_remainder:, solar_location:, lunar_location:)
39
+ # 弦
40
+ @quarter = quater
41
+ # 経
42
+ @average_remainder = average_remainder
43
+ # 入定気
44
+ @solar_location = solar_location
45
+ # 入暦
46
+ @lunar_location = lunar_location
47
+
48
+ # 弦の位置
49
+ @index = 0
50
+ end
51
+
52
+ #
53
+ # 次の弦に進める
54
+ #
55
+ # @return [Remainder] 定朔
56
+ #
57
+ def next_phase
58
+ adjusted = current_remainder
59
+
60
+ add_quarter_moon_size
61
+
62
+ adjusted
63
+ end
64
+
65
+ #
66
+ # 次の月に進める
67
+ # @note 進めた後の月の定朔ではなく、当月のものを返却する
68
+ #
69
+ # @return [Remainder] 当月初の定朔
70
+ #
71
+ def next_month
72
+ result = nil
73
+ PHASE_INDEXES.each_with_index do |_phase, index|
74
+ adjust = next_phase
75
+ result = adjust if index.zero?
76
+ end
77
+
78
+ result
79
+ end
80
+
81
+ private
82
+
83
+ #
84
+ # 次の弦に進める
85
+ #
86
+ # @return [Integer] 弦
87
+ #
88
+ def next_index
89
+ @index += 1
90
+ @index = 0 if @index >= PHASE_INDEXES.size
91
+ @index
92
+ end
93
+
94
+ #
95
+ # 朔月(月初)であるか
96
+ #
97
+ # @return [True] 朔月である
98
+ # @return [False] 朔月ではない
99
+ #
100
+ def first_phase?
101
+ @index.zero?
102
+ end
103
+
104
+ #
105
+ # 朔月のみログ出力する
106
+ #
107
+ # @param [String] messages メッセージ(可変長)
108
+ #
109
+ def debug(*messages)
110
+ # 全ての弦を対象にするためコメントアウトする
111
+ # return unless first_phase?
112
+
113
+ LOGGER.debug(*messages)
114
+ end
115
+
116
+ #
117
+ # 現在の定朔を取得する
118
+ #
119
+ # @return [Remainder] 定朔
120
+ #
121
+ def current_remainder
122
+ # abstract
123
+ end
124
+
125
+ #
126
+ # 補正値を得る
127
+ #
128
+ # @return [Integer] 補正値
129
+ #
130
+ def correction_value
131
+ sun = correction_solar_value
132
+ moon = correction_moon_value
133
+
134
+ sum = sun + moon
135
+
136
+ debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
137
+
138
+ sum
139
+ end
140
+
141
+ #
142
+ # 太陽運動の補正値を得る
143
+ #
144
+ # @return [Integer] 太陽運動の補正値
145
+ #
146
+ def correction_solar_value
147
+ # abstract
148
+ end
149
+
150
+ #
151
+ # 月運動の補正値を得る
152
+ #
153
+ # @return [Integer] 月運動の補正値
154
+ #
155
+ def correction_moon_value
156
+ # abstract
157
+ end
158
+
159
+ def add_quarter_moon_size
160
+ @average_remainder.add!(@quarter)
161
+ @solar_location.add_quarter
162
+ @lunar_location.add_quarter
163
+
164
+ next_index
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -23,7 +23,7 @@ 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, remainder:)
27
27
  # 西暦日
28
28
  @western_date = western_date
29
29
  # 大余小余
@@ -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 月情報(運用)
@@ -40,6 +40,7 @@ module Zakuro
40
40
  solar_terms: solar_terms)
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
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../output/logger'
4
+ require_relative '../monthly/initialized_month'
5
+ require_relative '../monthly/month_label'
6
+ require_relative '../monthly/first_day'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Calculation
12
+ # :nodoc:
13
+ module Range
14
+ #
15
+ # MedievalAnnualRange 年間範囲(中世)
16
+ #
17
+ # * 儀鳳暦 ~ 宣明暦 を便宜的に中世とした
18
+ # * 冬至から1年の開始を算出する
19
+ # * 二十四節気:平気法
20
+ # * 月の大小:定朔
21
+ #
22
+ module MedievalAnnualRange
23
+ # @return [Output::Logger] ロガー
24
+ LOGGER = Output::Logger.new(location: 'medieval_annual_range')
25
+
26
+ #
27
+ # 一覧取得する
28
+ #
29
+ # * 対象年に対して、前年11月-当年11月までを出力する
30
+ # * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
31
+ #
32
+ # @param [Context] context 暦コンテキスト
33
+ # @param [Monthly::AbstractLunarPhase] lunar_phase 月の位相
34
+ # @param [Solar::AbstractAverage] solar_average 定気(太陽軌道平均)
35
+ #
36
+ # @return [Array<Month>] 1年データ
37
+ #
38
+ def self.get(context:, lunar_phase:, solar_average:)
39
+ annual_range = initialized_annual_range(context: context, lunar_phase: lunar_phase)
40
+
41
+ apply_big_and_small_of_the_month(annual_range: annual_range)
42
+
43
+ solar_average.set(annual_range: annual_range)
44
+
45
+ # 月間隔を取得するためだけの末尾要素を削除
46
+ annual_range.pop
47
+
48
+ initialize_month_label(annual_range: annual_range)
49
+ end
50
+
51
+ #
52
+ # 1年データを取得する
53
+ #
54
+ # @param [Context] context 暦コンテキスト
55
+ # @param [Monthly::LunarPhase] lunar_phase 月の位相
56
+ #
57
+ # @return [Array<Month>] 1年データ
58
+ #
59
+ def self.initialized_annual_range(context:, lunar_phase:)
60
+ result = []
61
+
62
+ # 14ヶ月分を生成する(閏年で最大13ヶ月 + 末月の大小/二十四節気を求めるために必要な月)
63
+ (0..13).each do |_index|
64
+ adjusted = lunar_phase.next_month
65
+
66
+ result.push(
67
+ Monthly::InitializedMonth.new(
68
+ context: context,
69
+ month_label: Monthly::MonthLabel.new,
70
+ first_day: Monthly::FirstDay.new(remainder: adjusted),
71
+ phase_index: 0
72
+ )
73
+ )
74
+ end
75
+
76
+ result
77
+ end
78
+ private_class_method :initialized_annual_range
79
+
80
+ #
81
+ # 1年データの各月に月の大小を設定する
82
+ #
83
+ # @param [Array<Month>] annual_range 1年データ
84
+ #
85
+ def self.apply_big_and_small_of_the_month(annual_range:)
86
+ # NOTE: 最後の月は処理できない(=計算外の余分な月が最後に必要である)
87
+ annual_range.each_cons(2) do |(current_month, next_month)|
88
+ current_month.eval_many_days(next_month_day: next_month.remainder.day)
89
+ end
90
+ end
91
+ private_class_method :apply_big_and_small_of_the_month
92
+
93
+ #
94
+ # 月表示情報を更新する
95
+ #
96
+ # @param [Array<Month>] annual_range 1年データ
97
+ #
98
+ def self.initialize_month_label(annual_range:)
99
+ annual_range.each(&:rename_month_label_by_solar_term)
100
+ end
101
+ private_class_method :initialize_month_label
102
+ end
103
+ end
104
+ end
105
+ end