zakuro 0.1.4 → 0.4.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/doc/gengou.md +22 -22
  3. data/doc/operation/csv/month.csv +447 -202
  4. data/doc/operation/operation.xlsx +0 -0
  5. data/lib/zakuro/calculation/base/operated_year.rb +114 -0
  6. data/lib/zakuro/calculation/base/year.rb +3 -0
  7. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +44 -19
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +1 -1
  10. data/lib/zakuro/calculation/monthly/operated_month.rb +47 -3
  11. data/lib/zakuro/calculation/range/full_range.rb +1 -1
  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 +7840 -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 +59 -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/gihou/const/number.rb +55 -0
  45. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  46. data/lib/zakuro/version/gihou/cycle/remainder.rb +56 -0
  47. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  48. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  49. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  50. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  51. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  52. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  53. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  54. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  55. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  56. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  57. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  58. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  59. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  60. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  61. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  62. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  63. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  64. data/lib/zakuro/version/senmyou/const/remainder.rb +47 -0
  65. data/lib/zakuro/version/senmyou/cycle/remainder.rb +5 -12
  66. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +4 -1
  67. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +36 -155
  68. data/lib/zakuro/version/senmyou/range/annual_range.rb +7 -135
  69. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  70. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  71. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +87 -0
  72. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +67 -0
  73. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  74. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  75. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  76. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  77. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  78. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  79. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  80. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  81. data/lib/zakuro/version/version_class_resolver.rb +8 -0
  82. data/lib/zakuro/version.rb +1 -1
  83. data/lib/zakuro/version_factory.rb +1 -1
  84. metadata +62 -8
  85. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  86. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  87. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  88. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  89. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  90. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../../calculation/cycle/abstract_solar_term'
4
+
5
+ require_relative '../const/remainder'
6
+
4
7
  require_relative './remainder'
5
8
 
6
9
  # :nodoc:
@@ -14,7 +17,7 @@ module Zakuro
14
17
  #
15
18
  class SolarTerm < Calculation::Cycle::AbstractSolarTerm
16
19
  # @return [Remainder] 気策(24分の1年)
17
- SOLAR_TERM_AVERAGE = Remainder.new(day: 15, minute: 1835, second: 5)
20
+ SOLAR_TERM_AVERAGE = Const::Remainder::Solar::SOLAR_TERM_AVERAGE
18
21
 
19
22
  #
20
23
  # 初期化
@@ -1,8 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../output/logger'
3
+ require_relative '../../../calculation/monthly/abstract_lunar_phase'
4
4
 
5
- require_relative '../stella/winter_solstice'
5
+ require_relative '../const/remainder'
6
+
7
+ require_relative '../stella/solar/location'
8
+ require_relative '../stella/solar/value'
9
+ require_relative '../stella/lunar/location'
10
+ require_relative '../stella/lunar/value'
11
+
12
+ require_relative '../stella/origin/lunar_age'
13
+ require_relative '../stella/origin/average_november'
6
14
 
7
15
  # :nodoc:
8
16
  module Zakuro
@@ -10,44 +18,12 @@ module Zakuro
10
18
  module Senmyou
11
19
  # :nodoc:
12
20
  module Monthly
13
- # :reek:TooManyInstanceVariables { max_instance_variables: 7 }
14
-
15
21
  #
16
22
  # LunarPhase 月の位相
17
23
  #
18
- class LunarPhase
19
- #
20
- # QuarterMoon
21
- #
22
- module QuarterMoon
23
- # @return [Remainder] 弦(1分=8秒)
24
- DEFAULT = Cycle::Remainder.new(day: 7, minute: 3214, second: 2)
25
- # @return [Remainder] 弦(1分=100秒)
26
- BASE_HUNDRED = Cycle::LunarRemainder.new(day: 7, minute: 3214, second: 25)
27
- end
28
-
29
- # @return [Output::Logger] ロガー
30
- LOGGER = Output::Logger.new(location: 'lunar_phase')
31
-
32
- # @return [Array<String>] 月内の弦
33
- PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
34
-
35
- # @return [Integer] 西暦年
36
- attr_reader :western_year
37
- # @return [Remainder]] 経
38
- attr_reader :average_remainder
39
- # @return [True] 初回計算
40
- # @return [False] 次回以降計算
41
- attr_reader :first
42
- # @return [SolarTerm] 二十四節気(入定気)
43
- attr_reader :solar_term
44
- # @return [Remainder] 入暦
45
- attr_reader :moon_remainder
46
- # @return [True] 進(遠地点より数える)
47
- # @return [False] 退(近地点より数える)
48
- attr_reader :is_forward
49
- # @return [Integer] 弦
50
- attr_reader :phase_index
24
+ class LunarPhase < Calculation::Monthly::AbstractLunarPhase
25
+ # @return [Cycle::Remainder] 弦
26
+ QUARTER = Const::Remainder::Solar::QUARTER
51
27
 
