zakuro 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -13
  3. data/VERSION +1 -1
  4. data/doc/dropped_date.md +93 -0
  5. data/doc/error.md +45 -0
  6. data/doc/operation/csv/month.csv +100 -79
  7. data/doc/operation/operation.xlsx +0 -0
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +5 -5
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  11. data/lib/zakuro/calculation/base/operated_year.rb +26 -24
  12. data/lib/zakuro/calculation/base/year.rb +7 -7
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
  14. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  15. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  16. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
  17. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  18. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  19. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
  27. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  28. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  29. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  30. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  31. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  32. data/lib/zakuro/calculation/monthly/month.rb +17 -17
  33. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  34. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  35. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  36. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  37. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  38. data/lib/zakuro/calculation/range/abstract_full_range.rb +40 -25
  39. data/lib/zakuro/calculation/range/abstract_operation_range.rb +111 -109
  40. data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
  41. data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
  42. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  43. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  44. data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
  45. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  46. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  47. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  48. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  49. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  50. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  51. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  52. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  53. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  54. data/lib/zakuro/calculation/summary/internal/month.rb +32 -11
  55. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  56. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  57. data/lib/zakuro/calculation/summary/japan/range.rb +145 -118
  58. data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
  59. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +57 -50
  60. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  61. data/lib/zakuro/calculation/summary/western/range.rb +95 -92
  62. data/lib/zakuro/calculation/summary/western/single.rb +78 -76
  63. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -119
  64. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +63 -56
  65. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  66. data/lib/zakuro/calculation/type/optional.rb +46 -0
  67. data/lib/zakuro/condition.rb +142 -92
  68. data/lib/zakuro/context/context.rb +44 -0
  69. data/lib/zakuro/context/option.rb +119 -0
  70. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  71. data/lib/zakuro/era/japan/calendar.rb +35 -33
  72. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +8 -4
  73. data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
  74. data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
  75. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
  76. data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
  77. data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -34
  78. data/lib/zakuro/era/japan/gengou/resource/type.rb +45 -37
  79. data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
  80. data/lib/zakuro/era/japan/gengou.rb +28 -26
  81. data/lib/zakuro/era/japan/version.rb +18 -16
  82. data/lib/zakuro/era/western/calendar.rb +104 -88
  83. data/lib/zakuro/exception/case/pattern.rb +39 -3
  84. data/lib/zakuro/exception/case/preset.rb +2 -2
  85. data/lib/zakuro/exception/exception.rb +17 -15
  86. data/lib/zakuro/exception/zakuro_error.rb +19 -1
  87. data/lib/zakuro/gateway/locale/date.rb +2 -2
  88. data/lib/zakuro/gateway/locale/range.rb +3 -3
  89. data/lib/zakuro/gateway/range.rb +3 -3
  90. data/lib/zakuro/gateway/single.rb +14 -3
  91. data/lib/zakuro/merchant.rb +79 -9
  92. data/lib/zakuro/operation/month/parser.rb +252 -249
  93. data/lib/zakuro/operation/month/type.rb +17 -8
  94. data/lib/zakuro/operation/month/validator.rb +148 -144
  95. data/lib/zakuro/operation/operation.rb +38 -36
  96. data/lib/zakuro/operation/yaml/month.yaml +955 -281
  97. data/lib/zakuro/output/response.rb +107 -141
  98. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  99. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  100. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  101. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  102. data/lib/zakuro/result/data/single_day.rb +9 -1
  103. data/lib/zakuro/result/operation/month/annotation.rb +2 -2
  104. data/lib/zakuro/result/operation/month/history.rb +2 -2
  105. data/lib/zakuro/result/operation/month.rb +31 -0
  106. data/lib/zakuro/result/operation.rb +39 -0
  107. data/lib/zakuro/result/result.rb +3 -3
  108. data/lib/zakuro/tools/stringifier.rb +67 -42
  109. data/lib/zakuro/tools/typeconv.rb +17 -15
  110. data/lib/zakuro/tools/typeof.rb +15 -13
  111. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  112. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  113. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  114. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  115. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  116. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  117. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  118. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  119. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  120. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  121. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  122. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  123. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  124. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  125. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  126. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  127. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  128. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  129. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  130. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  131. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  132. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  133. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  134. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  135. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  136. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  137. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  138. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  139. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  140. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  141. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  142. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  143. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  144. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  145. data/lib/zakuro/version/senmyou/const/remainder.rb +7 -1
  146. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  147. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  148. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  149. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  150. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  151. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  152. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  153. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  154. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  155. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  156. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  157. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  158. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  159. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  160. metadata +27 -7
  161. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
  162. data/lib/zakuro/result/operation/month/bundle.rb +0 -36
  163. data/lib/zakuro/result/operation/operation.rb +0 -44
  164. data/lib/zakuro/version/context.rb +0 -44
  165. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -0,0 +1,220 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../operation/operation'
