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
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # WesternDateAllocation 西暦日の割り当て
9
- #
10
- module WesternDateAllocation
11
- #
12
- # 月初日の西暦日を更新する
13
- #
14
- # @param [Array<Year>] years 完全範囲(月初日なし)
15
- #
16
- # @return [Array<Year>] 完全範囲(月初日あり)
17
- #
18
- def self.get(years:)
19
- update_first_day(years: years)
20
-
21
- years
22
- end
23
-
24
- #
25
- # 月初日の西暦日を更新する
26
- #
27
- # @param [Array<Year>] years 完全範囲(月初日なし)
28
- #
29
- def self.update_first_day(years:)
30
- years.each_with_index do |year, index|
31
- new_year_date = year.new_year_date.clone
32
-
33
- months = year.months
34
- update_first_day_within_all_months(
35
- new_year_date: new_year_date, months: months
36
- )
37
-
38
- years[index] = Year.new(
39
- multi_gengou: year.multi_gengou, new_year_date: new_year_date,
40
- months: months, total_days: year.total_days
41
- )
42
- end
43
- end
44
-
45
- #
46
- # 全ての月で月初日の西暦日を更新する
47
- #
48
- # @param [Western::Calendar] new_year_date 元旦
49
- # @param [Array<Month>] months 月データ
50
- #
51
- def self.update_first_day_within_all_months(new_year_date:, months:)
52
- date = new_year_date.clone
53
- months.each_with_index do |month, index|
54
- updated_month = Month.new(
55
- month_label: month.month_label,
56
- first_day: FirstDay.new(remainder: month.first_day.remainder,
57
- western_date: date),
58
- solar_terms: month.solar_terms
59
- )
60
- months[index] = updated_month
61
-
62
- date = date.clone + updated_month.days
63
- end
64
- end
65
- private_class_method :update_first_day_within_all_months
66
- end
67
- end
68
- end
@@ -1,138 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../base/multi_gengou_roller'
4
-
5
- require_relative '../../../era/western'
6
- require_relative './annual_range'
7
-
8
- require_relative '../base/year'
9
-
10
- # :nodoc:
11
- module Zakuro
12
- # :nodoc:
13
- module Senmyou
14
- #
15
- # YearBoundary 年境界
16
- #
17
- module YearBoundary
18
- #
19
- # 年間範囲内の年データの開始月を変更する
20
- #
21
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
22
- #
23
- # @return [Array<Year>] 年データ(元旦基準)
24
- #
25
- def self.get(annual_ranges:)
26
- categorize(annual_ranges: annual_ranges)
27
- rearranged_years(annual_ranges: annual_ranges)
28
- end
29
-
30
- #
31
- # 年間範囲内の年データの開始月を変更する
32
- #
33
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
34
- #
35
- # @return [Array<Year>] 年データ(元旦基準)
36
- #
37
- def self.rearranged_years(annual_ranges:)
38
- years = []
39
-
40
- (0..(annual_ranges.size - 2)).each do |index|
41
- year = rearranged_year(annual_ranges: annual_ranges, index: index)
42
- years.push(year)
43
- end
44
-
45
- years
46
- end
47
- private_class_method :rearranged_years
48
-
49
- #
50
- # 年間範囲を昨年/今年で分類する
51
- #
52
- # @param [Array<Year>] annual_range 1年データ
53
- #
54
- def self.categorize(annual_ranges:)
55
- annual_ranges.each do |annual_range|
56
- categorize_year(annual_range: annual_range)
57
- end
58
- end
59
- private_class_method :categorize
60
-
61
- #
62
- # 各月を昨年/今年で分類する
63
- #
64
- # @param [Array<Month>] annual_range 1年データ
65
- #
66
- def self.categorize_year(annual_range:)
67
- is_last_year = true
68
- annual_range.each_with_index do |month, index|
69
- is_last_year = false if month.number == 1
70
-
71
- annual_range[index] = InitializedMonth.new(
72
- month_label: month.month_label, first_day: month.first_day,
73
- solar_terms: month.solar_terms, phase_index: month.phase_index,
74
- is_last_year: is_last_year
75
- )
76
- end
77
- end
78
- private_class_method :categorize_year
79
-
80
- #
81
- # 年データの開始月を変更する
82
- #
83
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
84
- # @param [Integer] index 対象年の要素番号
85
- #
86
- # @return [Year] 年データ(元旦基準)
87
- #
88
- def self.rearranged_year(annual_ranges:, index:)
89
- current_annual_range = annual_ranges[index]
90
- next_annual_range = annual_ranges[index + 1]
91
-
92
- year = push_current_year(annual_range: current_annual_range)
93
- push_last_year(annual_range: next_annual_range, year: year)
94
-
95
- year
96
- end
97
- private_class_method :rearranged_year
98
-
99
- #
100
- # 当年データを生成する
101
- #
102
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
103
- # @param [Year] year 対象年
104
- #
105
- # @return [Year] 当年月ありの対象年
106
- #
107
- def self.push_current_year(annual_range:, year: Year.new)
108
- annual_range.each do |month|
109
- next if month.is_last_year
110
-
111
- year.push(month: month)
112
- end
113
-
114
- year
115
- end
116
- private_class_method :push_current_year
117
-
118
- #
119
- # 昨年データを生成する
120
- #
121
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
122
- # @param [Year] year 対象年
123
- #
124
- # @return [Year] 昨年月ありの対象年
125
- #
126
- def self.push_last_year(annual_range:, year: Year.new)
127
- annual_range.each do |month|
128
- next unless month.is_last_year
129
-
130
- year.push(month: month)
131
- end
132
-
133
- year
134
- end
135
- private_class_method :push_last_year
136
- end
137
- end
138
- end
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../era/western'
4
- require_relative '../range/full_range'
5
- require_relative '../base/multi_gengou_roller'
6
- require_relative '../base/year'
7
- require_relative '../../../output/response'
8
- require_relative '../../../output/logger'
9
-
10
- # :nodoc:
11
- module Zakuro
12
- # :nodoc:
13
- module Senmyou
14
- #
15
- # SingleDaySpecifier 一日検索
16
- #
17
- module SingleDaySpecifier
18
- # @return [Logger] ロガー
19
- LOGGER = Logger.new(location: 'specifier')
20
-
21
- #
22
- # 取得する
23
- #
24
- # @param [Array<Year>] yeas 範囲
25
- # @param [Western::Calendar] date 西暦日
26
- #
27
- # @return [Result::Data::SingleDay] 和暦日
28
- #
29
- def self.get(years: [], date: Western::Calendar.new)
30
- year = specify_year(years: years, date: date)
31
-
32
- year = transfer(year: year, date: date)
33
-
34
- month = specify_month(year: year, date: date)
35
- first_date = month.western_date
36
-
37
- Response::SingleDay.save_single_day(
38
- param: Response::SingleDay::Param.new(
39
- year: year, month: month,
40
- date: date, days: date - first_date
41
- )
42
- )
43
- end
44
-
45
- #
46
- # 年を特定する
47
- #
48
- # @param [Array<Year>] years 範囲
49
- # @param [Western::Calendar] date 西暦日
50
- #
51
- # @return [Year] 対象年
52
- #
53
- def self.specify_year(years:, date:)
54
- years.reverse_each do |year|
55
- return year if date >= year.new_year_date
56
- end
57
-
58
- raise ArgumentError, "invalid year range. date: #{date.format}"
59
- end
60
- private_class_method :specify_year
61
-
62
- #
63
- # 改元する
64
- #
65
- # @param [Year] year 年
66
- # @param [Western::Calendar] date 西暦日
67
- #
68
- # @return [Year] 改元後の年
69
- #
70
- def self.transfer(year:, date:)
71
- multi_gengou = MultiGengouRoller.transfer(multi_gengou: year.multi_gengou, date: date)
72
- Year.new(multi_gengou: multi_gengou, new_year_date: year.new_year_date,
73
- months: year.months, total_days: year.total_days)
74
- end
75
- private_class_method :transfer
76
-
77
- # :reek:TooManyStatements { max_statements: 7 }
78
-
79
- #
80
- # 月を特定する
81
- #
82
- # @param [Year] year 年
83
- # @param [Western::Calendar] date 西暦日
84
- #
85
- # @return [Month] 対象月
86
- #
87
- def self.specify_month(year:, date:)
88
- months = year.months
89
-
90
- current_month = months[0]
91
- months.each do |month|
92
- return current_month if month.western_date > date
93
-
94
- current_month = month
95
- end
96
-
97
- current_month
98
- end
99
- private_class_method :specify_month
100
- end
101
- end
102
- end
@@ -1,332 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # LunarOrbit 月軌道
9
- #
10
- module LunarOrbit
11
- # @return [Integer] 暦周(1近日点)
12
- ANOMALISTIC_MONTH = 231_458.19
13
- # @return [Integer] 暦中日
14
- # @note ANOMALISTIC_MONTH の半分に相当する
15
- HALF_ANOMALISTIC_MONTH = \
16
- LunarRemainder.new(day: 13, minute: 6529, second: 9.5)
17
-
18
- #
19
- # Adjustment 補正値情報
20
- #
21
- module Adjustment
22
- #
23
- # Item 補正値
24
- #
25
- class Item
26
- # @return [Integer] 損益率
27
- attr_reader :per
28
- # @return [Integer] 眺朒(ちょうじく)積
29
- attr_reader :stack
30
-
31
- #
32
- # 初期化
33
- #
34
- # @param [Integer] per 損益率
35
- # @param [Integer] stack 眺朒(ちょうじく)積
36
- #
37
- def initialize(per:, stack:)
38
- @per = per
39
- @stack = stack
40
- end
41
-
42
- #
43
- # 文字化
44
- #
45
- # @return [String] 文字
46
- #
47
- def to_s
48
- "per:#{@per}, stack:#{@stack}"
49
- end
50
- end
51
-
52
- # @return [Array<Item>] 月の補正値
53
- # @note キーは複合キーであり、以下のパターンに対応する
54
- # * 進退
55
- # * forward: 進(遠地点より数える)
56
- # * back: 退(近地点より数える)
57
- # * 入暦(1-14)
58
- # * 小余(0-8400)
59
- LIST = {
60
- forward_01_0000_8400: Item.new(per: +830, stack: 0),
61
- forward_02_0000_8400: Item.new(per: +726, stack: +830),
62
- forward_03_0000_8400: Item.new(per: +606, stack: +1556),
63
- forward_04_0000_8400: Item.new(per: +471, stack: +2162),
64
- forward_05_0000_8400: Item.new(per: +337, stack: +2633),
65
- forward_06_0000_8400: Item.new(per: +202, stack: +2970),
66
- forward_07_0000_7465: Item.new(per: +53, stack: +3172),
67
- forward_07_7465_8400: Item.new(per: -7, stack: +3225), # +3172 + 53(初益)
68
- forward_08_0000_8400: Item.new(per: -82, stack: +3218),
69
- forward_09_0000_8400: Item.new(per: -224, stack: +3136),
70
- forward_10_0000_8400: Item.new(per: -366, stack: +2912),
71
- forward_11_0000_8400: Item.new(per: -509, stack: +2546),
72
- forward_12_0000_8400: Item.new(per: -643, stack: +2037),
73
- forward_13_0000_8400: Item.new(per: -748, stack: +1394),
74
- forward_14_0000_6529: Item.new(per: -646, stack: +646), # 14日の小余は常に6529以下
75
- back_01_0000_8400: Item.new(per: -830, stack: 0),
76
- back_02_0000_8400: Item.new(per: -726, stack: -830),
77
- back_03_0000_8400: Item.new(per: -598, stack: -1556),
78
- back_04_0000_8400: Item.new(per: -464, stack: -2154),
79
- back_05_0000_8400: Item.new(per: -329, stack: -2618),
80
- back_06_0000_8400: Item.new(per: -195, stack: -2947),
81
- back_07_0000_7465: Item.new(per: -53, stack: -3142),
82
- back_07_7465_8400: Item.new(per: +7, stack: -3195), # -3142 - 53(初益)
83
- back_08_0000_8400: Item.new(per: +82, stack: -3188),
84
- back_09_0000_8400: Item.new(per: +225, stack: -3106),
85
- back_10_0000_8400: Item.new(per: +366, stack: -2881),
86
- back_11_0000_8400: Item.new(per: +501, stack: -2515),
87
- back_12_0000_8400: Item.new(per: +628, stack: -2014),
88
- back_13_0000_8400: Item.new(per: +740, stack: -1386),
89
- back_14_0000_6529: Item.new(per: +646, stack: -646) # 14日の小余は常に6529以下
90
- }.freeze
91
- end
92
-
93
- #
94
- # 月の運行による補正値を算出する
95
- #
96
- # @param [Remainder] remainder_month 月の大余小余
97
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
98
- #
99
- # @return [Integer] 補正値
100
- #
101
- def self.calc_moon_orbit_value(remainder_month:, is_forward:)
102
- valid?(remainder: remainder_month)
103
-
104
- day, minute = make_calculable_remainder_value(remainder: remainder_month)
105
-
106
- # 引き当て
107
- adjustment, diff, minute = specify_moon_adjustment(
108
- is_forward: is_forward, day: day, minute: minute
109
- )
110
- day = make_cumulative_value_for_days(per: adjustment.per,
111
- denominator: diff, minute: minute)
112
-
113
- adjustment.stack + day
114
- end
115
-
116
- #
117
- # 大余小余を検証する
118
- #
119
- # @param [Remainder] remainder 大余小余
120
- #
121
- # @return [True] 正しい(月の位相計算に使う大余小余)
122
- # @return [True] 正しくない
123
- #
124
- def self.valid?(remainder:)
125
- return if remainder.is_a?(LunarRemainder)
126
-
127
- raise ArgumentError, "unmatch parameter type: #{remainder.class}"
128
- end
129
- private_class_method :valid?
130
-
131
- #
132
- # 大余小余を計算可能な値にする
133
- # @note 大余の秒(second)は使わない
134
- #
135
- # @param [LunarRemainder] remainder 大余小余
136
- #
137
- # @return [Integer] 大余
138
- # @return [Integer] 小余
139
- #
140
- def self.make_calculable_remainder_value(remainder:)
141
- day = remainder.day
142
- minute = remainder.minute + (remainder.second / 100)
143
- minute = minute.floor
144
-
145
- [day, minute]
146
- end
147
- private_class_method :make_calculable_remainder_value
148
-
149
- # :reek:TooManyStatements { max_statements: 9 }
150
-
151
- #
152
- # 累計値(大余)を作成する
153
- #
154
- # @param [Integer] per 入暦(1-14)
155
- # @param [Integer] denominator 小余の分母
156
- # @param [Integer] minute 小余
157
- #
158
- # @return [Integer] 累計値(大余)
159
- #
160
- def self.make_cumulative_value_for_days(per:, denominator:, minute:)
161
- remainder_minute = (per * minute).to_f
162
- day = remainder_minute / denominator
163
- # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
164
- day = day.negative? ? day.ceil : day.floor
165
- sign = remainder_minute.negative? ? -1 : 1
166
- remainder_day = (sign * remainder_minute) % denominator
167
- # 四捨五入(8400ならその半分の4200以上を繰り上げる)
168
- day += sign if remainder_day >= (denominator / 2)
169
-
170
- day
171
- end
172
- private_class_method :make_cumulative_value_for_days
173
-
174
- # :reek:TooManyStatements { max_statements: 9 }
175
-
176
- #
177
- # 月軌道の補正に必要な基本値を引き当てる
178
- #
179
- # @note 戻り値は calc_moon_orbit_value で使用する
180
- #
181
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
182
- # @param [Integer] day 大余
183
- # @param [Integer] minute 小余
184
- #
185
- # @return [Adjustment::Item] 補正値
186
- # @return [Integer] (小余を処理する時の)分母
187
- # @return [Integer] 小余の下げ幅
188
- #
189
- def self.specify_moon_adjustment(is_forward:, day:, minute:)
190
- prefix = { true => 'forward', false => 'back' }[is_forward]
191
-
192
- targets = Adjustment::LIST.select \
193
- { |key, _| key.match(/^#{prefix}_#{format('%<day>02d', day: day)}_.*/) }
194
-
195
- targets.each do |key, value|
196
- # NOTE: 境界値は上から順に引き当てた方を返す(7日の境界値7465は上のキーで返す)
197
- matched, diff = \
198
- extract_data_from_moon_adjustment_key(key, minute)
199
- # 小余の下げ幅
200
- calc_minute = (day == 7 && minute > 7465 ? minute - 7465 : minute)
201
- return value, diff, calc_minute if matched
202
- end
203
-
204
- [nil, nil, nil]
205
- end
206
- private_class_method :specify_moon_adjustment
207
-
208
- #
209
- # 補正値を引き当てる
210
- #
211
- # @param [String] key 補正値のキー
212
- # @param [Integer] minute 小余
213
- #
214
- # @return [Adjustment::Item] 補正値
215
- # @return [Integer] (小余を処理する時の)分母
216
- #
217
- def self.extract_data_from_moon_adjustment_key(key, minute)
218
- matched = key.match(/([0-9]{4})_([0-9]{4})$/)
219
- start = matched[1].to_i
220
- finish = matched[2].to_i
221
-
222
- matched = minute >= start && minute <= finish
223
- [matched, (finish - start)]
224
- end
225
- private_class_method :extract_data_from_moon_adjustment_key
226
-
227
- # :reek:ControlParameter and :reek:BooleanParameter
228
- # :reek:LongParameterList { max_params: 4 }
229
-
230
- #
231
- # 月地点を計算する
232
- #
233
- # @param [LunarRemainder] remainder 初回(昨年冬至), 前回計算結果(入暦)
234
- # @param [Integer] western_year 西暦年
235
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
236
- # @param [True, False] first 初回計算, 次回以降計算
237
- #
238
- # @return [LunarRemainder] 入暦
239
- # @return [True] 進(遠地点より数える)
240
- # @return [False] 退(近地点より数える)
241
- #
242
- def self.calc_moon_point(remainder:, western_year:,
243
- is_forward: true, first: true)
244
- if first
245
- return calc_first_moon_point(winter_solstice_age: remainder,
246
- western_year: western_year)
247
- end
248
- calc_following_moon_point(remainder: remainder, is_forward: is_forward)
249
- end
250
-
251
- # :reek:TooManyStatements { max_statements: 7 }
252
-
253
- #
254
- # 入暦(月の遠地点から数えた日数/近地点から数えた日数)を求める
255
- #
256
- # 天正冬至(入暦前回未計算)を求める
257
- #
258
- # @param [Remainder] winter_solstice_age 天正閏余
259
- # @param [Integer] western_year 西暦年
260
- #
261
- # @return [LunarRemainder] 入暦
262
- # @return [True] 進(遠地点より数える)
263
- # @return [False] 退(近地点より数える)
264
- #
265
- def self.calc_first_moon_point(winter_solstice_age:, western_year:)
266
- # 積年の開始から対象年までの年数
267
- total_year = \
268
- WinterSolstice::TOTAL_YEAR + western_year - WinterSolstice::BEGIN_YEAR
269
-
270
- # 通積分 - 天正閏余
271
- total_day = \
272
- total_year * WinterSolstice::YEAR - winter_solstice_age.to_minute
273
-
274
- remainder_month = \
275
- LunarRemainder.new(total: (total_day % ANOMALISTIC_MONTH))
276
-
277
- remainder_month, is_forward = decrease_moon_point(
278
- remainder_month: remainder_month,
279
- remainder_limit: HALF_ANOMALISTIC_MONTH, is_forward: true
280
- )
281
-
282
- remainder_month.add!(Remainder.new(day: 1, minute: 0, second: 0))
283
-
284
- [remainder_month, is_forward]
285
- end
286
- private_class_method :calc_first_moon_point
287
-
288
- #
289
- # 入暦(月の遠地点から数えた日数/近地点から数えた日数)を求める
290
- #
291
- # 前回計算結果を補正する
292
- #
293
- # @param [LunarRemainder] remainder 前回計算結果(入暦)
294
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
295
- #
296
- # @return [LunarRemainder] 入暦
297
- # @return [True] 進(遠地点より数える)
298
- # @return [False] 退(近地点より数える)
299
- #
300
- def self.calc_following_moon_point(remainder:, is_forward:)
301
- # 前回計算結果を引き継いた場合、暦中日ではなく損益眺朒(ちょうじく)数の上限とする
302
- remainder_month, is_forward = \
303
- decrease_moon_point(
304
- remainder_month: remainder,
305
- remainder_limit: Remainder.new(day: 14, minute: 6529, second: 0),
306
- is_forward: is_forward
307
- )
308
-
309
- [remainder_month, is_forward]
310
- end
311
- private_class_method :calc_following_moon_point
312
-
313
- #
314
- # 月地点を減算する
315
- #
316
- # @param [LunarRemainder] remainder_month 大余小余
317
- # @param [Remainder] remainder_limit 大余小余の上限(最大の入暦)
318
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
319
- #
320
- # @return [LunarRemainder] 大余小余の減算結果(上限値超えした場合)
321
- # @return [True] 進(遠地点より数える)
322
- # @return [False] 退(近地点より数える)
323
- #
324
- def self.decrease_moon_point(remainder_month:, remainder_limit:, is_forward:)
325
- return remainder_month, is_forward if remainder_month < remainder_limit
326
-
327
- [remainder_month.sub(HALF_ANOMALISTIC_MONTH), !is_forward]
328
- end
329
- private_class_method :decrease_moon_point
330
- end
331
- end
332
- end