zakuro 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +46 -17
  4. data/VERSION +1 -1
  5. data/doc/dropped_date.md +93 -0
  6. data/doc/error.md +45 -0
  7. data/doc/operation/transfer.rb +8 -8
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +49 -3
  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/{scroll.rb → abstract_scroll.rb} +44 -37
  17. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  19. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  20. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +156 -0
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  27. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +73 -0
  28. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
  29. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  30. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  31. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  32. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  33. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  34. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  35. data/lib/zakuro/calculation/monthly/month.rb +55 -16
  36. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  37. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  38. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  39. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  40. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  41. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +45 -29
  42. data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
  43. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  44. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  45. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  46. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  47. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  48. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  49. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  50. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  51. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  52. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  53. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  54. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  55. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  56. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  57. data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
  58. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  59. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  60. data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
  61. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  62. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
  63. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  64. data/lib/zakuro/calculation/summary/western/range.rb +127 -0
  65. data/lib/zakuro/calculation/summary/western/single.rb +115 -0
  66. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
  67. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
  68. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  69. data/lib/zakuro/calculation/type/optional.rb +46 -0
  70. data/lib/zakuro/condition.rb +143 -94
  71. data/lib/zakuro/context/context.rb +44 -0
  72. data/lib/zakuro/context/option.rb +119 -0
  73. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  74. data/lib/zakuro/era/japan/calendar.rb +35 -33
  75. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
  76. data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
  77. data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
  78. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
  79. data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
  80. data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
  81. data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
  82. data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
  83. data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
  84. data/lib/zakuro/era/japan/gengou.rb +28 -41
  85. data/lib/zakuro/era/japan/version.rb +18 -16
  86. data/lib/zakuro/era/western/calendar.rb +104 -88
  87. data/lib/zakuro/exception/case/pattern.rb +71 -0
  88. data/lib/zakuro/exception/case/preset.rb +51 -0
  89. data/lib/zakuro/exception/case/template.rb +48 -0
  90. data/lib/zakuro/exception/cause.rb +28 -0
  91. data/lib/zakuro/exception/exception.rb +39 -0
  92. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  93. data/lib/zakuro/gateway/locale/date.rb +127 -0
  94. data/lib/zakuro/gateway/locale/range.rb +67 -0
  95. data/lib/zakuro/gateway/range.rb +99 -0
  96. data/lib/zakuro/gateway/single.rb +81 -0
  97. data/lib/zakuro/merchant.rb +67 -33
  98. data/lib/zakuro/operation/month/parser.rb +252 -249
  99. data/lib/zakuro/operation/month/type.rb +44 -35
  100. data/lib/zakuro/operation/month/validator.rb +182 -178
  101. data/lib/zakuro/operation/operation.rb +38 -36
  102. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  103. data/lib/zakuro/output/logger.rb +17 -3
  104. data/lib/zakuro/output/response.rb +107 -141
  105. data/lib/zakuro/result/data/day.rb +43 -0
  106. data/lib/zakuro/result/data/gengou.rb +35 -0
  107. data/lib/zakuro/result/data/month.rb +63 -0
  108. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  109. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  110. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  111. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  112. data/lib/zakuro/result/data/single_day.rb +56 -0
  113. data/lib/zakuro/result/data/solar_term.rb +35 -0
  114. data/lib/zakuro/result/data/year.rb +45 -0
  115. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  116. data/lib/zakuro/result/operation/month/history.rb +54 -0
  117. data/lib/zakuro/result/operation/month.rb +31 -0
  118. data/lib/zakuro/result/operation.rb +22 -97
  119. data/lib/zakuro/result/result.rb +6 -4
  120. data/lib/zakuro/tools/stringifier.rb +67 -42
  121. data/lib/zakuro/tools/typeconv.rb +17 -15
  122. data/lib/zakuro/tools/typeof.rb +15 -13
  123. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  124. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  125. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  126. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  127. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  128. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  129. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  130. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  131. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  132. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  133. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  134. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  135. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  136. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  137. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  138. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  139. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  140. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  141. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  142. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  143. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  144. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  145. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  146. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  147. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  148. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  149. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  150. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  151. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  152. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  153. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  154. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  155. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  156. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  157. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  158. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  159. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  160. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  161. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  162. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  163. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  164. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  165. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  166. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  167. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  168. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  169. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  170. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  171. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  172. metadata +68 -16
  173. data/lib/zakuro/calculation/range/operated_range.rb +0 -193
  174. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
  175. data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
  176. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  177. data/lib/zakuro/calculation/summary/range.rb +0 -120
  178. data/lib/zakuro/calculation/summary/single.rb +0 -110
  179. data/lib/zakuro/result/data.rb +0 -187
  180. data/lib/zakuro/version/context.rb +0 -44
  181. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -0,0 +1,193 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './operated_solar_term'
