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
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/abstract_location'
4
+
5
+ require_relative '../../const/remainder'
6
+
7
+ require_relative './interval'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Gihou
13
+ # :nodoc:
14
+ module Solar
15
+ #
16
+ # Location 入定気
17
+ #
18
+ class Location < Calculation::Solar::AbstractLocation
19
+ # @return [Cycle::Remainder] 弦
20
+ QUARTER = Const::Remainder::Solar::QUARTER
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Cycle::Remainder] lunar_age 天正閏余(大余小余)
26
+ #
27
+ def initialize(lunar_age:)
28
+ super(lunar_age: lunar_age, quarter: QUARTER)
29
+ end
30
+
31
+ # :reek:UtilityFunction
32
+
33
+ #
34
+ # 二十四節気番号に対応する入気定日加減数を返す
35
+ #
36
+ # @note 継承のためクラスメソッドにしない
37
+ #
38
+ # @param [Integer] index 二十四節気番号
39
+ #
40
+ # @return [Cycle::Remainder] 入気定日加減数
41
+ #
42
+ def interval(index:)
43
+ Interval.index_of(index)
44
+ end
45
+
46
+ # :reek:UtilityFunction
47
+
48
+ #
49
+ # 入気定日加減数の要素数を返す
50
+ #
51
+ # @note 継承のためクラスメソッドにしない
52
+ #
53
+ # @return [Integer] 入気定日加減数の要素数
54
+ #
55
+ def interval_size
56
+ Interval.size
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/choukei_value'
4
+
5
+ require_relative '../../const/number'
6
+
7
+ require_relative './adjustment'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Gihou
13
+ # :nodoc:
14
+ module Solar
15
+ #
16
+ # Value 太陽補正値
17
+ #
18
+ module Value
19
+ #
20
+ # 太陽の運行による補正値を算出する
21
+ #
22
+ # @param [SolarTerm] solar_location 入定気
23
+ #
24
+ # @return [Integer] 補正値
25
+ #
26
+ def self.get(solar_location:)
27
+ remainder = solar_location.remainder
28
+
29
+ row = Adjustment.specify(index: solar_location.index)
30
+
31
+ Calculation::Solar::ChoukeiValue.get(remainder: remainder, row: row)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -18,7 +18,7 @@ module Zakuro
18
18
  module Cycle
19
19
  # @return [Integer] 統法(1日=8400分)
20
20
  DAY = 8400
21
- # @return [Integer] 暦周(1近日点)
21
+ # @return [Float] 暦周(1近点月)
22
22
  ANOMALISTIC_MONTH = 231_458.19
23
23
  # @return [Integer] 朔望月
24
24
  SYNODIC_MONTH = 248_057
@@ -20,6 +20,9 @@ module Zakuro
20
20
  module Solar
21
21
  # @return [Cycle::Remainder] 気策(24分の1年)
22
22
  SOLAR_TERM_AVERAGE = Cycle::Remainder.new(day: 15, minute: 1835, second: 5)
23
+ #
24
+ # @note 章月 248057 = 29-4457
25
+ #
23
26
  # @return [Cycle::Remainder] 弦(1分=8秒)
24
27
  QUARTER = Cycle::Remainder.new(day: 7, minute: 3214, second: 2)
25
28
  end
@@ -29,11 +32,12 @@ module Zakuro
29
32
  #
30
33
  module Lunar
31
34
  # @return [Cycle::LunarRemainder] 暦中日
32
- # @note ANOMALISTIC_MONTH の半分に相当する
35
+ # @note ANOMALISTIC_MONTH (1近点月)の半分に相当する
33
36
  HALF_ANOMALISTIC_MONTH = \
34
37
  Cycle::LunarRemainder.new(day: 13, minute: 6529, second: 9.5)
35
- # @return [Cycle::LunarRemainder] 入暦上限
36
- LIMIT = Cycle::LunarRemainder.new(day: 14, minute: 6529, second: 0)
38
+ #
39
+ # @note 章月 248057 = 29-4457
40
+ #
37
41
  # @return [Cycle::LunarRemainder] 弦(1分=100秒)
38
42
  QUARTER = Cycle::LunarRemainder.new(day: 7, minute: 3214, second: 25)
39
43
  end
@@ -11,12 +11,7 @@ module Zakuro
11
11
  # :nodoc:
12
12
  module Cycle
13
13
  #
