zakuro 0.1.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  3. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  4. data/lib/zakuro/calculation/base/year.rb +107 -0
  5. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +484 -0
  6. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  7. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  10. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  11. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  12. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  13. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  14. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  15. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  16. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  17. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  18. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  19. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  20. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  21. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +78 -0
  22. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +71 -0
  23. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  24. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  25. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  26. data/lib/zakuro/calculation/summary/single.rb +129 -0
  27. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  28. data/lib/zakuro/era/japan/reki.rb +1 -1
  29. data/lib/zakuro/merchant.rb +2 -2
  30. data/lib/zakuro/output/error.rb +7 -6
  31. data/lib/zakuro/output/logger.rb +50 -49
  32. data/lib/zakuro/output/response.rb +145 -144
  33. data/lib/zakuro/tools/typeof.rb +2 -2
  34. data/lib/zakuro/version.rb +1 -1
  35. data/lib/zakuro/version/abstract_version.rb +1 -1
  36. data/lib/zakuro/version/context.rb +23 -0
  37. data/lib/zakuro/version/daien/const/number.rb +55 -0
  38. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  39. data/lib/zakuro/version/daien/cycle/remainder.rb +59 -0
  40. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  41. data/lib/zakuro/version/daien/daien.rb +36 -0
  42. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  43. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  44. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  45. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  46. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  47. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  48. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  49. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  50. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  51. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  52. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  53. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  54. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  55. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  56. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  57. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  58. data/lib/zakuro/version/gihou/cycle/remainder.rb +56 -0
  59. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  60. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  61. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  62. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  63. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  64. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  65. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  66. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  67. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  68. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  69. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  70. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  71. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  72. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  73. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  74. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  75. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  76. data/lib/zakuro/version/senmyou/const/remainder.rb +47 -0
  77. data/lib/zakuro/version/senmyou/cycle/remainder.rb +56 -0
  78. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +34 -0
  79. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +80 -195
  80. data/lib/zakuro/version/senmyou/range/annual_range.rb +25 -145
  81. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  82. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  83. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  84. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +87 -0
  85. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +67 -0
  86. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  87. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  88. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  89. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  90. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  91. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  92. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  93. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  94. data/lib/zakuro/version/version_class_resolver.rb +70 -0
  95. data/lib/zakuro/version_factory.rb +3 -3
  96. metadata +83 -28
  97. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  98. data/lib/zakuro/cycle/zodiac.rb +0 -103
  99. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  100. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  101. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  102. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  103. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -148
  104. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  105. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  106. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -119
  107. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  108. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  109. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -196
  110. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -194
  111. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  112. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  113. data/lib/zakuro/version/senmyou/range/western_date_allocation.rb +0 -68
  114. data/lib/zakuro/version/senmyou/range/year_boundary.rb +0 -138
  115. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  116. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  117. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  118. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  119. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  120. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  121. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
  122. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -0,0 +1,209 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './month'