4
+ require_relative '../../operation/operation'
5
+ require_relative '../base/operated_year'
6
+ require_relative '../../calculation/monthly/operated_month'
7
+ require_relative './transfer/gengou_scroller'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Calculation
13
+ # :nodoc:
14
+ module Range
15
+ #
16
+ # AbstractOperationRange 運用結果範囲
17
+ #
18
+ # 何らかの理由により、計算された暦とは異なる運用結果である場合、その結果に合わせて計算結果を上書きする
19
+ class AbstractOperationRange
20
+ # @return [Array<Year>] 年データ(完全範囲)
21
+ attr_reader :years
22
+ # @return [OperatedSolarTerm] 運用時二十四節気
23
+ attr_reader :operated_solar_term
24
+ # @return [Context::Context] 暦コンテキスト
25
+ attr_reader :context
26
+
27
+ #
28
+ # 初期化
29
+ #
30
+ # @param [Context::Context] context 暦コンテキスト
31
+ # @param [Gengou::AbstractScroll] scroll 元号スクロール
32
+ # @param [Array<Year>] years 年データ(完全範囲)
33
+ #
34
+ def initialize(context:, scroll:, years: [])
35
+ @context = context
36
+ @years = years
37
+ @scroll = scroll
38
+ @operated_solar_term = OperatedSolarTerm.new(context: context, years: @years)
39
+ operated_solar_term.create
40
+ end
41
+
42
+ #
43
+ # 運用結果範囲を取得する
44
+ #
45
+ # @return [Array<Year>] 運用結果範囲
46
+ #
47
+ def get
48
+ operated_years = rewrite
49
+
50
+ self.class.move(operated_years: operated_years)
51
+
52
+ self.class.commit(operated_years: operated_years)
53
+
54
+ Transfer::GengouScroller.set(scroll: @scroll, years: operated_years)
55
+
56
+ operated_years
57
+ end
58
+
59
+ #
60
+ # 運用結果に書き換える
61
+ #
62
+ # @return [Array<OperatedYear>] 運用結果範囲
63
+ #
64
+ def rewrite
65
+ operated_years = []
66
+
67
+ years.each do |year|
68
+ operated_year = self.class.rewrite_year(
69
+ year: year,
70
+ operated_solar_term: operated_solar_term
71
+ )
72
+ operated_years.push(operated_year)
73
+ end
74
+
75
+ operated_years
76
+ end
77
+
78
+ class << self
79
+ #
80
+ # 運用情報で年を跨ぐ月をその年に寄せる
81
+ #
82
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
83
+ #
84
+ def move(operated_years:)
85
+ move_into_next_year(operated_years: operated_years)
86
+ move_into_last_year(operated_years: operated_years)
87
+ end
88
+
89
+ #
90
+ # 運用情報では来年に属する月を来年に寄せる
91
+ #
92
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
93
+ #
94
+ def move_into_next_year(operated_years:)
95
+ operated_years.each_cons(2) do |current_year, next_year|
96
+ months = current_year.pop_next_year_months
97
+
98
+ next_year.unshift_months(months)
99
+ end
100
+ end
101
+
102
+ #
103
+ # 運用情報では昨年に属する月を昨年に寄せる
104
+ #
105
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
106
+ #
107
+ def move_into_last_year(operated_years:)
108
+ rerversed_year = operated_years.reverse!
109
+ rerversed_year.each_cons(2) do |current_year, last_year|
110
+ months = current_year.shift_last_year_months
111
+ last_year.push_months(months)
112
+ end
113
+
114
+ rerversed_year.reverse!
115
+ end
116
+
117
+ #
118
+ # 年を確定させる
119
+ #
120
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
121
+ #
122
+ def commit(operated_years:)
123
+ operated_years.each(&:commit)
124
+ end
125
+
126
+ #
127
+ # 年を書き換える
128
+ #
129
+ # @param [Year] year 年
130
+ # @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
131
+ #
132
+ # @return [OperatedYear] 年
133
+ #
134
+ def rewrite_year(year:, operated_solar_term:)
135
+ context = year.context
136
+ result = Base::OperatedYear.new(context: context)
137
+ year.months.each do |month|
138
+ result.push(month: resolve_month(
139
+ context: context, month: month,
140
+ operated_solar_term: operated_solar_term
141
+ ))
142
+ end
143
+
144
+ result
145
+ end
146
+
147
+ #
148
+ # 履歴情報の有無に応じた月にする
149
+ #
150
+ # @param [Context] context 暦コンテキスト
151
+ # @param [Month] month 月
152
+ # @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
153
+ #
154
+ # @return [Month] 月
155
+ #
156
+ def resolve_month(context:, month:, operated_solar_term:)
157
+ history = Operation.specify_history(western_date: month.western_date)
158
+
159
+ rewrite_month(
160
+ context: context, month: month, history: history,
161
+ operated_solar_term: operated_solar_term
162
+ )
163
+ end
164
+
165
+ # :reek:LongParameterList {max_params: 4}
166
+
167
+ #
168
+ # 月を運用結果に書き換える
169
+ #
170
+ # @param [Context] context 暦コンテキスト
171
+ # @param [Month] month 月
172
+ # @param [Operation::MonthHistory] history 変更履歴
173
+ # @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
174
+ #
175
+ # @return [Month] 月(運用結果)
176
+ #
177
+ def rewrite_month(context:, month:, history:, operated_solar_term:)
178
+ operated_month = Monthly::OperatedMonth.new(
179
+ context: context,
180
+ month_label: month.month_label, first_day: month.first_day,
181
+ solar_terms: month.solar_terms, history: history, gengou: month.gengou,
182
+ operated_solar_term: operated_solar_term
183
+ )
184
+
185
+ operated_month.rewrite unless history.invalid?
186
+
187
+ operated_month
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../era/gengou/dated_scroll'
4
+ require_relative './abstract_full_range'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Range
12
+ #
13
+ # DatedFullRange 完全範囲
14
+ #
15
+ class DatedFullRange < AbstractFullRange
16
+ #
17
+ # 初期化
18
+ #
19
+ # @param [Context::Context] context 暦コンテキスト
20
+ # @param [Western::Calendar] start_date 開始日
21
+ # @param [Western::Calendar] last_date 終了日
22
+ #
23
+ def initialize(context:,
24
+ start_date: Western::Calendar.new, last_date: Western::Calendar.new)
25
+ scroll = Gengou::DatedScroll.new(start_date: start_date, last_date: last_date)
26
+
27
+ super(context: context, scroll: scroll, start_date: start_date, last_date: last_date)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../era/gengou/dated_scroll'
4
+
5
+ require_relative './abstract_operation_range'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Calculation
11
+ # :nodoc:
12
+ module Range
13
+ #
14
+ # DatedOperationRange 運用結果範囲
15
+ #
16
+ class DatedOperationRange < AbstractOperationRange
17
+ #
18
+ # 初期化
19
+ #
20
+ # @param [Context::Context] context 暦コンテキスト
21
+ # @param [Western::Calendar] start_date 開始日
22
+ # @param [Western::Calendar] last_date 終了日
23
+ # @param [Array<Year>] years 年データ(完全範囲)
24
+ #
25
+ def initialize(context:, start_date: Western::Calendar.new,
26
+ last_date: Western::Calendar.new, years: [])
27
+ scroll = Gengou::DatedScroll.new(start_date: start_date, last_date: last_date)
28
+ super(context: context, scroll: scroll, years: years)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -23,82 +23,83 @@ module Zakuro
23
23
  # @return [Output::Logger] ロガー