14
- # Remainder 宣明暦の時刻情報(大余小余)
15
- #
16
- # * 「15日1835分5秒」のような形式で表される
17
- # * 分は8400で一日に繰り上げる
18
- # * 秒は基本的に1/8分で、8秒で1分に繰り上げる。ただし、月補正値は1分に100秒とするなど基数の変更がありえる
19
- # * 十干十二支(60日)を上限とした「日時分秒」の情報で、日付(date)/時刻(time)と部分的に重なる概念
14
+ # Remainder 時刻情報(大余小余)
20
15
  #
21
16
  class Remainder < Calculation::Cycle::AbstractRemainder
22
17
  # @return [Integer] 分(1分=8秒)
@@ -34,6 +29,19 @@ module Zakuro
34
29
  super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
35
30
  day: day, minute: minute, second: second, total: total)
36
31
  end
32
+
33
+ #
34
+ # 特定の文字フォーマットにして出力する
35
+ #
36
+ # @param [String] form フォーマット(大余、小余、秒それぞれを%dで指定する)
37
+ #
38
+ # @return [String] フォーマットした結果
39
+ #
40
+ def format(form: '%d-%d')
41
+ return '' if invalid?
42
+
43
+ super(form, @day, @minute, @second)
44
+ end
37
45
  end
38
46
 
39
47
  #
@@ -55,6 +63,19 @@ module Zakuro
55
63
  super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
56
64
  day: day, minute: minute, second: second, total: total)
57
65
  end
66
+
67
+ #
68
+ # 特定の文字フォーマットにして出力する
69
+ #
70
+ # @param [String] form フォーマット(大余、小余、秒それぞれを%dで指定する)
71
+ #
72
+ # @return [String] フォーマットした結果
73
+ #
74
+ def format(form: '%d-%d')
75
+ return '' if invalid?
76
+
77
+ super(form, @day, @minute, @second)
78
+ end
58
79
  end
59
80
  end
60
81
  end
@@ -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,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../output/logger'
3
+ require_relative '../../../calculation/monthly/abstract_lunar_phase'
4
4
 
5
5
  require_relative '../const/remainder'
6
6
 
@@ -21,108 +21,32 @@ module Zakuro
21
21
  #
22
22
  # LunarPhase 月の位相
23
23
  #
24
- class LunarPhase
24
+ class LunarPhase < Calculation::Monthly::AbstractLunarPhase
25
25
  # @return [Cycle::Remainder] 弦
26
26
  QUARTER = Const::Remainder::Solar::QUARTER
27
27
 
28
- # @return [Output::Logger] ロガー
29
- LOGGER = Output::Logger.new(location: 'lunar_phase')
30
-
31
- # @return [Array<String>] 月内の弦
32
- PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
33
-
34
- # @return [Remainder]] 経
35
- attr_reader :average_remainder
36
- # @return [SolarTerm] 二十四節気(入定気)
37
- attr_reader :solar_term
38
- # @return [Integer] 弦
39
- attr_reader :phase_index
40
-
41
28
  #
42
29
  # 初期化
43
30
  #
44
31
  # @param [Integer] western_year 西暦年
45
32
  #
46
33
  def initialize(western_year:)
47
- # 経
48
- @average_remainder = Origin::AverageNovember.get(western_year: western_year)
49
34
  # 天正閏余
50
35
  lunar_age = Origin::LunarAge.get(western_year: western_year)
51
- # 入定気
52
- @solar_location = Solar::Location.new(lunar_age: lunar_age)
53
- # 入暦
54
- @lunar_location = Lunar::Location.new(
55
- western_year: western_year,
56
- lunar_age: Cycle::LunarRemainder.new(total: 0).add!(lunar_age)
57
- )
58
-
59
- # 弦
60
- @phase_index = 0
61
- end
62
-
63
- #
64
- # 次の弦に進める
65
- #
66
- # @return [Remainder] 定朔
67
- #
68
- def next_phase
69
- adjusted = current_remainder
70
-
71
- add_quarter_moon_size
72
36
 
73
- adjusted
74
- end
75
-
76
- #
77
- # 次の月に進める
78
- # @note 進めた後の月の定朔ではなく、当月のものを返却する
79
- #
80
- # @return [Remainder] 当月初の定朔
81
- #
82
- def next_month
83
- result = nil
84
- PHASE_INDEXES.each_with_index do |_phase, index|
85
- adjust = next_phase
86
- result = adjust if index.zero?
87
- end
88
-
89
- result
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
+ )
90
46
  end
