zakuro 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -12
  3. data/doc/operation/csv/month.csv +202 -202
  4. data/doc/operation/operation.xlsx +0 -0
  5. data/doc/operation/transfer.rb +6 -2
  6. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  7. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  8. data/lib/zakuro/calculation/base/year.rb +107 -0
  9. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +471 -0
  10. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  11. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  12. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  13. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  14. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  15. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  16. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  17. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  18. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  19. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  20. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  21. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  22. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  23. data/lib/zakuro/calculation/summary/single.rb +129 -0
  24. data/lib/zakuro/condition.rb +16 -13
  25. data/lib/zakuro/era/japan/gengou/parser.rb +1 -3
  26. data/lib/zakuro/era/japan/gengou/type.rb +3 -3
  27. data/lib/zakuro/era/japan/gengou/validator.rb +15 -13
  28. data/lib/zakuro/merchant.rb +2 -2
  29. data/lib/zakuro/operation/month/parser.rb +132 -36
  30. data/lib/zakuro/operation/month/type.rb +11 -10
  31. data/lib/zakuro/operation/month/validator.rb +332 -28
  32. data/lib/zakuro/operation/operation.rb +21 -0
  33. data/lib/zakuro/operation/yaml/month.yaml +1 -1
  34. data/lib/zakuro/output/error.rb +7 -6
  35. data/lib/zakuro/output/logger.rb +50 -49
  36. data/lib/zakuro/output/response.rb +145 -144
  37. data/lib/zakuro/result/operation.rb +64 -36
  38. data/lib/zakuro/tools/stringifier.rb +2 -2
  39. data/lib/zakuro/tools/typeof.rb +2 -2
  40. data/lib/zakuro/version.rb +1 -1
  41. data/lib/zakuro/version/abstract_version.rb +1 -1
  42. data/lib/zakuro/version/context.rb +23 -0
  43. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  44. data/lib/zakuro/version/senmyou/const/remainder.rb +43 -0
  45. data/lib/zakuro/version/senmyou/cycle/remainder.rb +61 -0
  46. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
  47. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +166 -181
  48. data/lib/zakuro/version/senmyou/range/annual_range.rb +86 -159
  49. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  50. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  51. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +45 -0
  52. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +108 -0
  53. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +89 -0
  54. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  55. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  56. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  57. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  58. data/lib/zakuro/version/senmyou/stella/solar/average.rb +175 -0
  59. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  60. data/lib/zakuro/version/senmyou/stella/solar/location.rb +164 -0
  61. data/lib/zakuro/version/senmyou/stella/solar/value.rb +138 -0
  62. data/lib/zakuro/version/version_class_resolver.rb +62 -0
  63. data/lib/zakuro/version_factory.rb +2 -2
  64. metadata +38 -24
  65. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  66. data/lib/zakuro/cycle/zodiac.rb +0 -103
  67. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  68. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  69. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  70. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  71. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -76
  72. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  73. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  74. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -48
  75. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  76. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  77. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -167
  78. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -324
  79. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -105
  80. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -163
  81. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -99
  82. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  83. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -214
  84. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -394
  85. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  86. data/lib/zakuro/version/senmyou/summary/single.rb +0 -71
@@ -17,7 +17,7 @@ module Zakuro
17
17
  # @return [True] 運用あり
18
18
  # @return [False] 運用なし
19
19
  attr_reader :operated
20
- # @return [Month] 月別履歴情報
20
+ # @return [Month::Bundle] 月別履歴情報
21
21
  attr_reader :month
22
22
  # @return [Data::SingleDay] 計算値
23
23
  attr_reader :original
@@ -26,7 +26,7 @@ module Zakuro
26
26
  # 初期化
27
27
  #
28
28
  # @param [True, False] operated 運用有無
29
- # @param [Month] month 月別履歴情報
29
+ # @param [Month::Bundle] month 月別履歴情報
30
30
  # @param [Data::SingleDay] original 計算値
31
31
  #
32
32
  def initialize(operated:, month:, original:)
@@ -37,48 +37,76 @@ module Zakuro
37
37
  end
38
38
 
39
39
  #
40
- # Month 月別履歴情報
40
+ # Month 運用情報(月)
41
41
  #
42
- class Month
43
- # @return [Integer] 原文頁数
44
- attr_reader :page
45
- # @return [Integer] 原文注釈番号
46
- attr_reader :number
47
- # @return [Array<Zakuro::Result::Operation::Annotation>] 注釈
48
- attr_reader :annotations
49
-
50
- #
51
- # 初期化
42
+ module Month
52
43
  #