52
28
  #
53
29
  # 初期化
@@ -55,91 +31,22 @@ module Zakuro
55
31
  # @param [Integer] western_year 西暦年
56
32
  #
57
33
  def initialize(western_year:)
58
- @western_year = western_year
59
- # 経
60
- @average_remainder = WinterSolstice.calc_averaged_last_november_1st(
61
- western_year: @western_year
62
- )
63
34
  # 天正閏余
64
- winter_solstice_age = \
65
- WinterSolstice.calc_moon_age(western_year: @western_year)
66
- # 入定気
67
- @solar_term = Cycle::SolarTerm.new(remainder: winter_solstice_age)
68
- # 入暦
69
- @moon_remainder = Cycle::LunarRemainder.new(total: 0).add!(winter_solstice_age)
70
-
71
- @is_forward = false
72
- @first = true
73
-
74
- # 弦
75
- @phase_index = 0
76
- end
77
-
78
- #
79
- # 次の弦に進める
80
- #
81
- # @return [Remainder] 定朔
82
- #
83
- def next_phase
84
- adjusted = current_remainder
85
-
86
- @first = false if @first
87
-
88
- add_quarter_moon_size
89
-
90
- adjusted
91
- end
92
-
93
- #
94
- # 次の月に進める
95
- # @note 進めた後の月の定朔ではなく、当月のものを返却する
96
- #
97
- # @return [Remainder] 当月初の定朔
98
- #
99
- def next_month
100
- result = nil
101
- PHASE_INDEXES.each_with_index do |_phase, index|
102
- adjust = next_phase
103
- result = adjust if index.zero?
104
- end
105
-
106
- result
35
+ lunar_age = Origin::LunarAge.get(western_year: western_year)
36
+
37
+ super(
38
+ quater: QUARTER,
39
+ average_remainder: Origin::AverageNovember.get(western_year: western_year),
40
+ solar_location: Solar::Location.new(lunar_age: lunar_age),
41
+ lunar_location: Lunar::Location.new(
42
+ western_year: western_year,
43
+ lunar_age: Cycle::LunarRemainder.new(total: 0).add!(lunar_age)
44
+ )
45
+ )
107
46
  end
108
47
 
109
48
  private
110
49
 
111
- #
112
- # 次の弦に進める
113
- #
114
- # @return [Integer] 弦
115
- #
116
- def next_phase_index
117
- @phase_index += 1
118
- @phase_index = 0 if @phase_index >= PHASE_INDEXES.size
119
- @phase_index
120
- end
121
-
122
- #
123
- # 朔月(月初)かを確認する
124
- #
125
- # @return [True] 朔月である
126
- # @return [False] 朔月ではない
127
- #
128
- def first_phase?
129
- @phase_index.zero?
130
- end
131
-
132
- #
133
- # 朔月のみログ出力する
134
- #
135
- # @param [String] messages メッセージ(可変長)
136
- #
137
- def debug(*messages)
138
- return unless first_phase?
139
-
140
- LOGGER.debug(*messages)
141
- end
142
-
143
50
  # :reek:TooManyStatements { max_statements: 6 }
144
51
 
145
52
  #
@@ -161,62 +68,36 @@ module Zakuro
161
68
  adjusted
162
69
  end
163
70
 
164
- #
165
- # 補正値を得る
166
- #
167
- # @return [Integer] 補正値
168
- #
169
- def correction_value
170
- sun = correction_solar_value
171
- moon = correction_moon_value
172
-
173
- sum = sun + moon
174
-
175
- debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
176
-
177
- sum
178
- end
179
-
180
71
  #
181
72
  # 太陽運動の補正値を得る
182
73
  #
183
74
  # @return [Integer] 太陽運動の補正値
184
75
  #
185
76
  def correction_solar_value