91
47
 
92
48
  private
93
49
 
94
- #
95
- # 次の弦に進める
96
- #
97
- # @return [Integer] 弦
98
- #
99
- def next_phase_index
100
- @phase_index += 1
101
- @phase_index = 0 if @phase_index >= PHASE_INDEXES.size
102
- @phase_index
103
- end
104
-
105
- #
106
- # 朔月(月初)であるか
107
- #
108
- # @return [True] 朔月である
109
- # @return [False] 朔月ではない
110
- #
111
- def first_phase?
112
- @phase_index.zero?
113
- end
114
-
115
- #
116
- # 朔月のみログ出力する
117
- #
118
- # @param [String] messages メッセージ(可変長)
119
- #
120
- def debug(*messages)
121
- return unless first_phase?
122
-
123
- LOGGER.debug(*messages)
124
- end
125
-
126
50
  # :reek:TooManyStatements { max_statements: 6 }
127
51
 
128
52
  #
@@ -144,22 +68,6 @@ module Zakuro
144
68
  adjusted
145
69
  end
146
70
 
147
- #
148
- # 補正値を得る
149
- #
150
- # @return [Integer] 補正値
151
- #
152
- def correction_value
153
- sun = correction_solar_value
154
- moon = correction_moon_value
155
-
156
- sum = sun + moon
157
-
158
- debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
159
-
160
- sum
161
- end
162
-
163
71
  #
164
72
  # 太陽運動の補正値を得る
165
73
  #
@@ -183,7 +91,7 @@ module Zakuro
183
91
  def correction_moon_value
184
92
  @lunar_location.run
185
93
 
186
- remainder = @lunar_location.remainder
94
+ remainder = @lunar_location.adjusted_remainder
187
95
  forward = @lunar_location.forward
188
96
 
189
97
  debug("[lunar]remainder.format: #{remainder.format}")
@@ -191,14 +99,6 @@ module Zakuro
191
99
 
192
100
  Lunar::Value.get(remainder: remainder, forward: forward)
193
101
  end
194
-
195
- def add_quarter_moon_size
196
- @average_remainder.add!(QUARTER)
197
- @solar_location.add_quarter
198
- @lunar_location.add_quarter
199
-
200
- next_phase_index
201
- end
202
102
  end
203
103
  end
204
104
  end
@@ -1,17 +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/lunar/location'
9
- require_relative '../stella/lunar/value'
10
5
  require_relative '../stella/solar/average'
11
- require_relative '../stella/solar/location'
12
- require_relative '../stella/solar/value'
13
- require_relative '../stella/origin/lunar_age'
14
- require_relative '../stella/origin/average_november'
15
6
 
16
7
  # :nodoc:
17
8
  module Zakuro
@@ -23,11 +14,6 @@ module Zakuro
23
14
  # AnnualRange 年間範囲
24
15
  #
25
16
  module AnnualRange
26
- # @return [Output::Logger] ロガー
27
- LOGGER = Output::Logger.new(location: 'annual_range')
28
-
29
- # :reek:TooManyStatements { max_statements: 6 }
30
-
31
17
  #
32
18
  # 一覧取得する
33
19
  #
@@ -40,71 +26,13 @@ module Zakuro
40
26
  # @return [Array<Month>] 1年データ
41
27
  #
42
28
  def self.get(context:, western_year:)
43
- annual_range = initialized_annual_range(context: context, western_year: western_year)
44
-
45
- apply_big_and_small_of_the_month(annual_range: annual_range)
46
-
47
- solar_average = Solar::Average.new(western_year: western_year)
48
- solar_average.set(annual_range: annual_range)
49
-
50
- # 月間隔を取得するためだけの末尾要素を削除
51
- annual_range.pop
52
-
53
- initialize_month_label(annual_range: annual_range)
54
- end
55
-
56
- #
57
- # 1年データを取得する
58
- #
59
- # @param [Context] context 暦コンテキスト
60
- # @param [Integer] western_year 西暦年
61
- #
62
- # @return [Array<Month>] 1年データ
63
- #
64
- def self.initialized_annual_range(context:, western_year:)
65
- result = []
66
29
  lunar_phase = Monthly::LunarPhase.new(western_year: western_year)
30
+ solar_average = Solar::Average.new(western_year: western_year)
67
31
 