53
- # @param [Integer] page 原文頁数
54
- # @param [Integer] number 原文注釈番号
55
- # @param [Array<Zakuro::Result::Operation::Annotation>] annotations 注釈
44
+ # Bundle 月履歴集約情報
56
45
  #
57
- def initialize(page: -1, number: -1, annotations: [])
58
- @page = page
59
- @number = number
60
- @annotations = annotations
61
- end
62
- end
46
+ class Bundle
47
+ # @return [History] 月別履歴情報(当月)
48
+ attr_reader :current
49
+ # @return [History] 月別履歴情報(影響を与えた月)
50
+ attr_reader :parent
63
51
 
64
- #
65
- # Annotation 注釈
66
- #
67
- class Annotation
68
- # @return [String] 注釈内容
69
- attr_reader :description
70
- # @return [String] 注釈補記
71
- attr_reader :note
52
+ def initialize(current: History.new, parent: History.new)
53
+ @current = current
54
+ @parent = parent
55
+ end
56
+ end
72
57
 
73
58
  #
74
- # 初期化
59
+ # History 月別履歴情報
75
60
  #
76
- # @param [String] description 注釈内容
77
- # @param [<Type>] note 注釈補記
61
+ class History
62
+ # @return [String] ID
63
+ attr_reader :id
64
+ # @return [String] 月初日の西暦日
65
+ attr_reader :western_date
66
+ # @return [Integer] 原文頁数
67
+ attr_reader :page
68
+ # @return [Integer] 原文注釈番号
69
+ attr_reader :number
70
+ # @return [Array<Zakuro::Result::Operation::Annotation>] 注釈
71
+ attr_reader :annotations
72
+
73
+ #
74
+ # 初期化
75
+ #
76
+ # @param [String] id ID
77
+ # @param [String] western_date 月初日の西暦日
78
+ # @param [Integer] page 原文頁数
79
+ # @param [Integer] number 原文注釈番号
80
+ # @param [Array<Annotation>] annotations 注釈
81
+ #
82
+ def initialize(id: '', western_date: '', page: -1, number: -1, annotations: [])
83
+ @id = id
84
+ @western_date = western_date
85
+ @page = page
86
+ @number = number
87
+ @annotations = annotations
88
+ end
89
+ end
90
+
91
+ #
92
+ # Annotation 注釈
78
93
  #
79
- def initialize(description:, note:)
80
- @description = description
81
- @note = note
94
+ class Annotation
95
+ # @return [String] 注釈内容
96
+ attr_reader :description
97
+ # @return [String] 注釈補記
98
+ attr_reader :note
99
+
100
+ #
101
+ # 初期化
102
+ #
103
+ # @param [String] description 注釈内容
104
+ # @param [<Type>] note 注釈補記
105
+ #
106
+ def initialize(description:, note:)
107
+ @description = description
108
+ @note = note
109
+ end
82
110
  end
83
111
  end
84
112
  end
@@ -31,7 +31,7 @@ module Zakuro
31
31
  hash
32
32
  end
33
33
 
34
- # :reek:TooManyStatements { max_statements: 7 } and :reek:NilCheck
34
+ # :reek:TooManyStatements { max_statements: 7 }
35
35
 
36
36
  #
37
37
  # 対象インスタンスをハッシュ化する(再帰処理)
@@ -42,7 +42,7 @@ module Zakuro
42
42
  # @return [Hash<String, Objcet>] ハッシュ
43
43
  #
44
44
  def self.value_to_hash(obj:, class_prefix:, formatted:)
45
- return obj if obj.nil?
45
+ return obj unless obj
46
46
 
47
47
  # 日付をフォーマットする
48
48
  return obj.format if formatted && Tools::Typeof.time?(obj: obj)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../cycle/abstract_remainder'
3
+ require_relative '../calculation/cycle/abstract_remainder'
4
4
  require_relative '../era/western'
5
5
 
6
6
  # :nodoc:
@@ -24,7 +24,7 @@ module Zakuro
24
24
  def self.time?(obj:)
25
25
  return true if obj.is_a?(Western::Calendar)
26
26
 
27
- return true if obj.is_a?(Cycle::AbstractRemainder)
27
+ return true if obj.is_a?(Calculation::Cycle::AbstractRemainder)
28
28
 
29
29
  false
30
30
  end
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Zakuro
5
5
  # @return [String] library version
6
- VERSION = '0.1.0'
6
+ VERSION = '0.1.5'
7
7
  end
@@ -17,7 +17,7 @@ module Zakuro
17
17
  #