24
24
  LOGGER = Output::Logger.new(location: 'medieval_annual_range')
25
25
 
26
- #
27
- # 一覧取得する
28
- #
29
- # * 対象年に対して、前年11月-当年11月までを出力する
30
- # * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
31
- #
32
- # @param [Context] context 暦コンテキスト
33
- # @param [Monthly::AbstractLunarPhase] lunar_phase 月の位相
34
- # @param [Solar::AbstractAverage] solar_average 定気(太陽軌道平均)
35
- #
36
- # @return [Array<Month>] 1年データ
37
- #
38
- def self.get(context:, lunar_phase:, solar_average:)
39
- annual_range = initialized_annual_range(context: context, lunar_phase: lunar_phase)
26
+ class << self
27
+ #
28
+ # 一覧取得する
29
+ #
30
+ # * 対象年に対して、前年11月-当年11月までを出力する
31
+ # * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
32
+ #
33
+ # @param [Context::Context] context 暦コンテキスト
34
+ # @param [Monthly::AbstractLunarPhase] lunar_phase 月の位相
35
+ # @param [Solar::AbstractAverage] solar_average 定気(太陽軌道平均)
36
+ #
37
+ # @return [Array<Month>] 1年データ
38
+ #
39
+ def get(context:, lunar_phase:, solar_average:)
40
+ annual_range = initialized_annual_range(context: context, lunar_phase: lunar_phase)
40
41
 