68
- # 14ヶ月分を生成する(閏年で最大13ヶ月 + 末月の大小/二十四節気を求めるために必要な月)
69
- (0..13).each do |_index|
70
- adjusted = lunar_phase.next_month
71
-
72
- result.push(
73
- Calculation::Monthly::InitializedMonth.new(
74
- context: context,
75
- month_label: Calculation::Monthly::MonthLabel.new,
76
- first_day: Calculation::Monthly::FirstDay.new(remainder: adjusted),
77
- phase_index: 0
78
- )
79
- )
80
- end
81
-
82
- result
83
- end
84
- private_class_method :initialized_annual_range
85
-
86
- #
87
- # 1年データの各月に月の大小を設定する
88
- #
89
- # @param [Array<Month>] annual_range 1年データ
90
- #
91
- def self.apply_big_and_small_of_the_month(annual_range:)
92
- # NOTE: 最後の月は処理できない(=計算外の余分な月が最後に必要である)
93
- annual_range.each_cons(2) do |(current_month, next_month)|
94
- current_month.eval_many_days(next_month_day: next_month.remainder.day)
95
- end
96
- end
97
- private_class_method :apply_big_and_small_of_the_month
98
-
99
- #
100
- # 月表示情報を更新する
101
- #
102
- # @param [Array<Month>] annual_range 1年データ
103
- #
104
- def self.initialize_month_label(annual_range:)
105
- 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
+ )
106
35
  end
107
- private_class_method :initialize_month_label
108
36
  end
109
37
  end
110
38
  end
@@ -12,7 +12,7 @@ module Zakuro
12
12
  # Localization 入暦特定
13
13
  #
14
14
  module Localization
15
- # @return [Integer] 1近日点
15
+ # @return [Integer] 1近点月
16
16
  ANOMALISTIC_MONTH = Const::Number::Cycle::ANOMALISTIC_MONTH
17
17
  # @return [Integer] 積年
18
18
  TOTAL_YEAR = Const::Number::Stack::TOTAL_YEAR
@@ -34,8 +34,7 @@ module Zakuro
34
34
  total_year = TOTAL_YEAR + western_year - BEGIN_YEAR
35
35
 
36
36
  # 通積分 - 天正閏余
37
- total_day = \
38
- total_year * YEAR - lunar_age.to_minute
37
+ total_day = total_year * YEAR - lunar_age.to_minute
39
38
 
40
39
  Cycle::LunarRemainder.new(total: (total_day % ANOMALISTIC_MONTH))
41
40
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../../../calculation/stella/lunar/abstract_location'
4
+
3
5
  require_relative '../../const/remainder'
4
6
 
5
7
  require_relative './localization'
@@ -13,38 +15,26 @@ module Zakuro
13
15
  #
14
16
  # Location 入暦
15
17
  #
16
- class Location
17
- # @return [Cycle::LunarRemainder] 暦中日
18
+ class Location < Calculation::Lunar::AbstractLocation
19
+ # @return [Cycle::LunarRemainder] 暦中日(1近点月の半分)
18
20
  HALF_ANOMALISTIC_MONTH = Const::Remainder::Lunar::HALF_ANOMALISTIC_MONTH
19
- # @return [Cycle::LunarRemainder] 入暦上限
20
- LIMIT = Const::Remainder::Lunar::LIMIT
21
21
  # @return [Cycle::LunarRemainder] 弦
22
22
  QUARTER = Const::Remainder::Lunar::QUARTER
23
23
 
24
- # @return [True] 計算済み(前回計算あり)
25
- # @return [False] 未計算(初回計算)
26
- attr_reader :calculated
27
- # @return [Integer] 西暦年
28
- attr_reader :western_year
29
- # @return [True] 進(遠地点より数える)
30
- # @return [False] 退(近地点より数える)
24
+ # @return [True]
25
+ # @return [False] 退
31
26
  attr_reader :forward
32
- # @return [Cycle::LunarRemainder] 大余小余(初回:昨年天正閏余)
33
- attr_reader :remainder
34
27
 
35
28
  #
36
29
  # 初期化
37
30
  #
38
31
  # @param [Cycle::LunarRemainder] lunar_age 天正閏余(大余小余)
39
32
  # @param [Integer] western_year 西暦年
40
- # @param [True, False] forward 進(遠地点より数える)/退(近地点より数える)
41
33
  #
42
34
  def initialize(lunar_age:, western_year:)
43
- @calculated = false
44
- @western_year = western_year
35
+ super(lunar_age: lunar_age, western_year: western_year)
45
36
  # 進