18
18
  # @param [Date] western_date 西暦日
19
19
  #
20
- # @return [Result::SingleDay] 和暦日
20
+ # @return [Result::Single] 和暦日
21
21
  #
22
22
  # @raise [NotImplementedError] オーバーライドなし
23
23
  #
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './version_class_resolver'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Context 暦コンテキスト
9
+ #
10
+ class Context
11
+ attr_reader :version_name
12
+ attr_reader :resolver
13
+
14
+ VERSION_NAMES = %w[Genka Gihou Taien Senmyou Joukyou Kansei Tenpou Gregorio].freeze
15
+
16
+ def initialize(version_name:)
17
+ raise ArgumentError.new, 'invalid version' unless VERSION_NAMES.include?(version_name)
18
+
19
+ @version_name = version_name
20
+ @resolver = VersionClassResolver.new(version_name: version_name)
21
+ end
22
+ end
23
+ 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
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/cycle/abstract_remainder'
4
+
5
+ require_relative '../const/number'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Senmyou
11
+ # :nodoc:
12
+ module Cycle
13
+ #
14
+ # Remainder 宣明暦の時刻情報(大余小余)
15
+ #
16
+ # * 「15日1835分5秒」のような形式で表される
17
+ # * 分は8400で一日に繰り上げる
18
+ # * 秒は基本的に1/8分で、8秒で1分に繰り上げる。ただし、月補正値は1分に100秒とするなど基数の変更がありえる
19
+ # * 十干十二支(60日)を上限とした「日時分秒」の情報で、日付(date)/時刻(time)と部分的に重なる概念
20
+ #
21
+ class Remainder < Calculation::Cycle::AbstractRemainder
22
+ # @return [Integer] 分(1分=8秒)
23
+ MINUTE = 8
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [Integer] day 大余("日"に相当)
29
+ # @param [Integer] minute 小余("分"に相当)
30
+ # @param [Integer] second 秒
31
+ # @param [Integer] total 繰り上げなしの小余
32
+ #
33
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
34
+ super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
35
+ day: day, minute: minute, second: second, total: total)
36
+ end
37
+ end
38
+
39
+ #
40
+ # LunarRemainder 月の位相計算向け時刻情報(大余小余)
41
+ #
42
+ class LunarRemainder < Calculation::Cycle::AbstractRemainder
43
+ # @return [Integer] 分(1分=100秒)
44
+ MINUTE = 100
45
+
46
+ #
47
+ # 初期化
48
+ #
49
+ # @param [Integer] day 大余("日"に相当)
50
+ # @param [Integer] minute 小余("分"に相当)
51
+ # @param [Integer] second 秒
52
+ # @param [Integer] total 繰り上げなしの小余
53
+ #
54
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
55
+ super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
56
+ day: day, minute: minute, second: second, total: total)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/cycle/abstract_solar_term'
4
+ require_relative './remainder'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Senmyou
10
+ # :nodoc:
11
+ module Cycle
12
+ #
13
+ # SolarTerm 二十四節気
14
+ #
15
+ class SolarTerm < Calculation::Cycle::AbstractSolarTerm
16
+ # @return [Remainder] 気策(24分の1年)
17
+ SOLAR_TERM_AVERAGE = Remainder.new(day: 15, minute: 1835, second: 5)
18
+
19
+ #
20
+ # 初期化
21
+ #
22
+ # @param [Integer] index 連番
23
+ # @param [Remainder] remainder 時刻情報(大余小余)
24
+ #
25
+ def initialize(index: -1, remainder: Remainder.new)
26
+ super(index: index, remainder: remainder, average: SOLAR_TERM_AVERAGE)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,218 +2,203 @@
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
9
17
  # :nodoc:
10
18
  module Senmyou
11
- # :reek:TooManyStatements { max_statements: 7 }
12
- # :reek:TooManyInstanceVariables { max_instance_variables: 7 }
19
+ # :nodoc:
20
+ module Monthly
21
+ #
22
+ # LunarPhase 月の位相
23
+ #
24
+ class LunarPhase
25
+ # @return [Cycle::Remainder] 弦
26
+ QUARTER = Const::Remainder::Solar::QUARTER
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
+ #
42
+ # 初期化
43
+ #
44
+ # @param [Integer] western_year 西暦年
45
+ #
46
+ def initialize(western_year:)
47
+ # 経
48
+ @average_remainder = Origin::AverageNovember.get(western_year: western_year)
49
+ # 天正閏余
50
+ 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
13
62
 