41
- apply_big_and_small_of_the_month(annual_range: annual_range)
42
+ apply_big_and_small_of_the_month(annual_range: annual_range)
42
43
 
43
- solar_average.set(annual_range: annual_range)
44
+ solar_average.set(annual_range: annual_range)
44
45
 
45
- # 月間隔を取得するためだけの末尾要素を削除
46
- annual_range.pop
46
+ # 月間隔を取得するためだけの末尾要素を削除
47
+ annual_range.pop
47
48
 
48
- initialize_month_label(annual_range: annual_range)
49
- end
49
+ initialize_month_label(annual_range: annual_range)
50
+ end
50
51
 
51
- #
52
- # 1年データを取得する
53
- #
54
- # @param [Context] context 暦コンテキスト
55
- # @param [Monthly::LunarPhase] lunar_phase 月の位相
56
- #
57
- # @return [Array<Month>] 1年データ
58
- #
59
- def self.initialized_annual_range(context:, lunar_phase:)
60
- result = []
52
+ private
61
53
 
62
- # 14ヶ月分を生成する(閏年で最大13ヶ月 + 末月の大小/二十四節気を求めるために必要な月)
63
- (0..13).each do |_index|
64
- adjusted = lunar_phase.next_month
54
+ #
55
+ # 1年データを取得する
56
+ #
57
+ # @param [Context::Context] context 暦コンテキスト
58
+ # @param [Monthly::LunarPhase] lunar_phase 月の位相
59
+ #
60
+ # @return [Array<Month>] 1年データ
61
+ #
62
+ def initialized_annual_range(context:, lunar_phase:)
63
+ result = []
65
64
 
