zakuro 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/VERSION +1 -1
  4. data/lib/zakuro/calculation/base/gengou.rb +5 -5
  5. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  6. data/lib/zakuro/calculation/base/operated_year.rb +23 -21
  7. data/lib/zakuro/calculation/base/year.rb +3 -3
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
  9. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  10. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  11. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
  12. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  13. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
  22. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  23. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  24. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  25. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  26. data/lib/zakuro/calculation/monthly/initialized_month.rb +39 -37
  27. data/lib/zakuro/calculation/monthly/month.rb +15 -15
  28. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  29. data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
  30. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  31. data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
  32. data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
  33. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  34. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  35. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  36. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  37. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  38. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  39. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  40. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +5 -5
  41. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  42. data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
  43. data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
  44. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  45. data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
  46. data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
  47. data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
  48. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
  49. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  50. data/lib/zakuro/calculation/summary/western/range.rb +95 -92
  51. data/lib/zakuro/calculation/summary/western/single.rb +78 -76
  52. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -124
  53. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
  54. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  55. data/lib/zakuro/condition.rb +121 -111
  56. data/lib/zakuro/context/context.rb +1 -1
  57. data/lib/zakuro/context/option.rb +31 -29
  58. data/lib/zakuro/context/version_class_resolver.rb +26 -24
  59. data/lib/zakuro/era/japan/calendar.rb +35 -33
  60. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -4
  61. data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
  62. data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
  63. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
  64. data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
  65. data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -36
  66. data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -37
  67. data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
  68. data/lib/zakuro/era/japan/gengou.rb +28 -26
  69. data/lib/zakuro/era/japan/version.rb +18 -16
  70. data/lib/zakuro/era/western/calendar.rb +102 -90
  71. data/lib/zakuro/exception/case/preset.rb +2 -2
  72. data/lib/zakuro/exception/exception.rb +15 -13
  73. data/lib/zakuro/exception/zakuro_error.rb +1 -1
  74. data/lib/zakuro/gateway/locale/date.rb +2 -2
  75. data/lib/zakuro/gateway/locale/range.rb +3 -3
  76. data/lib/zakuro/gateway/range.rb +1 -1
  77. data/lib/zakuro/gateway/single.rb +13 -2
  78. data/lib/zakuro/merchant.rb +1 -1
  79. data/lib/zakuro/operation/month/parser.rb +252 -251
  80. data/lib/zakuro/operation/month/type.rb +17 -8
  81. data/lib/zakuro/operation/month/validator.rb +148 -144
  82. data/lib/zakuro/operation/operation.rb +38 -36
  83. data/lib/zakuro/output/response.rb +112 -113
  84. data/lib/zakuro/result/operation/month/annotation.rb +2 -2
  85. data/lib/zakuro/result/operation/month/history.rb +2 -2
  86. data/lib/zakuro/result/operation/month.rb +31 -0
  87. data/lib/zakuro/result/operation.rb +39 -0
  88. data/lib/zakuro/result/result.rb +3 -3
  89. data/lib/zakuro/tools/stringifier.rb +66 -64
  90. data/lib/zakuro/tools/typeconv.rb +17 -15
  91. data/lib/zakuro/tools/typeof.rb +15 -13
  92. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  93. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  94. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
  95. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  96. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
  97. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  98. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  99. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  100. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  101. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  102. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  103. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  104. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  105. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  106. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  107. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  108. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  109. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  110. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  111. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
  112. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  113. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
  114. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  115. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  116. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  117. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  118. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  119. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  120. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  121. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  122. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  123. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
  124. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  125. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
  126. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  127. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  128. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  129. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  130. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  131. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  132. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  133. metadata +12 -9
  134. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
  135. data/lib/zakuro/result/operation/bundle.rb +0 -44
  136. data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -14,39 +14,42 @@ module Zakuro
14
14
  # GengouScroller 元号スクロール
15
15
  #
16
16
  module GengouScroller