186
- @solar_term = SolarLocation.get(
187
- solar_term: @solar_term
188
- )
189
- debug("@solar_term.remainder: #{@solar_term.remainder.format(form: '%d-%d.%d')}")
190
- debug("@solar_term.index: #{@solar_term.index}")
77
+ @solar_location.run
78
+ debug("@solar_term.remainder: #{@solar_location.remainder.format(form: '%d-%d.%d')}")
79
+ debug("@solar_term.index: #{@solar_location.index}")
191
80
 
192
- SolarOrbit.calc_sun_orbit_value(solar_term: @solar_term)
81
+ Solar::Value.get(solar_location: @solar_location)
193
82
  end
194
83
 
84
+ # :reek:TooManyStatements { max_statements: 6 }
85
+
195
86
  #
196
87
  # 月運動の補正値を得る
197
88
  #
198
89
  # @return [Integer] 月運動の補正値
199
90
  #
200
91
  def correction_moon_value
201
- @moon_remainder, @is_forward = \
202
- LunarOrbit.calc_moon_point(remainder: @moon_remainder,
203
- western_year: @western_year,
204
- is_forward: @is_forward,
205
- first: @first)
206
-
207
- debug("@moon_remainder.format: #{@moon_remainder.format}")
208
- debug("@is_forward: #{@is_forward}")
92
+ @lunar_location.run
209
93
 
210
- LunarOrbit.calc_moon_orbit_value(remainder_month: @moon_remainder,
211
- is_forward: @is_forward)
212
- end
94
+ remainder = @lunar_location.adjusted_remainder
95
+ forward = @lunar_location.forward
213
96
 
214
- def add_quarter_moon_size
215
- @average_remainder.add!(QuarterMoon::DEFAULT)
216
- @solar_term.remainder.add!(QuarterMoon::DEFAULT)
217
- @moon_remainder.add!(QuarterMoon::BASE_HUNDRED)
97
+ debug("[lunar]remainder.format: #{remainder.format}")
98
+ debug("[lunar]forward: #{forward}")
218
99
 
219
- next_phase_index
100
+ Lunar::Value.get(remainder: remainder, forward: forward)
220
101
  end
221
102
  end
222
103
  end
@@ -1,14 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../output/logger'
4
- require_relative '../cycle/remainder'
5
- require_relative '../cycle/solar_term'
6
- require_relative '../../../calculation/monthly/initialized_month'
3
+ require_relative '../../../calculation/range/medieval_annual_range'
7
4
  require_relative '../monthly/lunar_phase'
8
- require_relative '../stella/solar_orbit'
9
- require_relative '../stella/solar_average'
10
- require_relative '../stella/solar_location'
11
- require_relative '../stella/lunar_orbit'
5
+ require_relative '../stella/solar/average'
12
6
 
13
7
  # :nodoc:
14
8
  module Zakuro
@@ -20,42 +14,6 @@ module Zakuro
20
14
  # AnnualRange 年間範囲
21
15
  #
22
16
  module AnnualRange
23
- # @return [Output::Logger] ロガー
24
- LOGGER = Output::Logger.new(location: 'annual_range')
25
-
26
- # :reek:TooManyStatements { max_statements: 6 }
27
-
28
- #
29
- # 11月定朔(冬至が含まれる月の1日:補正済)を求める
30
- #
31
- # @param [Integer] western_year 西暦年
32
- #
33
- # @return [Remainder] 11月定朔
34
- #
35
- def self.calc_last_november_1st(western_year:)
36
- # 天正閏余
37
- winter_solstice_age = \
38
- WinterSolstice.calc_moon_age(western_year: western_year)
39
- # 11月経朔
40
- november_1st = \
41
- WinterSolstice.calc_averaged_last_november_1st(western_year: western_year)
42
- # 11月定朔
43
-
44
- # 補正
45
- correction_value = correction_value_on_last_november_1st(
46
- winter_solstice_age: winter_solstice_age,
47
- western_year: western_year
48
- )
49
-
50
- result = november_1st.add(Cycle::Remainder.new(day: 0, minute: correction_value,
51
- second: 0))
52
- # 進朔
53
- result.up_on_new_moon!
54
- result
55
- end
56
-
57
- # :reek:TooManyStatements { max_statements: 6 }
58
-
59
17
  #
60
18
  # 一覧取得する
61
19
  #
@@ -67,100 +25,14 @@ module Zakuro
67
25
  #
68
26
  # @return [Array<Month>] 1年データ
69
27
  #