46
37
  @forward = true
47
- @remainder = lunar_age
48
38
  end
49
39
 
50
40
  #
@@ -52,8 +42,7 @@ module Zakuro
52
42
  #
53
43
  def run
54
44
  if calculated
55
- # 1始まりで計算しているので、入暦上限を用いる
56
- decrease(limit: LIMIT)
45
+ decrease(limit: HALF_ANOMALISTIC_MONTH)
57
46
  return
58
47
  end
59
48
 
@@ -64,7 +53,7 @@ module Zakuro
64
53
  # 弦の分だけ月地点を進める
65
54
  #
66
55
  def add_quarter
67
- @remainder.add!(QUARTER)
56
+ remainder.add!(QUARTER)
68
57
  end
69
58
 
70
59
  private
@@ -74,12 +63,9 @@ module Zakuro
74
63
  #
75
64
  def first
76
65
  @remainder = Localization.first_remainder(
77
- lunar_age: @remainder, western_year: @western_year
66
+ lunar_age: remainder, western_year: western_year
78
67
  )
79
- # 初回は0始まりで計算しているので、暦中日を用いる
80
68
  decrease(limit: HALF_ANOMALISTIC_MONTH)
81
- # 1始まりに改める
82
- one_based
83
69
 
84
70
  @calculated = true
85
71
  end
@@ -90,17 +76,10 @@ module Zakuro
90
76
  # @param [Cycle::LunarRemainder] limit 上限
91
77
  #
92
78
  def decrease(limit:)
93
- return if @remainder < limit
94
-
95
- @remainder.sub!(HALF_ANOMALISTIC_MONTH)
96
- @forward = !@forward
97
- end
79
+ return if remainder < limit
98
80
 
99
- #
100
- # 1始まりにする
101
- #
102
- def one_based
103
- @remainder.add!(Cycle::Remainder.new(day: 1, minute: 0, second: 0))
81
+ remainder.sub!(limit)
82
+ @forward = !forward
104
83
  end
105
84
  end
106
85
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../../../calculation/stella/lunar/choukei_value'
4
+
3
5
  require_relative '../../cycle/remainder'
4
6
 
5
7
  require_relative './adjustment'
@@ -27,19 +29,20 @@ module Zakuro
27
29
  def self.get(remainder:, forward:)
28
30
  valid?(remainder: remainder)
29
31
 
30
- day = remainder.day
31
- minute = remainder.floor_minute
32
+ day, minute = Calculation::Lunar::ChoukeiValue.remainder_without_second(
33
+ remainder: remainder
34
+ )
32
35
 
33
36
  # 引き当て
34
37
  row = Adjustment.specify(forward: forward, day: day, minute: minute)
35
38
 
36
39
  value = row.value
37
- denominator = row.denominator
38
40
 
39
41
  minus_minute = Adjustment.minus_minute(day: day, minute: minute)
40
42
 
41
- day = calc_day(per: value.per, denominator: denominator,
42
- minute: minus_minute)
43
+ day = Calculation::Lunar::ChoukeiValue.rounded_day(
44
+ per: value.per, denominator: row.denominator, minute: minus_minute
45
+ )
43
46
 
44
47
  value.stack + day
45
48
  end
@@ -58,31 +61,6 @@ module Zakuro
58
61
  raise ArgumentError, "unmatch parameter type: #{remainder.class}"
59
62
  end
60
63
  private_class_method :valid?
61
-
62
- # :reek:TooManyStatements { max_statements: 9 }
63
-
64
- #
65
- # 累計値(大余)を作成する
66
- #
67
- # @param [Integer] per 入暦(1-14)
68
- # @param [Integer] denominator 小余の分母
69
- # @param [Integer] minute 小余
70
- #
71
- # @return [Integer] 累計値(大余)
72
- #
73
- def self.calc_day(per:, denominator:, minute:)
74
- remainder_minute = (per * minute).to_f
75
- day = remainder_minute / denominator
76
- # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
77
- day = day.negative? ? day.ceil : day.floor
78
- sign = remainder_minute.negative? ? -1 : 1
79
- remainder_day = (sign * remainder_minute) % denominator
80
- # 四捨五入(8400ならその半分の4200以上を繰り上げる)
81
- day += sign if remainder_day >= (denominator / 2)
82
-
83
- day
84
- end
85
- private_class_method :calc_day
86
64
  end
87
65
  end
88
66
  end