17
- #
18
- # 元号を年に設定する
19
- #
20
- # @param [Gengou::Scroll] scroll 元号スクロール
21
- # @param [Array<Base::Year>] years
22
- #
23
- def self.set(scroll:, years: [])
24
- years.each do |year|
25
- update_gengou_year(scroll: scroll, year: year)
17
+ class << self
18
+ #
19
+ # 元号を年に設定する
20
+ #
21
+ # @param [Gengou::Scroll] scroll 元号スクロール
22
+ # @param [Array<Base::Year>] years 年
23
+ #
24
+ def set(scroll:, years: [])
25
+ years.each do |year|
26
+ update_gengou_year(scroll: scroll, year: year)
27
+ end
26
28
  end
27
- end
28
29
 
29
- #
30
- # 年の元号を更新する
31
- #
32
- # @param [Base::Year] year 年
33
- #
34
- def self.update_gengou_year(scroll:, year:)
35
- year.months.each_with_index do |month, index|
36
- scroll.run(month: month)
37
- gengou = scroll.to_gengou
38
- year.months[index] = Monthly::Month.new(
39
- context: month.context,
40
- month_label: month.month_label,
41
- first_day: Monthly::FirstDay.new(
42
- remainder: month.first_day.remainder,
43
- western_date: gengou.start_date.clone
44
- ),
45
- solar_terms: month.solar_terms, gengou: gengou
46
- )
30
+ private
31
+
32
+ #
33
+ # 年の元号を更新する
34
+ #
35
+ # @param [Base::Year] year
36
+ #
37
+ def update_gengou_year(scroll:, year:)
38
+ year.months.each_with_index do |month, index|
39
+ scroll.run(month: month)
40
+ gengou = scroll.to_gengou
41
+ year.months[index] = Monthly::Month.new(
42
+ context: month.context,
43
+ month_label: month.month_label,
44
+ first_day: Monthly::FirstDay.new(
45
+ remainder: month.first_day.remainder,
46
+ western_date: gengou.start_date.clone
47
+ ),
48
+ solar_terms: month.solar_terms, gengou: gengou
49
+ )
50
+ end
47
51
  end
48
52
  end
49
- private_class_method :update_gengou_year
50
53
  end
51
54
  end
52
55
  end
@@ -16,133 +16,131 @@ module Zakuro
16
16
  # YearBoundary 年境界
17
17
  #
18
18
  module YearBoundary
19
- #
20
- # 年間範囲内の年データの開始月を変更する
21
- #
22
- # @param [Context::Context] context 暦コンテキスト
23
- # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
24
- #
25
- # @return [Array<Base::Year>] 年データ(元旦基準)
26
- #
27
- def self.get(context:, annual_ranges:)
28
- categorize(context: context, annual_ranges: annual_ranges)
29
- rearranged_years(context: context, annual_ranges: annual_ranges)
30
- end
19
+ class << self
20
+ #
21
+ # 年間範囲内の年データの開始月を変更する
22
+ #
23
+ # @param [Context::Context] context 暦コンテキスト
24
+ # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
25
+ #
26
+ # @return [Array<Base::Year>] 年データ(元旦基準)
27
+ #
28
+ def get(context:, annual_ranges:)
29
+ categorize(context: context, annual_ranges: annual_ranges)
30
+ rearranged_years(context: context, annual_ranges: annual_ranges)
31
+ end
31
32
 
32
- #
33
- # 年間範囲内の年データの開始月を変更する
34
- #
35
- # @param [Context::Context] context 暦コンテキスト
36
- # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
37
- #
38
- # @return [Array<Base::Year>] 年データ(元旦基準)
39
- #
40
- def self.rearranged_years(context:, annual_ranges:)
41
- years = []
42
-
43
- (0..(annual_ranges.size - 2)).each do |index|
44
- year = rearranged_year(
45
- context: context, annual_ranges: annual_ranges, index: index
46
- )
47
- years.push(year)
33
+ private
34
+
35
+ #
36
+ # 年間範囲内の年データの開始月を変更する
37
+ #
38
+ # @param [Context::Context] context 暦コンテキスト
39
+ # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
40
+ #
41
+ # @return [Array<Base::Year>] 年データ(元旦基準)
42
+ #
43
+ def rearranged_years(context:, annual_ranges:)
44
+ years = []
45
+
46
+ (0..(annual_ranges.size - 2)).each do |index|
47
+ year = rearranged_year(
48
+ context: context, annual_ranges: annual_ranges, index: index
49
+ )
50
+ years.push(year)
51
+ end
52
+
53
+ years
48
54
  end