4
+ require_relative '../monthly/month'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Range
12
+ #
13
+ # OperatedSolarTerm 運用時二十四節気
14
+ #
15
+ class OperatedSolarTerm
16
+ # @return [Array<Year>] 完全範囲(年データ)
17
+ attr_reader :years
18
+ # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
19
+ #
20
+ # * 移動元の二十四節気:無効な大余小余あり(削除対象)
21
+ # * 移動先の二十四節気:移動元からの二十四節気(追加対象)
22
+ #
23
+ attr_reader :directions
24
+ # @return [Context::Context] 暦コンテキスト
25
+ attr_reader :context
26
+
27
+ #
28
+ # 初期化
29
+ #
30
+ # @param [Context::Context] context 暦コンテキスト
31
+ # @param [Array<Year>] years 完全範囲(年データ)
32
+ #
33
+ def initialize(context:, years: [])
34
+ @context = context
35
+ @years = years
36
+ @directions = {}
37
+ end
38
+
39
+ #
40
+ # データ生成する
41
+ #
42
+ # @return [<Type>] <description>
43
+ #
44
+ def create
45
+ @directions = create_directions
46
+ end
47
+
48
+ #
49
+ # 二十四節気を取得する
50
+ #
51
+ # @param [Western::Calendar] western_date 月初日の西暦日
52
+ #
53
+ # @return [True] 対象あり
54
+ # @return [False] 対象なし
55
+ # @return [SolarTerm] 二十四節気
56
+ #
57
+ def get(western_date: Western::Calendar.new)
58
+ context = current_context(western_date: western_date)
59
+
60
+ solar_term_class = context.resolver.solar_term
61
+ solar_term = directions.fetch(western_date.format, solar_term_class.new)
62
+
63
+ # 合致しない場合
64
+ return false, solar_term_class.new if solar_term.empty?
65
+
66
+ # 合致した上で、二十四節気が移動元(削除対象)の場合
67
+ # 合致した上で、二十四節気が移動先(追加対象)の場合
68
+ [true, solar_term]
69
+ end
70
+
71
+ # :reek:LongParameterList {max_params: 4}
72
+
73
+ class << self
74
+ # :reek:TooManyStatements { max_statements: 6 }
75
+
76
+ #
77
+ # 年内の全ての月の移動方向を作成する
78
+ #
79
+ # @param [Context::Context] context 暦コンテキスト
80
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
81
+ # @param [Array<Month>] months 年内の全ての月
82
+ #
83
+ def create_directions_with_months(context:, directions: {}, months: [])
84
+ months.each do |month|
85
+ history = Operation.specify_history(western_date: month.western_date)
86
+
87
+ next if history.invalid?
88
+
89
+ direction = history.diffs.solar_term
90
+
91
+ next if direction.invalid?
92
+
93
+ create_directions_each_month(
94
+ context: context, directions: directions, direction: direction, month: month
95
+ )
96
+ end
97
+ end
98
+
99
+ #
100
+ # 月毎の移動方向を作成する
101
+ #
102
+ # @param [Context::Context] context 暦コンテキスト
103
+ # @param [Month] 月
104
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
105
+ # @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
106
+ #
107
+ def create_directions_each_month(context:, month:, directions: {},
108
+ direction: Operation::SolarTerm::Diretion.new)
109
+
110
+ month.solar_terms.each do |solar_term|
111
+ push_source(context: context, directions: directions,
112
+ direction: direction, solar_term: solar_term)
113
+ end
114
+ push_destination(context: context, directions: directions,
115
+ destination: direction.destination)
116
+ end
117
+
118
+ # :reek:LongParameterList {max_params: 4}
119
+
120
+ #
121
+ # 移動先に有効な二十四節気(差し替える二十四節気)を指定する
122
+ #
123
+ # @param [Context::Context] context 暦コンテキスト
124
+ # @param [SolarTerm] solar_term 二十四節気(計算値)
125
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
126
+ # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
127
+ #
128
+ def push_source(context:, solar_term:, directions: {},
129
+ direction: Operation::SolarTerm::Direction.new)
130
+ source = direction.source
131
+
132
+ return if source.invalid?
133
+
134
+ return unless source.index == solar_term.index
135
+
136
+ # 移動先に移動元の二十四節気を指定する
137
+ directions[source.to.format] = created_source(
138
+ context: context, direction: direction, solar_term: solar_term
139
+ )
140
+ end
141
+
142
+ #
143
+ # 移動先に有効な二十四節気(差し替える二十四節気)を生成する
144
+ #
145
+ # @param [Context::Context] context 暦コンテキスト
146
+ # @param [SolarTerm] solar_term 二十四節気(計算値)
147
+ # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
148
+ #
149
+ # @return [SolarTerm] 二十四節気(運用値)
150
+ #
151
+ def created_source(context:, solar_term:,
152
+ direction: Operation::SolarTerm::Direction.new)
153
+ operated_solar_term = solar_term.clone
154
+ remainder_class_name = context.resolver.remainder
155
+
156
+ unless direction.invalid_days?
157
+ # 二十四節気の大余をずらす
158
+ operated_solar_term.remainder.add!(
159
+ remainder_class_name.new(day: direction.days, minute: 0, second: 0)
160
+ )
161
+ end
162
+
163
+ operated_solar_term
164
+ end
165
+
166
+ #
167
+ # 移動元に無効な二十四節気(連番のみ指定)を指定する
168
+ #
169
+ # @param [Context::Context] context 暦コンテキスト
170
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
171
+ # @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
172
+ #
173
+ def push_destination(context:, directions: {},
174
+ destination: Operation::SolarTerm::Destination.new)
175
+ return if destination.invalid?
176
+
177
+ solar_term_class = context.resolver.solar_term
178
+ directions[destination.from.format] = solar_term_class.new(
179
+ index: destination.index
180
+ )
181
+ end
182
+ end
183
+
184
+ private
185
+
186
+ #
187
+ # 日付に対応する暦コンテキストを取得する
188
+ #
189
+ # @param [Western::Calendar] western_date 西暦日
190
+ #
191
+ # @return [Context::Context] 暦コンテキスト
192
+ #
193
+ def current_context(western_date: Western::Calendar.new)
194
+ years.each do |year|
195
+ return year.context if western_date >= year.new_year_date
196
+ end
197
+
198
+ Context::Context.new
199
+ end
200
+
201
+ #
202
+ # 二十四節気の移動元/移動先を生成する
203
+ #
204
+ # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
205
+ #
206
+ def create_directions
207
+ directions = {}
208
+
209
+ years.each do |year|
210
+ self.class.create_directions_with_months(
211
+ context: year.context, directions: directions, months: year.months
212
+ )
213
+ end
214
+
215
+ directions
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
@@ -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 暦コンテキスト
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 暦コンテキスト
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 暦コンテキスト
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 暦コンテキスト
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 暦コンテキスト
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 暦コンテキスト
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