zakuro 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +12 -0
  3. data/lib/zakuro/calculation/range/full_range.rb +1 -1
  4. data/lib/zakuro/version.rb +1 -1
  5. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  6. data/lib/zakuro/version/senmyou/const/remainder.rb +43 -0
  7. data/lib/zakuro/version/senmyou/cycle/remainder.rb +4 -6
  8. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +35 -54
  9. data/lib/zakuro/version/senmyou/range/annual_range.rb +9 -65
  10. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  11. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +45 -0
  12. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +108 -0
  13. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +89 -0
  14. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  15. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  16. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  17. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  18. data/lib/zakuro/version/senmyou/stella/solar/average.rb +175 -0
  19. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  20. data/lib/zakuro/version/senmyou/stella/solar/location.rb +164 -0
  21. data/lib/zakuro/version/senmyou/stella/solar/value.rb +138 -0
  22. metadata +20 -11
  23. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  24. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  25. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  26. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  27. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b346e15da34df44ce5692780edbd4b73a46161f8ab9c52a0a3b5e11708f60c9
4
- data.tar.gz: 664d457a7e3a5a271073633bba9d2b85c94c1edc35d2ceaa5a0649d10c628202
3
+ metadata.gz: a5bbb00f73830eff0f9e912c0fa0c10d49d7849b3f46395c19de8ec1f71f8012
4
+ data.tar.gz: e95b80813e7ce382e0c5fce6a62382d3c26383db6f0b7e64e82bd1f005a6f15c
5
5
  SHA512:
6
- metadata.gz: 95779bea84d41f42027b8974742a924050c9b668f258a116d564b94991987ff5ac81554a6d8e518f8d7cc2bcd018eb9f082df6a997819d43fa475bfd3cd6f1bd
7
- data.tar.gz: 4624affe06f638a930c36f80c357deb8ce311af730a67e2a296491efab1b3c648e3a5f5473b3f5fbfd6e9e088644bc7a29741204a9aac71517d1b4aef2dc3568
6
+ metadata.gz: a3bb973f87a0bb6e3d3caffca76e9cc57cf5748e16bb3e9f87b3e9ffe2307682646aa08077ad6685a04ec282d255aa0f3ecf5992d2595f89bcd00b364aa22f45
7
+ data.tar.gz: f85ca93529ec87eb15e97f2564509429b95d8433c22d3141bdef26fa79154689030d9552ca38e8e81812289d5adf272b8445e510a21967cd9b517c805e6956a5
@@ -331,6 +331,18 @@ module Zakuro
331
331
  @day * @base_day + @minute
332
332
  end
333
333
 
334
+ #
335
+ # 小余(秒切り捨て)を返す
336
+ #
337
+ # @note 切り捨て前に繰り上げる
338
+ #
339
+ # @return [Integer] 小余(秒切り捨て)
340
+ #
341
+ def floor_minute
342
+ result = @minute + @second / @base_minute
343
+ result.floor
344
+ end
345
+
334
346
  #
335
347
  # 大余に四捨五入した結果を返す(秒は除外する)
336
348
  #
@@ -111,7 +111,7 @@ module Zakuro
111
111
  years = []
112
112
  ((oldest_date.year)..(newest_date.year + 2)).each do |year|
113
113
  years.push(
114
- annual_range.collect_annual_range_after_last_november_1st(
114
+ annual_range.get(
115
115
  context: @context, western_year: year
116
116
  )
117
117
  )
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Zakuro
5
5
  # @return [String] library version
6
- VERSION = '0.1.4'
6
+ VERSION = '0.1.5'
7
7
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Senmyou
7
+ #
8
+ # Const 定数
9
+ #
10
+ module Const
11
+ #
12
+ # Number 数値
13
+ #
14
+ module Number
15
+ #
16
+ # Cycle 周期
17
+ #
18
+ module Cycle
19
+ # @return [Integer] 統法(1日=8400分)
20
+ DAY = 8400
21
+ # @return [Integer] 暦周(1近日点)
22
+ ANOMALISTIC_MONTH = 231_458.19
23
+ # @return [Integer] 朔望月
24
+ SYNODIC_MONTH = 248_057
25
+ # @return [Integer] 一年
26
+ YEAR = 3_068_055
27
+ end
28
+
29
+ #
30
+ # Derivation 導出
31
+ #
32
+ module Derivation
33
+ # @return [Integer] 通余: (YEAR - DAY * 12 * 30) = 44055
34
+ REMAINDER_ALL_YEAR = 44_055
35
+ # @return [Integer] 旬周(60日) DAY * 60
36
+ SIXTY_DAYS = 504_000
37
+ end
38
+
39
+ #
40
+ # 累積
41
+ #
42
+ module Stack
43
+ # @return [Integer] 積年(甲子夜半朔旦冬至〜暦の開始前)
44
+ TOTAL_YEAR = 7_070_138
45
+ # @return [Integer] 暦の開始年(長慶2年)
46
+ BEGIN_YEAR = 822
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../cycle/remainder'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Senmyou
9
+ #
10
+ # Const 定数
11
+ #
12
+ module Const
13
+ #
14
+ # Remainder 大余小余
15
+ #
16
+ module Remainder
17
+ #
18
+ # Solar 太陽
19
+ #
20
+ module Solar
21
+ # @return [Cycle::Remainder] 気策(24分の1年)
22
+ SOLAR_TERM_AVERAGE = Cycle::Remainder.new(day: 15, minute: 1835, second: 5)
23
+ # @return [Cycle::Remainder] 弦(1分=8秒)
24
+ QUARTER = Cycle::Remainder.new(day: 7, minute: 3214, second: 2)
25
+ end
26
+
27
+ #
28
+ # Lunar 月
29
+ #
30
+ module Lunar
31
+ # @return [Cycle::LunarRemainder] 暦中日
32
+ # @note ANOMALISTIC_MONTH の半分に相当する
33
+ HALF_ANOMALISTIC_MONTH = \
34
+ 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)
37
+ # @return [Cycle::LunarRemainder] 弦(1分=100秒)
38
+ QUARTER = Cycle::LunarRemainder.new(day: 7, minute: 3214, second: 25)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative '../../../calculation/cycle/abstract_remainder'
4
4
 