49
55
 
50
- years
51
- end
52
- private_class_method :rearranged_years
53
-
54
- #
55
- # 年間範囲を昨年/今年で分類する
56
- #
57
- # @param [Context::Context] context 暦コンテキスト
58
- # @param [Array<Base::Year>] annual_range 1年データ
59
- #
60
- def self.categorize(context:, annual_ranges:)
61
- annual_ranges.each do |annual_range|
62
- categorize_year(context: context, annual_range: annual_range)
56
+ #
57
+ # 年間範囲を昨年/今年で分類する
58
+ #
59
+ # @param [Context::Context] context 暦コンテキスト
60
+ # @param [Array<Base::Year>] annual_range 1年データ
61
+ #
62
+ def categorize(context:, annual_ranges:)
63
+ annual_ranges.each do |annual_range|
64
+ categorize_year(context: context, annual_range: annual_range)
65
+ end
63
66
  end
64
- end
65
- private_class_method :categorize
66
-
67
- #
68
- # 各月を昨年/今年で分類する
69
- #
70
- # @param [Context::Context] context 暦コンテキスト
71
- # @param [Array<Month>] annual_range 1年データ
72
- #
73
- def self.categorize_year(context:, annual_range:)
74
- is_last_year = true
75
- annual_range.each_with_index do |month, index|
76
- is_last_year = false if month.number == 1
77
-
78
- annual_range[index] = Monthly::InitializedMonth.new(
79
- context: context,
80
- month_label: month.month_label, first_day: month.first_day,
81
- solar_terms: month.solar_terms, phase_index: month.phase_index,
82
- is_last_year: is_last_year
83
- )
67
+
68
+ #
69
+ # 各月を昨年/今年で分類する
70
+ #
71
+ # @param [Context::Context] context 暦コンテキスト
72
+ # @param [Array<Month>] annual_range 1年データ
73
+ #
74
+ def categorize_year(context:, annual_range:)
75
+ is_last_year = true
76
+ annual_range.each_with_index do |month, index|
77
+ is_last_year = false if month.number == 1
78
+
79
+ annual_range[index] = Monthly::InitializedMonth.new(
80
+ context: context,
81
+ month_label: month.month_label, first_day: month.first_day,
82
+ solar_terms: month.solar_terms, phase_index: month.phase_index,
83
+ is_last_year: is_last_year
84
+ )
85
+ end
84
86
  end
85
- end
86
- private_class_method :categorize_year
87
-
88
- #
89
- # 年データの開始月を変更する
90
- #
91
- # @param [Context::Context] context 暦コンテキスト
92
- # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
93
- # @param [Integer] index 対象年の要素番号
94
- #
95
- # @return [Base::Year] 年データ(元旦基準)
96
- #
97
- def self.rearranged_year(context:, annual_ranges:, index:)
98
- current_annual_range = annual_ranges[index]
99
- next_annual_range = annual_ranges[index + 1]
100
-
101
- year = push_current_year(context: context, annual_range: current_annual_range)
102
- push_last_year(annual_range: next_annual_range, year: year)
103
-
104
- year
105
- end
106
- private_class_method :rearranged_year
107
-
108
- #
109
- # 当年データを生成する
110
- #
111
- # @param [Context::Context] context 暦コンテキスト
112
- # @param [Array<Month>] annual_range 1年データ
113
- #
114
- # @return [Base::Year] 当年月ありの対象年
115
- #
116
- def self.push_current_year(context:, annual_range:)
117
- year = Base::Year.new(context: context)
118
- annual_range.each do |month|
119
- next if month.is_last_year
120
-
121
- year.push(month: month)
87
+
88
+ #
89
+ # 年データの開始月を変更する
90
+ #
91
+ # @param [Context::Context] context 暦コンテキスト
92
+ # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
93
+ # @param [Integer] index 対象年の要素番号
94
+ #
95
+ # @return [Base::Year] 年データ(元旦基準)
96
+ #
97
+ def rearranged_year(context:, annual_ranges:, index:)
98
+ current_annual_range = annual_ranges[index]
99
+ next_annual_range = annual_ranges[index + 1]
100
+
101
+ year = push_current_year(context: context, annual_range: current_annual_range)
102
+ push_last_year(annual_range: next_annual_range, year: year)
103
+
104
+ year
122
105
  end