70
- def self.collect_annual_range_after_last_november_1st(context:, western_year:)
71
- annual_range = initialized_annual_range(context: context, western_year: western_year)
72
-
73
- apply_big_and_small_of_the_month(annual_range: annual_range)
74
-
75
- solar_average = SolarAverage.new(western_year: western_year)
76
- solar_average.set(annual_range: annual_range)
77
-
78
- # 月間隔を取得するためだけの末尾要素を削除
79
- annual_range.pop
80
-
81
- initialize_month_label(annual_range: annual_range)
82
- end
83
-
84
- #
85
- # 11月定朔の補正値を求める
86
- #
87
- # @param [Remainder] winter_solstice_age 天正閏余
88
- # @param [Integer] western_year 西暦年
89
- #
90
- # @return [Integer] 補正値
91
- #
92
- def self.correction_value_on_last_november_1st(winter_solstice_age:, western_year:)
93
- # 補正
94
- solar_term = Cycle::SolarTerm.new(
95
- remainder: winter_solstice_age
96
- )
97
- solar_term = \
98
- SolarLocation.get(
99
- solar_term: solar_term
100
- )
101
-
102
- moon_remainder, is_forward = LunarOrbit.calc_moon_point(
103
- remainder: winter_solstice_age, western_year: western_year
104
- )
105
-
106
- SolarOrbit.calc_sun_orbit_value(solar_term: solar_term) +
107
- LunarOrbit.calc_moon_orbit_value(remainder_month: moon_remainder,
108
- is_forward: is_forward)
109
- end
110
- private_class_method :correction_value_on_last_november_1st
111
-
112
- #
113
- # 1年データを取得する
114
- #
115
- # @param [Context] context 暦コンテキスト
116
- # @param [Integer] western_year 西暦年
117
- #
118
- # @return [Array<Month>] 1年データ
119
- #
120
- def self.initialized_annual_range(context:, western_year:)
121
- result = []
28
+ def self.get(context:, western_year:)
122
29
  lunar_phase = Monthly::LunarPhase.new(western_year: western_year)
30
+ solar_average = Solar::Average.new(western_year: western_year)
123
31
 
124
- # 14ヶ月分を生成する(閏年で最大13ヶ月 + 末月の大小/二十四節気を求めるために必要な月)
125
- (0..13).each do |_index|
126
- adjusted = lunar_phase.next_month
127
-
128
- result.push(
129
- Calculation::Monthly::InitializedMonth.new(
130
- context: context,
131
- month_label: Calculation::Monthly::MonthLabel.new,
132
- first_day: Calculation::Monthly::FirstDay.new(remainder: adjusted),
133
- phase_index: 0
134
- )
135
- )
136
- end
137
-
138
- result
139
- end
140
- private_class_method :initialized_annual_range
141
-
142
- #
143
- # 1年データの各月に月の大小を設定する
144
- #
145
- # @param [Array<Month>] annual_range 1年データ
146
- #
147
- def self.apply_big_and_small_of_the_month(annual_range:)
148
- # NOTE: 最後の月は処理できない(=計算外の余分な月が最後に必要である)
149
- annual_range.each_cons(2) do |(current_month, next_month)|
150
- current_month.eval_many_days(next_month_day: next_month.remainder.day)
151
- end
152
- end
153
- private_class_method :apply_big_and_small_of_the_month
154
-
155
- #
156
- # 月表示情報を更新する
157
- #
158
- # @param [Array<Month>] annual_range 1年データ
159
- #
160
- def self.initialize_month_label(annual_range:)
161
- annual_range.each(&:rename_month_label_by_solar_term)
32
+ Calculation::Range::MedievalAnnualRange.get(
33
+ context: context, lunar_phase: lunar_phase, solar_average: solar_average
34
+ )
162
35
  end
163
- private_class_method :initialize_month_label
164
36
  end
165
37
  end
166
38
  end