5
+ require_relative '../const/number'
6
+
5
7
  # :nodoc:
6
8
  module Zakuro
7
9
  # :nodoc:
@@ -17,8 +19,6 @@ module Zakuro
17
19
  # * 十干十二支(60日)を上限とした「日時分秒」の情報で、日付(date)/時刻(time)と部分的に重なる概念
18
20
  #
19
21
  class Remainder < Calculation::Cycle::AbstractRemainder
20
- # @return [Integer] 統法(1日=8400分)
21
- DAY = 8400
22
22
  # @return [Integer] 分(1分=8秒)
23
23
  MINUTE = 8
24
24
 
@@ -31,7 +31,7 @@ module Zakuro
31
31
  # @param [Integer] total 繰り上げなしの小余
32
32
  #
33
33
  def initialize(day: -1, minute: -1, second: -1, total: -1)
34
- super(base_day: DAY, base_mitune: MINUTE,
34
+ super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
35
35
  day: day, minute: minute, second: second, total: total)
36
36
  end
37
37
  end
@@ -40,8 +40,6 @@ module Zakuro
40
40
  # LunarRemainder 月の位相計算向け時刻情報(大余小余)
41
41
  #
42
42
  class LunarRemainder < Calculation::Cycle::AbstractRemainder
43
- # @return [Integer] 統法(1日=8400分)
44
- DAY = 8400
45
43
  # @return [Integer] 分(1分=100秒)
46
44
  MINUTE = 100
47
45
 
@@ -54,7 +52,7 @@ module Zakuro
54
52
  # @param [Integer] total 繰り上げなしの小余
55
53
  #
56
54
  def initialize(day: -1, minute: -1, second: -1, total: -1)
57
- super(base_day: DAY, base_mitune: MINUTE,
55
+ super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
58
56
  day: day, minute: minute, second: second, total: total)
59
57
  end
60
58
  end
@@ -2,7 +2,15 @@
2
2
 
3
3
  require_relative '../../../output/logger'
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,21 +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
24
  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
25
+ # @return [Cycle::Remainder] 弦
26
+ QUARTER = Const::Remainder::Solar::QUARTER
28
27
 
29
28
  # @return [Output::Logger] ロガー
30
29
  LOGGER = Output::Logger.new(location: 'lunar_phase')
@@ -32,20 +31,10 @@ module Zakuro
32
31
  # @return [Array<String>] 月内の弦
33
32
  PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
34
33
 
35
- # @return [Integer] 西暦年
36
- attr_reader :western_year
37
34
  # @return [Remainder]] 経
38
35
  attr_reader :average_remainder
39
- # @return [True] 初回計算
40
- # @return [False] 次回以降計算
41
- attr_reader :first
42
36
  # @return [SolarTerm] 二十四節気(入定気)
43
37
  attr_reader :solar_term
44
- # @return [Remainder] 入暦
45
- attr_reader :moon_remainder
46
- # @return [True] 進(遠地点より数える)
47
- # @return [False] 退(近地点より数える)
48
- attr_reader :is_forward
49
38
  # @return [Integer] 弦
50
39
  attr_reader :phase_index
51
40
 
@@ -55,21 +44,17 @@ module Zakuro
55
44
  # @param [Integer] western_year 西暦年
56
45
  #
57
46
  def initialize(western_year:)
58
- @western_year = western_year
59
47
  # 経