123
106
 
124
- year
125
- end
126
- private_class_method :push_current_year
127
-
128
- #
129
- # 昨年データを生成する
130
- #
131
- # @param [Array<Month>] annual_range 1年データ
132
- # @param [Base::Year] year 対象年
133
- #
134
- # @return [Base::Year] 昨年月ありの対象年
135
- #
136
- def self.push_last_year(annual_range:, year: Base::Year.new)
137
- annual_range.each do |month|
138
- next unless month.is_last_year
139
-
140
- year.push(month: month)
107
+ #
108
+ # 当年データを生成する
109
+ #
110
+ # @param [Context::Context] context 暦コンテキスト
111
+ # @param [Array<Month>] annual_range 1年データ
112
+ #
113
+ # @return [Base::Year] 当年月ありの対象年
114
+ #
115
+ def push_current_year(context:, annual_range:)
116
+ year = Base::Year.new(context: context)
117
+ annual_range.each do |month|
118
+ next if month.is_last_year
119
+
120
+ year.push(month: month)
121
+ end
122
+
123
+ year
141
124
  end
142
125
 
143
- year
126
+ #
127
+ # 昨年データを生成する
128
+ #
129
+ # @param [Array<Month>] annual_range 1年データ
130
+ # @param [Base::Year] year 対象年
131
+ #
132
+ # @return [Base::Year] 昨年月ありの対象年
133
+ #
134
+ def push_last_year(annual_range:, year: Base::Year.new)
135
+ annual_range.each do |month|
136
+ next unless month.is_last_year
137
+
138
+ year.push(month: month)
139
+ end
140
+
141
+ year
142
+ end
144
143
  end
145
- private_class_method :push_last_year
146
144
  end
147
145
  end
148
146
  end
@@ -52,7 +52,7 @@ module Zakuro
52
52
  # @return [Cycle::AbstractRemainder] 1始まりの大余小余
53
53
  #
54
54
  def adjusted_remainder
55
- @remainder.add(Cycle::AbstractRemainder.new(day: 1, minute: 0, second: 0))
55
+ remainder.add(Cycle::AbstractRemainder.new(day: 1, minute: 0, second: 0))
56
56
  end
57
57
 
58
58
  private
@@ -12,59 +12,61 @@ module Zakuro
12
12
  # ChoukeiValue 再考長慶宣明暦算法
13
13
  #
14
14
  module ChoukeiValue
15
- #
16
- # 四捨五入した大余を返す
17
- #
18
- # @param [Integer] per 増減率
19
- # @param [Integer] denominator 小余の分母
20
- # @param [Integer] minute 小余
21
- #
22
- # @return [Integer] 累計値(大余)
23
- #
24
- def self.rounded_day(per:, denominator:, minute:)
25
- remainder_minute = Type::OldFloat.new((per * minute).to_f)
26
- day = day_only(remainder_minute: remainder_minute.get, denominator: denominator)
27
- # 繰り上げ結果を足す
28
- day += carried_minute(remainder_minute: remainder_minute, denominator: denominator)
15
+ class << self
16
+ #
17
+ # 四捨五入した大余を返す
18
+ #
19
+ # @param [Integer] per 増減率
20
+ # @param [Integer] denominator 小余の分母
21
+ # @param [Integer] minute 小余
22
+ #
23
+ # @return [Integer] 累計値(大余)
24
+ #
25
+ def rounded_day(per:, denominator:, minute:)
26
+ remainder_minute = Type::OldFloat.new((per * minute).to_f)
27
+ day = day_only(remainder_minute: remainder_minute.get, denominator: denominator)
28
+ # 繰り上げ結果を足す
29
+ day += carried_minute(remainder_minute: remainder_minute, denominator: denominator)
29
30
 