4
+ require_relative '../../operation/operation'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Monthly
12
+ # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
13
+
14
+ #
15
+ # OperatedMonth 月情報(運用)
16
+ #
17
+ class OperatedMonth < Month
18
+ # @return [Operation::MonthHistory] 変更履歴(月)
19
+ attr_reader :history
20
+ # @return [OperatedSolarTerms] 運用時二十四節気
21
+ attr_reader :operated_solar_terms
22
+
23
+ # :reek:LongParameterList {max_params: 6}
24
+ # rubocop:disable Metrics/ParameterLists
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [Context] context 暦コンテキスト
30
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
31
+ # @param [MonthLabel] month_label 月表示名
32
+ # @param [FirstDay] first_day 月初日(朔日)
33
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
34
+ # @param [Operation::MonthHistory] history 変更履歴(月)
35
+ #
36
+ def initialize(context:, operated_solar_terms:, month_label: MonthLabel.new,
37
+ first_day: FirstDay.new, solar_terms: [],
38
+ history: Operation::MonthHistory.new)
39
+ super(context: context, month_label: month_label, first_day: first_day,
40
+ solar_terms: solar_terms)
41
+ @history = history
42
+ @operated_solar_terms = operated_solar_terms
43
+ end
44
+
45
+ # rubocop:enable Metrics/ParameterLists
46
+
47
+ #
48
+ # 書き換える
49
+ #
50
+ def rewrite
51
+ rewrite_month
52
+ rewrite_solar_terms
53
+ rewrite_first_day
54
+ end
55
+
56
+ #
57
+ # 月ごとの差分で書き換える
58
+ #
59
+ def rewrite_month
60
+ diff = history.diffs.month
61
+
62
+ @month_label = MonthLabel.new(
63
+ number: OperatedMonth.rewrite_month_fields(
64
+ month_diff: diff, month_label: month_label, name: 'number'
65
+ ),
66
+ is_many_days: OperatedMonth.rewrite_month_fields(
67
+ month_diff: diff, month_label: month_label, name: 'is_many_days'
68
+ ),
69
+ leaped: OperatedMonth.rewrite_month_fields(
70
+ month_diff: diff, month_label: month_label, name: 'leaped'
71
+ )
72
+ )
73
+ end
74
+
75
+ def self.rewrite_month_fields(month_diff:, month_label:, name:)
76
+ method_name = name.intern
77
+
78
+ diff = month_diff.send(method_name)
79
+ default = month_label.send(method_name)
80
+ return default if diff.invalid?
81
+
82
+ diff.actual
83
+ end
84
+
85
+ #
86
+ # 二十四節気ごとの差分で書き換える
87
+ #
88
+ def rewrite_solar_terms
89
+ matched, operated_solar_term = @operated_solar_terms.get(
90
+ western_date: first_day.western_date
91
+ )
92
+
93
+ return unless matched
94
+
95
+ @solar_terms = OperatedMonth.create_operated_solar_terms(
96
+ operated_solar_term: operated_solar_term,
97
+ solar_terms: solar_terms
98
+ )
99
+ end
100
+
101
+ #
102
+ # <Description>
103
+ #
104
+ # @param [<Type>] operated_solar_term <description>
105
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
106
+ #
107
+ # @return [Array<SolarTerm>] 二十四節気
108
+ #
109
+ def self.create_operated_solar_terms(operated_solar_term:, solar_terms:)
110
+ index = operated_solar_term.index
111
+
112
+ # 別の月に移動する二十四節気。割り当てない。
113
+ result = remove_solar_term(index: index, solar_terms: solar_terms)
114
+
115
+ return result if used_solar_term?(index: index, solar_terms: solar_terms)
116
+
117
+ result.push(operated_solar_term)
118
+
119
+ result
120
+ end
121
+
122
+ # :reek:ControlParameter
123
+
124
+ #
125
+ # 二十四節気が使用されているか
126
+ #
127
+ # @param [Integer] index 二十四節気番号
128
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
129
+ #
130
+ # @return [True] 使用
131
+ # @return [False] 未使用
132
+ #
133
+ def self.used_solar_term?(index:, solar_terms:)
134
+ solar_terms.each do |solar_term|
135
+ return true if index == solar_term.index
136
+ end
137
+
138
+ false
139
+ end
140
+
141
+ # :reek:ControlParameter
142
+
143
+ #
144
+ # 対象の二十四節気を除外する
145
+ #
146
+ # @param [Integer] index 二十四節気番号
147
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
148
+ #
149
+ # @return [Array<SolarTerm>] 二十四節気(対象除外済)
150
+ #
151
+ def self.remove_solar_term(index:, solar_terms:)
152
+ result = []
153
+ solar_terms.each do |solar_term|
154
+ next if index == solar_term.index
155
+
156
+ result.push(solar_term)
157
+ end
158
+
159
+ result
160
+ end
161
+
162
+ #
163
+ # 月初日ごとの差分で書き換える
164
+ #
165
+ def rewrite_first_day
166
+ diffs = @history.diffs
167
+ return if diffs.invalid_days?
168
+
169
+ days = diffs.days
170
+
171
+ @first_day = FirstDay.new(
172
+ western_date: rewrite_western_date(days: days),
173
+ remainder: rewrite_remainder(days: days)
174
+ )
175
+ end
176
+
177
+ #
178
+ # 月初日の大余小余を日差分で書き換える
179
+ #
180
+ # @param [Integer] days 日差分
181
+ #
182
+ # @return [Remainder] 月初日の大余小余
183
+ #
184
+ def rewrite_remainder(days:)
185
+ remainder = first_day.remainder.clone
186
+ remainder.add!(
187
+ context.resolver.remainder.new(day: days, minute: 0, second: 0)
188
+ )
189
+
190
+ remainder
191
+ end
192
+
193
+ #
194
+ # 月初日の西暦日を日差分で書き換える
195
+ #
196
+ # @param [Integer] days 日差分
197
+ #
198
+ # @return [Western::Calendar] 月初日の西暦日
199
+ #
200
+ def rewrite_western_date(days:)
201
+ western_date = first_day.western_date.clone
202
+ western_date += days
203
+
204
+ western_date
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../era/western'
4
+ require_relative '../../output/logger'
5
+
6
+ require_relative '../base/multi_gengou_roller'
7
+ require_relative '../base/year'
8
+
9
+ require_relative './transfer/year_boundary'
10
+ require_relative './transfer/western_date_allocation'
11
+
12
+ # :nodoc:
13
+ module Zakuro
14
+ # :nodoc:
15
+ module Calculation
16
+ # :nodoc:
17
+ module Range
18
+ # :reek:TooManyInstanceVariables { max_instance_variables: 6 }
19
+
20
+ #
21
+ # FullRange 完全範囲
22
+ # ある日からある日の範囲を計算可能な年月範囲
23
+ # * 前提として元号年はその元号の開始年から数える
24
+ # * ある日の元号年を求める場合、その元号が含まれる最初の年まで遡る
25
+ # * 元号は一つとは限らない。南北朝などで二つある場合は、古い方の元号から求める
26
+ #
27
+ # NOTE: 割り当てた元号は年初を基準にした元号年である
28
+ # * 元旦を基準にした時の正しい元号を設定している
29
+ # * 引き当てたい日付が元旦ではない場合、その月日に従い元号を再度求める
30
+ # * この再計算が必要になるのは、元号が切り替わる年のみである
31
+ #
32
+ class FullRange
33
+ # @return [Context] 暦コンテキスト
34
+ attr_reader :context
35
+ # @return [Western::Calendar] 開始日
36
+ attr_reader :start_date
37
+ # @return [Western::Calendar] 終了日
38
+ attr_reader :end_date
39
+ # @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
45
+
46
+ # @return [Output::Logger] ロガー
47
+ LOGGER = Output::Logger.new(location: 'full_range')
48
+
49
+ #
50
+ # 初期化
51
+ #
52
+ # @param [Context] context 暦コンテキスト
53
+ # @param [Western::Calendar] start_date 開始日
54
+ # @param [Western::Calendar] end_date 終了日
55
+ #
56
+ def initialize(context:, start_date: Western::Calendar.new, end_date: Western::Calendar.new)
57
+ @start_date = start_date
58
+ @end_date = end_date
59
+ return if invalid?
60
+
61
+ @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
67
+ end
68
+
69
+ #
70
+ # 無効か
71
+ #
72
+ # @return [True] 無効
73
+ # @return [False] 有効
74
+ #
75
+ def invalid?
76
+ @start_date.invalid?
77
+ end
78
+
79
+ #
80
+ # 完全範囲を取得する
81
+ #
82
+ # @return [Array<Year>] 完全範囲
83
+ #
84
+ def get
85
+ return [] if invalid?
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
98
+
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
110
+
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
119
+
120
+ years
121
+ end
122
+
123
+ # :reek:TooManyStatements { max_statements: 8 }
124
+
125
+ #
126
+ # 完全範囲内の年データの元号を開始年基準で更新する
127
+ #
128
+ # @param [Array<Year>] years 年データ(元旦基準)
129
+ #
130
+ # @return [Array<Year>] 元号更新済み年データ(元旦基準)
131
+ #
132
+ def update_gengou(years:)
133
+ updated_years = []
134
+
135
+ nearest_end_date = choise_nearest_end_date
136
+
137
+ years.each do |year|
138
+ next_year(years: updated_years, year: year)
139
+
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
149
+
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)
164
+
165
+ nil
166
+ end
167
+
168
+ #
169
+ # 年の元号を更新する
170
+ #
171
+ # @param [Year] year 元号処理前の年(元旦基準)
172
+ #
173
+ # @return [Year] 元号処理済の年(元旦基準)
174
+ #
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
181
+ )
182
+ updated_year.commit
183
+
184
+ updated_year
185
+ end
186
+
187
+ #
188
+ # 次の年に進める
189
+ #
190
+ # @param [Integer] total_days 年の日数
191
+ #
192
+ def next_new_year_date(total_days:)
193
+ @new_year_date += total_days
194
+ @multi_gengou_roller.next(days: total_days)
195
+
196
+ nil
197
+ end
198
+
199
+ #
200
+ # 現在日からみて直近の未来に対する元号の切替前日を求める
201
+ #
202
+ # @return [Western::Calendar] 元号の切替前日
203
+ #
204
+ def choise_nearest_end_date
205
+ @multi_gengou_roller.choise_nearest_end_date
206
+ end
207
+ end
208
+ end
209
+ end
210
+ 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