60
- @average_remainder = WinterSolstice.calc_averaged_last_november_1st(
61
- western_year: @western_year
62
- )
48
+ @average_remainder = Origin::AverageNovember.get(western_year: western_year)
63
49
  # 天正閏余
64
- winter_solstice_age = \
65
- WinterSolstice.calc_moon_age(western_year: @western_year)
50
+ lunar_age = Origin::LunarAge.get(western_year: western_year)
66
51
  # 入定気
67
- @solar_term = Cycle::SolarTerm.new(remainder: winter_solstice_age)
52
+ @solar_location = Solar::Location.new(lunar_age: lunar_age)
68
53
  # 入暦
69
- @moon_remainder = Cycle::LunarRemainder.new(total: 0).add!(winter_solstice_age)
70
-
71
- @is_forward = false
72
- @first = true
54
+ @lunar_location = Lunar::Location.new(
55
+ western_year: western_year,
56
+ lunar_age: Cycle::LunarRemainder.new(total: 0).add!(lunar_age)
57
+ )
73
58
 
74
59
  # 弦
75
60
  @phase_index = 0
@@ -83,8 +68,6 @@ module Zakuro
83
68
  def next_phase
84
69
  adjusted = current_remainder
85
70
 
86
- @first = false if @first
87
-
88
71
  add_quarter_moon_size
89
72
 
90
73
  adjusted
@@ -120,7 +103,7 @@ module Zakuro
120
103
  end
121
104
 
122
105
  #
123
- # 朔月(月初)かを確認する
106
+ # 朔月(月初)であるか
124
107
  #
125
108
  # @return [True] 朔月である
126
109
  # @return [False] 朔月ではない
@@ -183,38 +166,36 @@ module Zakuro
183
166
  # @return [Integer] 太陽運動の補正値
184
167
  #
185
168
  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}")
169
+ @solar_location.run
170
+ debug("@solar_term.remainder: #{@solar_location.remainder.format(form: '%d-%d.%d')}")
171
+ debug("@solar_term.index: #{@solar_location.index}")
191
172
 
192
- SolarOrbit.calc_sun_orbit_value(solar_term: @solar_term)
173
+ Solar::Value.get(solar_location: @solar_location)
193
174
  end
194
175
 
176
+ # :reek:TooManyStatements { max_statements: 6 }
177
+
195
178
  #
196
179
  # 月運動の補正値を得る
197
180
  #
198
181
  # @return [Integer] 月運動の補正値
199
182
  #
200
183
  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)
184
+ @lunar_location.run
185
+
186
+ remainder = @lunar_location.remainder
187
+ forward = @lunar_location.forward
206
188
 
207
- debug("@moon_remainder.format: #{@moon_remainder.format}")
208
- debug("@is_forward: #{@is_forward}")
189
+ debug("[lunar]remainder.format: #{remainder.format}")
190
+ debug("[lunar]forward: #{forward}")
209
191
 
210
- LunarOrbit.calc_moon_orbit_value(remainder_month: @moon_remainder,
211
- is_forward: @is_forward)
192
+ Lunar::Value.get(remainder: remainder, forward: forward)
212
193
  end
213
194
 
214
195
  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)
196
+ @average_remainder.add!(QUARTER)
197
+ @solar_location.add_quarter
198
+ @lunar_location.add_quarter
218
199
 
219
200
  next_phase_index
220
201
  end
@@ -5,10 +5,13 @@ require_relative '../cycle/remainder'
5
5
  require_relative '../cycle/solar_term'
6
6
  require_relative '../../../calculation/monthly/initialized_month'
7
7
  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'
8
+ require_relative '../stella/lunar/location'
9
+ require_relative '../stella/lunar/value'
10
+ 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'
12
15
 
13
16
  # :nodoc:
14
17
  module Zakuro
@@ -25,37 +28,6 @@ module Zakuro
25
28
 
26
29
  # :reek:TooManyStatements { max_statements: 6 }
27
30
 
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
31
  #
60
32
  # 一覧取得する
61
33
  #
@@ -67,12 +39,12 @@ module Zakuro
67
39
  #
68
40
  # @return [Array<Month>] 1年データ
69
41
  #
70
- def self.collect_annual_range_after_last_november_1st(context:, western_year:)
42
+ def self.get(context:, western_year:)
71
43
  annual_range = initialized_annual_range(context: context, western_year: western_year)
72
44
 
73
45
  apply_big_and_small_of_the_month(annual_range: annual_range)
74
46
 
75
- solar_average = SolarAverage.new(western_year: western_year)
47
+ solar_average = Solar::Average.new(western_year: western_year)
76
48
  solar_average.set(annual_range: annual_range)
77
49
 
78
50
  # 月間隔を取得するためだけの末尾要素を削除
@@ -81,34 +53,6 @@ module Zakuro
81
53
  initialize_month_label(annual_range: annual_range)
82
54
  end
83
55
 
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
56
  #
113
57
  # 1年データを取得する
114
58
  #