30
- day
31
- end
31
+ day
32
+ end
32
33
 
33
- #
34
- # 秒がない大余小余にする
35
- #
36
- # @param [Cycle::LunarRemainder] remainder 大余小余
37
- #
38
- # @note 815年で大余繰り上げあり
39
- #
40
- # @return [Integer] 大余
41
- # @return [Float] 小余
42
- #
43
- def self.remainder_without_second(remainder:)
44
- adjusted = remainder.class.new(
45
- day: remainder.day, minute: remainder.floor_minute, second: 0
46
- )
47
- adjusted.carry!
34
+ #
35
+ # 秒がない大余小余にする
36
+ #
37
+ # @param [Cycle::LunarRemainder] remainder 大余小余
38
+ #
39
+ # @note 815年で大余繰り上げあり
40
+ #
41
+ # @return [Integer] 大余
42
+ # @return [Float] 小余
43
+ #
44
+ def remainder_without_second(remainder:)
45
+ adjusted = remainder.class.new(
46
+ day: remainder.day, minute: remainder.floor_minute, second: 0
47
+ )
48
+ adjusted.carry!
48
49
 
49
- [adjusted.day, adjusted.minute]
50
- end
50
+ [adjusted.day, adjusted.minute]
51
+ end
51
52
 
52
- def self.day_only(remainder_minute:, denominator:)
53
- float_day = Type::OldFloat.new(remainder_minute / denominator)
54
- # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
55
- float_day.floor!
56
- float_day.get
57
- end
58
- private_class_method :day_only
53
+ private
54
+
55
+ def day_only(remainder_minute:, denominator:)
56
+ float_day = Type::OldFloat.new(remainder_minute / denominator)
57
+ # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
58
+ float_day.floor!
59
+ float_day.get
60
+ end
59
61
 
60
- def self.carried_minute(remainder_minute:, denominator:)
61
- remainder_day = remainder_minute.abs % denominator
62
- # 四捨五入(1/2日 以上なら繰り上げる)
63
- return remainder_minute.sign if remainder_day >= (denominator / 2)
62
+ def carried_minute(remainder_minute:, denominator:)
63
+ remainder_day = remainder_minute.abs % denominator
64
+ # 四捨五入(1/2日 以上なら繰り上げる)
65
+ return remainder_minute.sign if remainder_day >= (denominator / 2)
64
66
 
65
- 0
67
+ 0
68
+ end
66
69
  end
67
- private_class_method :carried_minute
68
70
  end
69
71
  end
70
72
  end
@@ -10,6 +10,9 @@ module Zakuro
10
10
  # AbstractAverage 平気(太陽軌道平均)
11
11
  #
12
12
  class AbstractAverage
13
+ # @return [Cycle::AbstractSolarTerm] 入定気
14
+ attr_reader :solar_term
15
+
13
16
  #
14
17
  # 初期化
15
18
  #
@@ -41,30 +44,32 @@ module Zakuro
41
44
 
42
45
  # :reek:TooManyStatements { max_statements: 7 }
43
46
 