66
- result.push(
67
- Monthly::InitializedMonth.new(
68
- context: context,
69
- month_label: Monthly::MonthLabel.new,
70
- first_day: Monthly::FirstDay.new(remainder: adjusted),
71
- phase_index: 0
65
+ # 14ヶ月分を生成する(閏年で最大13ヶ月 + 末月の大小/二十四節気を求めるために必要な月)
66
+ (0..13).each do |_index|
67
+ adjusted = lunar_phase.next_month
68
+
69
+ result.push(
70
+ Monthly::InitializedMonth.new(
71
+ context: context,
72
+ month_label: Monthly::MonthLabel.new,
73
+ first_day: Monthly::FirstDay.new(remainder: adjusted),
74
+ phase_index: 0
75
+ )
72
76
  )
73
- )
74
- end
77
+ end
75
78
 
76
- result
77
- end
78
- private_class_method :initialized_annual_range
79
+ result
80
+ end
79
81
 
80
- #
81
- # 1年データの各月に月の大小を設定する
82
- #
83
- # @param [Array<Month>] annual_range 1年データ
84
- #
85
- def self.apply_big_and_small_of_the_month(annual_range:)
86
- # NOTE: 最後の月は処理できない(=計算外の余分な月が最後に必要である)
87
- annual_range.each_cons(2) do |(current_month, next_month)|
88
- current_month.eval_many_days(next_month_day: next_month.remainder.day)
82
+ #
83
+ # 1年データの各月に月の大小を設定する
84
+ #
85
+ # @param [Array<Month>] annual_range 1年データ
86
+ #
87
+ def apply_big_and_small_of_the_month(annual_range:)
88
+ # NOTE: 最後の月は処理できない(=計算外の余分な月が最後に必要である)
89
+ annual_range.each_cons(2) do |(current_month, next_month)|
90
+ current_month.eval_many_days(next_month_day: next_month.remainder.day)
91
+ end
89
92
  end
90
- end
91
- private_class_method :apply_big_and_small_of_the_month
92
93
 
93
- #
94
- # 月表示情報を更新する
95
- #
96
- # @param [Array<Month>] annual_range 1年データ
97
- #
98
- def self.initialize_month_label(annual_range:)
99
- annual_range.each(&:rename_month_label_by_solar_term)
94
+ #
95
+ # 月表示情報を更新する
96
+ #
97
+ # @param [Array<Month>] annual_range 1年データ
98
+ #
99
+ def initialize_month_label(annual_range:)
100
+ annual_range.each(&:rename_month_label_by_solar_term)
101
+ end
100
102
  end
101
- private_class_method :initialize_month_label
102
103
  end
103
104
  end
104
105
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../era/gengou/named_scroll'
4
+ require_relative './abstract_full_range'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Range
12
+ #
13
+ # NamedFullRange 完全範囲
14
+ #
15
+ class NamedFullRange < AbstractFullRange
16
+ # @return [String] 不正元号名
17
+ INVALID_NAME = Japan::Calendar::EMPTY
18
+
19
+ #
20
+ # 初期化
21
+ #
22
+ # @param [Context::Context] context 暦コンテキスト
23
+ # @param [String] start_name 開始元号名
24
+ # @param [String] last_name 終了元号名
25
+ #
26
+ def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME)
27
+ scroll = Gengou::NamedScroll.new(start_name: start_name, last_name: last_name)
28
+ range = scroll.range
29
+
30
+ super(
31
+ context: context, scroll: scroll,
32
+ start_date: range.western_start_date, last_date: range.western_last_date
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../era/gengou/named_scroll'
4
+
5
+ require_relative './abstract_operation_range'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Calculation
11
+ # :nodoc:
12
+ module Range
13
+ #
14
+ # NamedOperationRange 運用結果範囲
15
+ #
16
+ class NamedOperationRange < AbstractOperationRange
17
+ # @return [String] 不正元号名
18
+ INVALID_NAME = Japan::Calendar::EMPTY
19
+
20
+ #
21
+ # 初期化
22
+ #
23
+ # @param [Context::Context] context 暦コンテキスト
24
+ # @param [String] start_name 開始元号名
25
+ # @param [String] last_name 終了元号名
26
+ # @param [Array<Year>] years 年データ(完全範囲)
27
+ #
28
+ def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME, years: [])
29
+ scroll = Gengou::NamedScroll.new(start_name: start_name, last_name: last_name)
30
+
31
+ super(context: context, scroll: scroll, years: years)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end