@@ -0,0 +1,237 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../const/number'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Senmyou
9
+ # :nodoc:
10
+ module Lunar
11
+ #
12
+ # Adjustment 補正値情報
13
+ #
14
+ module Adjustment
15
+ # @return [Integer] 遠/近の地点での中間
16
+ HALF_DAYS = [7].freeze
17
+
18
+ #
19
+ # Row 行情報
20
+ #
21
+ class Row
22
+ # @return [True] 進(遠地点より数える)
23
+ # @return [False] 退(近地点より数える)
24
+ attr_reader :forward
25
+ # @return [Integer] 入暦(1-14)
26
+ attr_reader :day
27
+ # @return [Range] 小余範囲
28
+ attr_reader :range
29
+ # @return [Value] 補正値
30
+ attr_reader :value
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [True, False] forward 進(遠地点より数える)/退(近地点より数える)
36
+ # @param [Integer] day 入暦(1-14)
37
+ # @param [Range] range 小余範囲
38
+ # @param [Value] value 補正値
39
+ #
40
+ def initialize(forward:, day:, range:, value:)
41
+ @forward = forward
42
+ @day = day
43
+ @range = range
44
+ @value = value
45
+ end
46
+
47
+ # :reek:ControlParameter
48
+
49
+ #
50
+ # 一致するか
51
+ #
52
+ # @param [True, False] forward 進(遠地点より数える)/退(近地点より数える)
53
+ # @param [Integer] day 入暦(1-14)
54
+ # @param [Integer] minute 小余
55
+ #
56
+ # @return [True] 一致
57
+ # @return [False] 不一致
58
+ #
59
+ def match?(forward:, day:, minute:)
60
+ return false unless @forward == forward
61
+
62
+ return false unless @day == day
63
+
64
+ return false unless @range.include?(minute: minute)
65
+
66
+ true
67
+ end
68
+
69
+ #
70
+ # 分母を返す
71
+ #
72
+ # @return [Integer] 分母
73
+ #
74
+ def denominator
75
+ @range.denominator
76
+ end
77
+ end
78
+
79
+ #
80
+ # Range 小余範囲
81
+ #
82
+ class Range
83
+ # @return [Integer] 下限
84
+ MIN = 0
85
+ # @return [Integer] 上限
86
+ MAX = Const::Number::Cycle::DAY
87
+ # @return [Integer] 遠/近の地点での中間
88
+ HALF = 7465
89
+ # @return [Integer] 各地点の最後
90
+ LAST = 6529
91
+
92
+ # @return [Integer] 下限
93
+ attr_reader :min
94
+ # @return [Integer] 上限
95
+ attr_reader :max
96
+
97
+ #
98
+ # 初期化
99
+ #
100
+ # @param [Integer] min 下限
101
+ # @param [Integer] max 上限
102
+ #
103
+ def initialize(min: MIN, max: MAX)
104
+ @min = min
105
+ @max = max
106
+ end
107
+
108
+ #
109
+ # 含まれるか
110
+ #
111
+ # @param [Integer] minute 小余
112
+ #
113
+ # @return [True] 含まれる
114
+ # @return [False] 含まれない
115
+ #
116
+ def include?(minute:)
117
+ minute >= @min && minute <= @max
118
+ end
119
+
120
+ #
121
+ # 分母を返す
122
+ #
123
+ # @return [Integer] 分母
124
+ #
125
+ def denominator
126
+ @max - @min
127
+ end
128
+ end
129
+
130
+ #
131
+ # Value 補正値
132
+ #
133
+ class Value
134
+ # @return [Integer] 損益率
135
+ attr_reader :per
136
+ # @return [Integer] 眺朒(ちょうじく)積
137
+ attr_reader :stack
138
+
139
+ #
140
+ # 初期化
141
+ #
142
+ # @param [Integer] per 損益率
143
+ # @param [Integer] stack 眺朒(ちょうじく)積
144
+ #
145
+ def initialize(per:, stack:)
146
+ @per = per
147
+ @stack = stack
148
+ end
149
+
150
+ #
151
+ # 文字化
152
+ #
153
+ # @return [String] 文字
154
+ #
155
+ def to_s
156
+ "per:#{@per}, stack:#{@stack}"
157
+ end
158
+ end
159
+
160
+ # rubocop:disable Layout/LineLength
161
+
162
+ #
163
+ # @return [Array<Row>] 月の補正値情報
164
+ #
165
+ LIST = [
166
+ Row.new(forward: true, day: 1, range: Range.new, value: Value.new(per: +830, stack: 0)),
167
+ Row.new(forward: true, day: 2, range: Range.new, value: Value.new(per: +726, stack: +830)),
168
+ Row.new(forward: true, day: 3, range: Range.new, value: Value.new(per: +606, stack: +1556)),
169
+ Row.new(forward: true, day: 4, range: Range.new, value: Value.new(per: +471, stack: +2162)),
170
+ Row.new(forward: true, day: 5, range: Range.new, value: Value.new(per: +337, stack: +2633)),
171
+ Row.new(forward: true, day: 6, range: Range.new, value: Value.new(per: +202, stack: +2970)),
172
+ Row.new(forward: true, day: 7, range: Range.new(max: Range::HALF), value: Value.new(per: +53, stack: +3172)),
173
+ Row.new(forward: true, day: 7, range: Range.new(min: Range::HALF), value: Value.new(per: -7, stack: +3225)), # +3172 + 53(初益)
174
+ Row.new(forward: true, day: 8, range: Range.new, value: Value.new(per: -82, stack: +3218)),
175
+ Row.new(forward: true, day: 9, range: Range.new, value: Value.new(per: -224, stack: +3136)),
176
+ Row.new(forward: true, day: 10, range: Range.new, value: Value.new(per: -366, stack: +2912)),
177
+ Row.new(forward: true, day: 11, range: Range.new, value: Value.new(per: -509, stack: +2546)),
178
+ Row.new(forward: true, day: 12, range: Range.new, value: Value.new(per: -643, stack: +2037)),
179
+ Row.new(forward: true, day: 13, range: Range.new, value: Value.new(per: -748, stack: +1394)),
180
+ Row.new(forward: true, day: 14, range: Range.new(max: Range::LAST), value: Value.new(per: -646, stack: +646)), # 14日の小余は常に6529以下
181
+ Row.new(forward: false, day: 1, range: Range.new, value: Value.new(per: -830, stack: 0)),
182
+ Row.new(forward: false, day: 2, range: Range.new, value: Value.new(per: -726, stack: -830)),
183
+ Row.new(forward: false, day: 3, range: Range.new, value: Value.new(per: -598, stack: -1556)),
184
+ Row.new(forward: false, day: 4, range: Range.new, value: Value.new(per: -464, stack: -2154)),
185
+ Row.new(forward: false, day: 5, range: Range.new, value: Value.new(per: -329, stack: -2618)),
186
+ Row.new(forward: false, day: 6, range: Range.new, value: Value.new(per: -195, stack: -2947)),
187
+ Row.new(forward: false, day: 7, range: Range.new(max: Range::HALF), value: Value.new(per: -53, stack: -3142)),
188
+ Row.new(forward: false, day: 7, range: Range.new(min: Range::HALF), value: Value.new(per: +7, stack: -3195)), # -3142 - 53(初益)
189
+ Row.new(forward: false, day: 8, range: Range.new, value: Value.new(per: +82, stack: -3188)),
190
+ Row.new(forward: false, day: 9, range: Range.new, value: Value.new(per: +225, stack: -3106)),
191
+ Row.new(forward: false, day: 10, range: Range.new, value: Value.new(per: +366, stack: -2881)),
192
+ Row.new(forward: false, day: 11, range: Range.new, value: Value.new(per: +501, stack: -2515)),
193
+ Row.new(forward: false, day: 12, range: Range.new, value: Value.new(per: +628, stack: -2014)),
194
+ Row.new(forward: false, day: 13, range: Range.new, value: Value.new(per: +740, stack: -1386)),
195
+ Row.new(forward: false, day: 14, range: Range.new(max: Range::LAST), value: Value.new(per: +646, stack: -646)) # 14日の小余は常に6529以下
196
+ ].freeze
197
+ # rubocop:enable Layout/LineLength
198
+
199
+ #
200
+ # 月軌道の補正に必要な基本値を引き当てる
201
+ #
202
+ # @param [True, False] forward 進(遠地点より数える)/退(近地点より数える)
203
+ # @param [Integer] day 大余
204
+ # @param [Integer] minute 小余
205
+ #
206
+ # @return [Row] 補正値
207
+ #
208
+ def self.specify(forward:, day:, minute:)
209
+ LIST.each do |row|
210
+ # NOTE: 範囲が重複している場合、最初に引き当てたほうを優先する
211
+ return row if row.match?(forward: forward, day: day, minute: minute)
212
+ end
213
+
214
+ raise ArgumentError.new, "invalid parameter: #{forward}/#{day}/#{minute}"
215
+ end
216
+
217
+ # :reek:ControlParameter
218
+
219
+ #
220
+ # 小余の下げ幅を求める
221
+ #
222
+ # @param [Integer] day 大余
223
+ # @param [Integer] minute 小余
224
+ #
225
+ # @return [Integer] 小余の下げ幅
226
+ #
227
+ def self.minus_minute(day:, minute:)
228
+ return minute unless HALF_DAYS.include?(day)
229
+
230
+ return minute unless minute > Range::HALF
231
+
232
+ minute - Range::HALF
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end