14
- #
15
- # LunarPhase 月の位相
16
- #
17
- class LunarPhase
18
- #
19
- # QuarterMoon 弦
20
- #
21
- module QuarterMoon
22
- # @return [Remainder] 弦(1分=8秒)
23
- DEFAULT = Remainder.new(day: 7, minute: 3214, second: 2)
24
- # @return [Remainder] 弦(1分=100秒)
25
- BASE_HUNDRED = LunarRemainder.new(day: 7, minute: 3214, second: 25)
26
- end
63
+ #
64
+ # 次の弦に進める
65
+ #
66
+ # @return [Remainder] 定朔
67
+ #
68
+ def next_phase
69
+ adjusted = current_remainder
27
70
 
28
- # @return [Logger] ロガー
29
- LOGGER = Logger.new(location: 'lunar_phase')
30
-
31
- # @return [Array<String>] 月内の弦
32
- PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
33
-
34
- # @return [Integer] 西暦年
35
- attr_reader :western_year
36
- # @return [Remainder]] 経
37
- attr_reader :average_remainder
38
- # @return [True] 初回計算
39
- # @return [False] 次回以降計算
40
- attr_reader :first
41
- # @return [SolarTerm] 二十四節気(入定気)
42
- attr_reader :solar_term
43
- # @return [Remainder] 入暦
44
- attr_reader :moon_remainder
45
- # @return [True] 進(遠地点より数える)
46
- # @return [False] 退(近地点より数える)
47
- attr_reader :is_forward
48
- # @return [Integer] 弦
49
- attr_reader :phase_index
71
+ add_quarter_moon_size
50
72
 
51
- #
52
- # 初期化
53
- #
54
- # @param [Integer] western_year 西暦年
55
- #
56
- def initialize(western_year:)
57
- @western_year = western_year
58
- # 経
59
- @average_remainder = WinterSolstice.calc_averaged_last_november_1st(
60
- western_year: @western_year
61
- )
62
- # 天正冬至
63
- winter_solstice_age = \
64
- WinterSolstice.calc_moon_age(western_year: @western_year)
65
- # 入定気
66
- @solar_term = SolarTerm.new(remainder: winter_solstice_age)
67
- # 入暦
68
- @moon_remainder = LunarRemainder.new(total: 0).add!(winter_solstice_age)
69
-
70
- @is_forward = false
71
- @first = true
72
-
73
- # 弦
74
- @phase_index = 0
75
- end
73
+ adjusted
74
+ end
76
75
 
77
- #
78
- # 次の弦に進める
79
- #
80
- # @return [Remainder] 定朔
81
- #
82
- def next_phase
83
- adjusted = current_remainder
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
90
+ end
84
91
 
85
- @first = false if @first
92
+ private
93
+
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
86
104
 
87
- add_quarter_moon_size
105
+ #
106
+ # 朔月(月初)であるか
107
+ #
108
+ # @return [True] 朔月である
109
+ # @return [False] 朔月ではない
110
+ #
111
+ def first_phase?
112
+ @phase_index.zero?
113
+ end
88
114
 
89
- adjusted
90
- end
115
+ #
116
+ # 朔月のみログ出力する
117
+ #
118
+ # @param [String] messages メッセージ(可変長)
119
+ #
120
+ def debug(*messages)
121
+ return unless first_phase?
91
122
 
92
- #
93
- # 次の月に進める
94
- # @note 進めた後の月の定朔ではなく、当月のものを返却する
95
- #
96
- # @return [Remainder] 当月初の定朔
97
- #
98
- def next_month
99
- result = nil
100
- PHASE_INDEXES.each_with_index do |_phase, index|
101
- adjust = next_phase
102
- result = adjust if index.zero?
123
+ LOGGER.debug(*messages)
103
124
  end
104
125
 
105
- result
106
- end
126
+ # :reek:TooManyStatements { max_statements: 6 }
107
127
 
108
- private
128
+ #
129
+ # 現在の定朔を取得する
130
+ #
131
+ # @return [Remainder] 定朔
132
+ #
133
+ def current_remainder
134
+ debug("@average_remainder.format: #{@average_remainder.format}")
109
135
 
110
- #
111
- # 次の弦に進める
112
- #
113
- # @return [Integer] 弦
114
- #
115
- def next_phase_index
116
- @phase_index += 1
117
- @phase_index = 0 if @phase_index >= PHASE_INDEXES.size
118
- @phase_index
119
- end
120
-
121
- #
122
- # 朔月(月初)かを確認する
123
- #
124
- # @return [True] 朔月である
125
- # @return [False] 朔月ではない
126
- #
127
- def first_phase?
128
- @phase_index.zero?
129
- end
136
+ sum = correction_value
137
+ adjusted = @average_remainder.add(
138
+ Cycle::Remainder.new(day: 0, minute: sum, second: 0)
139
+ )
140
+ adjusted.up_on_new_moon!
130
141
 