44
- #
45
- # 月内(当月朔日から当月末日(来月朔日の前日)の間)に二十四節気があるか
46
- # @note 大余60で一巡するため 以下2パターンがある
47
- # * current_month <= next_month : (二十四節気) >= current_month && (二十四節気) < next_month
48
- # * current_month > next_month : (二十四節気) >= current_month || (二十四節気) < next_month
49
- #
50
- # @param [Cycle::AbstractRemainder] solar_term 二十四節気
51
- # @param [Cycle::AbstractRemainder] current_month 月初
52
- # @param [Cycle::AbstractRemainder] next_month 月末
53
- #
54
- # @return [True] 対象の二十四節気がある
55
- # @return [False] 対象の二十四節気がない
56
- #
57
- def self.in_solar_term?(solar_term:, current_month:, next_month:)
58
- # 大余で比較する
59
- target_time = solar_term.day
60
- current_month_time = current_month.day
61
- next_month_time = next_month.day
62
- current_month_over = (target_time >= current_month_time)
63
- next_month_under = (target_time < next_month_time)
47
+ class << self
48
+ #
49
+ # 月内(当月朔日から当月末日(来月朔日の前日)の間)に二十四節気があるか
50
+ # @note 大余60で一巡するため 以下2パターンがある
51
+ # * current_month <= next_month : (二十四節気) >= current_month && (二十四節気) < next_month
52
+ # * current_month > next_month : (二十四節気) >= current_month || (二十四節気) < next_month
53
+ #
54
+ # @param [Cycle::AbstractRemainder] solar_term 二十四節気
55
+ # @param [Cycle::AbstractRemainder] current_month 月初
56
+ # @param [Cycle::AbstractRemainder] next_month 月末
57
+ #
58
+ # @return [True] 対象の二十四節気がある
59
+ # @return [False] 対象の二十四節気がない
60
+ #
61
+ def in_solar_term?(solar_term:, current_month:, next_month:)
62
+ # 大余で比較する
63
+ target_time = solar_term.day
64
+ current_month_time = current_month.day
65
+ next_month_time = next_month.day
66
+ current_month_over = (target_time >= current_month_time)
67
+ next_month_under = (target_time < next_month_time)
64
68
 
65
- return current_month_over && next_month_under if current_month_time <= next_month_time
69
+ return current_month_over && next_month_under if current_month_time <= next_month_time
66
70
 
67
- current_month_over || next_month_under
71
+ current_month_over || next_month_under
72
+ end
68
73
  end
69
74
 
70
75
  private
@@ -83,8 +88,8 @@ module Zakuro
83
88
  # * 閏月は1回しか設定しない
84
89
  # * 最大2回設定する(中気・節気)
85
90
  (0..3).each do |_index|
86
- in_range = AbstractAverage.in_solar_term?(
87
- solar_term: @solar_term.remainder, current_month: current_month.remainder,
91
+ in_range = self.class.in_solar_term?(
92
+ solar_term: solar_term.remainder, current_month: current_month.remainder,
88
93
  next_month: next_month.remainder
89
94
  )
90
95
 
@@ -97,7 +102,7 @@ module Zakuro
97
102
  next
98
103
  end
99
104
 
100
- current_month.add_term(term: @solar_term.clone)
105
+ current_month.add_term(term: solar_term.clone)
101
106
  next_solar_term
102
107
 
103
108
  # 定気は最大2つまで
@@ -109,7 +114,7 @@ module Zakuro
109
114
  # 次の二十四節気に移る
110
115
  #
111
116
  def next_solar_term
112
- @solar_term.next_term!
117
+ solar_term.next_term!
113
118
  end
114
119
  end
115
120
  end
@@ -58,7 +58,7 @@ module Zakuro
58
58
  # 弦の分だけ太陽地点を進める
59
59
  #
60
60
  def add_quarter
61
- @remainder.add!(quarter)
61
+ remainder.add!(quarter)
62
62
  end
63
63
 
64
64
  #
@@ -151,12 +151,12 @@ module Zakuro
151
151
  def prev(index:)
152
152
  interval = interval(index: index)
153
153
  if remainder > interval
154
- @remainder.sub!(interval)
154
+ remainder.sub!(interval)
155
155
  return
156
156
  end
157
157
 
158
158
  # 入定気が確定する
159
- @remainder = interval.sub(@remainder)
159
+ @remainder = interval.sub(remainder)
160
160
  @index = index
161
161
  end
162
162
 
@@ -165,7 +165,7 @@ module Zakuro
165
165
  #
166
166
  def next_index
167
167
  @index += 1
168
- @index = 0 if @index >= interval_size
168
+ @index = 0 if index >= interval_size
169
169
  end
170
170
 
171
171
  #
@@ -176,7 +176,7 @@ module Zakuro
176
176
  # 現在の二十四節気に留まる
177
177
  return if remainder < interval
178
178
 
179
- @remainder.sub!(interval)
179
+ remainder.sub!(interval)
180
180
 
181
181
  next_index
182
182