131
- #
132
- # 朔月のみログ出力する
133
- #
134
- # @param [String] messages メッセージ(可変長)
135
- #
136
- def debug(*messages)
137
- return unless first_phase?
142
+ debug("result: #{adjusted.format}")
138
143
 
139
- LOGGER.debug(*messages)
140
- end
144
+ adjusted
145
+ end
141
146
 
142
- #
143
- # 現在の定朔を取得する
144
- #
145
- # @return [Remainder] 定朔
146
- #
147
- def current_remainder
148
- debug("@average_remainder.format: #{@average_remainder.format}")
147
+ #
148
+ # 補正値を得る
149
+ #
150
+ # @return [Integer] 補正値
151
+ #
152
+ def correction_value
153
+ sun = correction_solar_value
154
+ moon = correction_moon_value
149
155
 
150
- sum = correction_value
151
- adjusted = @average_remainder.add(
152
- Remainder.new(day: 0, minute: sum, second: 0)
153
- )
154
- adjusted.up_on_new_moon!
156
+ sum = sun + moon
155
157
 
156
- debug("result: #{adjusted.format}")
158
+ debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
157
159
 
158
- adjusted
159
- end
160
+ sum
161
+ end
160
162
 
161
- #
162
- # 補正値を得る
163
- #
164
- # @return [Integer] 補正値
165
- #
166
- def correction_value
167
- sun = correction_solar_value
168
- moon = correction_moon_value
163
+ #
164
+ # 太陽運動の補正値を得る
165
+ #
166
+ # @return [Integer] 太陽運動の補正値
167
+ #
168
+ def correction_solar_value
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}")
172
+
173
+ Solar::Value.get(solar_location: @solar_location)
174
+ end
169
175
 
170
- sum = sun + moon
176
+ # :reek:TooManyStatements { max_statements: 6 }
171
177
 
172
- debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
178
+ #
179
+ # 月運動の補正値を得る
180
+ #
181
+ # @return [Integer] 月運動の補正値
182
+ #
183
+ def correction_moon_value
184
+ @lunar_location.run
173
185
 
174
- sum
175
- end
186
+ remainder = @lunar_location.remainder
187
+ forward = @lunar_location.forward
176
188
 
177
- #
178
- # 太陽運動の補正値を得る
179
- #
180
- # @return [Integer] 太陽運動の補正値
181
- #
182
- def correction_solar_value
183
- @solar_term = SolarOrbit.calc_solar_term_by_remainder(
184
- solar_term: @solar_term
185
- )
186
- debug("@solar_term.remainder: #{@solar_term.remainder.format(form: '%d-%d.%d')}")
187
- debug("@solar_term.index: #{@solar_term.index}")
188
-
189
- SolarOrbit.calc_sun_orbit_value(solar_term: @solar_term)
190
- end
189
+ debug("[lunar]remainder.format: #{remainder.format}")
190
+ debug("[lunar]forward: #{forward}")
191
191
 
192
- #
193
- # 月運動の補正値を得る
194
- #
195
- # @return [Integer] 月運動の補正値
196
- #
197
- def correction_moon_value
198
- @moon_remainder, @is_forward = \
199
- LunarOrbit.calc_moon_point(remainder: @moon_remainder,
200
- western_year: @western_year,
201
- is_forward: @is_forward,
202
- first: @first)
203
-
204
- debug("@moon_remainder.format: #{@moon_remainder.format}")
205
- debug("@is_forward: #{@is_forward}")
206
-
207
- LunarOrbit.calc_moon_orbit_value(remainder_month: @moon_remainder,
208
- is_forward: @is_forward)
209
- end
192
+ Lunar::Value.get(remainder: remainder, forward: forward)
193
+ end
210
194
 
211
- def add_quarter_moon_size
212
- @average_remainder.add!(QuarterMoon::DEFAULT)
213
- @solar_term.remainder.add!(QuarterMoon::DEFAULT)
214
- @moon_remainder.add!(QuarterMoon::BASE_HUNDRED)
195
+ def add_quarter_moon_size
196
+ @average_remainder.add!(QUARTER)
197
+ @solar_location.add_quarter
198
+ @lunar_location.add_quarter
215
199
 
216
- next_phase_index
200
+ next_phase_index
201
+ end
217
202
  end
218
203
  end
219
204
  end