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
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './month'
4
3
  require_relative '../../operation/operation'
4
+ require_relative './operated_solar_term'
5
+ require_relative './month'
5
6
 
6
7
  # :nodoc:
7
8
  module Zakuro
@@ -17,8 +18,8 @@ module Zakuro
17
18
  class OperatedMonth < Month
18
19
  # @return [Operation::MonthHistory] 変更履歴(月)
19
20
  attr_reader :history
20
- # @return [OperatedSolarTerms] 運用時二十四節気
21
- attr_reader :operated_solar_terms
21
+ # @return [OperatedSolarTerm] 運用時二十四節気
22
+ attr_reader :operated_solar_term
22
23
 
23
24
  # :reek:LongParameterList {max_params: 6}
24
25
  # rubocop:disable Metrics/ParameterLists
@@ -26,20 +27,20 @@ module Zakuro
26
27
  #
27
28
  # 初期化
28
29
  #
29
- # @param [Context] context 暦コンテキスト
30
- # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
30
+ # @param [Context::Context] context 暦コンテキスト
31
+ # @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
31
32
  # @param [MonthLabel] month_label 月表示名
32
33
  # @param [FirstDay] first_day 月初日(朔日)
33
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
34
35
  # @param [Operation::MonthHistory] history 変更履歴(月)
35
36
  #
36
- def initialize(context:, operated_solar_terms:, month_label: MonthLabel.new,
37
+ def initialize(context:, operated_solar_term:, month_label: MonthLabel.new,
37
38
  first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
38
39
  history: Operation::MonthHistory.new)
39
40
  super(context: context, month_label: month_label, first_day: first_day,
40
41
  solar_terms: solar_terms, gengou: gengou)
41
42
  @history = history
42
- @operated_solar_terms = operated_solar_terms
43
+ @operated_solar_term = operated_solar_term
43
44
  @moved = false
44
45
  end
45
46
 
@@ -61,110 +62,39 @@ module Zakuro
61
62
  diff = history.diffs.month
62
63
 
63
64
  @month_label = MonthLabel.new(
64
- number: OperatedMonth.rewrite_month_fields(
65
+ number: self.class.rewrite_month_fields(
65
66
  month_diff: diff, month_label: month_label, name: 'number'
66
67
  ),
67
- is_many_days: OperatedMonth.rewrite_month_fields(
68
+ is_many_days: self.class.rewrite_month_fields(
68
69
  month_diff: diff, month_label: month_label, name: 'is_many_days'
69
70
  ),
70
- leaped: OperatedMonth.rewrite_month_fields(
71
+ leaped: self.class.rewrite_month_fields(
71
72
  month_diff: diff, month_label: month_label, name: 'leaped'
72
73
  )
73
74
  )
74
75
  end
75
76
 
76
- def self.rewrite_month_fields(month_diff:, month_label:, name:)
77
- method_name = name.intern
78
-
79
- diff = month_diff.send(method_name)
80
- default = month_label.send(method_name)
81
- return default if diff.invalid?
82
-
83
- diff.actual
84
- end
85
-
86
77
  #
87
78
  # 二十四節気ごとの差分で書き換える
88
79
  #
89
80
  def rewrite_solar_terms
90
- matched, operated_solar_term = @operated_solar_terms.get(
81
+ matched, solar_term = operated_solar_term.get(
91
82
  western_date: first_day.western_date
92
83
  )
93
84
 
94
85
  return unless matched
95
86
 
96
- @solar_terms = OperatedMonth.create_operated_solar_terms(
97
- operated_solar_term: operated_solar_term,
87
+ @solar_terms = OperatedSolarTerm.create_operated_solar_term(
88
+ operated_solar_term: solar_term,
98
89
  solar_terms: solar_terms
99
90
  )
100
91
  end
101
92
 
102
- #
103
- # 運用情報によって改変した二十四節気を作成する
104
- #
105
- # @param [<Type>] operated_solar_term 運用情報(二十四節気)
106
- # @param [Array<SolarTerm>] solar_terms 二十四節気
107
- #
108
- # @return [Array<SolarTerm>] 二十四節気
109
- #
110
- def self.create_operated_solar_terms(operated_solar_term:, solar_terms:)
111
- index = operated_solar_term.index
112
-
113
- # 別の月に移動する二十四節気。割り当てない。
114
- result = remove_solar_term(index: index, solar_terms: solar_terms)
115
-
116
- return result if used_solar_term?(index: index, solar_terms: solar_terms)
117
-
118
- result.push(operated_solar_term)
119
-
120
- result
121
- end
122
-
123
- # :reek:ControlParameter
124
-
125
- #
126
- # 二十四節気が使用されているか
127
- #
128
- # @param [Integer] index 二十四節気番号
129
- # @param [Array<SolarTerm>] solar_terms 二十四節気
130
- #
131
- # @return [True] 使用
132
- # @return [False] 未使用
133
- #
134
- def self.used_solar_term?(index:, solar_terms:)
135
- solar_terms.each do |solar_term|
136
- return true if index == solar_term.index
137
- end
138
-
139
- false
140
- end
141
-
142
- # :reek:ControlParameter
143
-
144
- #
145
- # 対象の二十四節気を除外する
146
- #
147
- # @param [Integer] index 二十四節気番号
148
- # @param [Array<SolarTerm>] solar_terms 二十四節気
149
- #
150
- # @return [Array<SolarTerm>] 二十四節気(対象除外済)
151
- #
152
- def self.remove_solar_term(index:, solar_terms:)
153
- result = []
154
- solar_terms.each do |solar_term|
155
- next if index == solar_term.index
156
-
157
- result.push(solar_term)
158
- end
159
-
160
- result
161
- end
162
-
163
93
  #
164
94
  # 月初日ごとの差分で書き換える
165
95
  #
166
96
  def rewrite_first_day
167
- diffs = @history.diffs
97
+ diffs = history.diffs
168
98
  return if diffs.invalid_days?
169
99
 
170
100
  days = diffs.days
@@ -242,10 +172,31 @@ module Zakuro
242
172
  @moved = true
243
173
  end
244
174
 
175
+ class << self
176
+ #
177
+ # 計算結果を該当のフィールドの運用情報に書き換える
178
+ #
179
+ # @param [Operation::Diffs] month_diff 月差分
180
+ # @param [MonthLabel] month_label 月表示情報
181
+ # @param [String] name フィールド名
182
+ #
183
+ # @return [Object] 運用情報
184
+ #
185
+ def rewrite_month_fields(month_diff:, month_label:, name:)
186
+ method_name = name.intern
187
+
188
+ diff = month_diff.send(method_name)
189
+ default = month_label.send(method_name)
190
+ return default if diff.invalid?
191
+
192
+ diff.dest
193
+ end
194
+ end
195
+
245
196
  private
246
197
 
247
198
  def history_month_number
248
- @history.diffs.month.number
199
+ history.diffs.month.number
249
200
  end
250
201
  end
251
202
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Monthly
9
+ #
10
+ # OperatedSolarTerm 運用二十四節気
11
+ #
12
+ module OperatedSolarTerm
13
+ class << self
14
+ #
15
+ # 運用情報によって改変した二十四節気を作成する
16
+ #
17
+ # @param [<Type>] operated_solar_term 運用情報(二十四節気)
18
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
19
+ #
20
+ # @return [Array<SolarTerm>] 二十四節気
21
+ #
22
+ def create_operated_solar_term(operated_solar_term:, solar_terms:)
23
+ index = operated_solar_term.index
24
+
25
+ # 別の月に移動する二十四節気。割り当てない。
26
+ result = remove_solar_term(index: index, solar_terms: solar_terms)
27
+
28
+ return result if used_solar_term?(index: index, solar_terms: solar_terms)
29
+
30
+ result.push(operated_solar_term)
31
+
32
+ result
33
+ end
34
+
35
+ private
36
+
37
+ # :reek:ControlParameter
38
+
39
+ #
40
+ # 二十四節気が使用されているか
41
+ #
42
+ # @param [Integer] index 二十四節気番号
43
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
44
+ #
45
+ # @return [True] 使用
46
+ # @return [False] 未使用
47
+ #
48
+ def used_solar_term?(index:, solar_terms:)
49
+ solar_terms.each do |solar_term|
50
+ return true if index == solar_term.index
51
+ end
52
+
53
+ false
54
+ end
55
+
56
+ # :reek:ControlParameter
57
+
58
+ #
59
+ # 対象の二十四節気を除外する
60
+ #
61
+ # @param [Integer] index 二十四節気番号
62
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
63
+ #
64
+ # @return [Array<SolarTerm>] 二十四節気(対象除外済)
65
+ #
66
+ def remove_solar_term(index:, solar_terms:)
67
+ result = []
68
+ solar_terms.each do |solar_term|
69
+ next if index == solar_term.index
70
+
71
+ result.push(solar_term)
72
+ end
73
+
74
+ result
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Option
9
+ # :nodoc:
10
+ module DroppedDate
11
+ #
12
+ # AbstractParameter 没日引数
13
+ #
14
+ class AbstractParameter
15
+ # @return [True] 有効
16
+ # @return [False] 無効
17
+ attr_reader :valid
18
+ # @return [Integer] 年
19
+ attr_reader :year
20
+ # @return [Cycle::AbstractRemainder] 「有没之気」判定
21
+ attr_reader :limit
22
+ # @return [Class] 没余クラス
23
+ attr_reader :remainder_class
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [True, False] valid 有効/無効
29
+ # @param [Integer] year 年
30
+ # @param [Cycle::AbstractRemainder] limit 「有没之気」判定
31
+ # @param [Class] remainder_class 没余クラス
32
+ #
33
+ def initialize(valid: false, year: 0, limit: Cycle::AbstractRemainder.new,
34
+ remainder_class: Object)
35
+ @valid = valid
36
+ @year = year
37
+ @limit = limit
38
+ @remainder_class = remainder_class
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Option
9
+ # :nodoc:
10
+ module DroppedDate
11
+ #
12
+ # Location 没日位置
13
+ #
14
+ class Location
15
+ # @return [Integer] 理想上の年日数
16
+ IDEAL_YEAR = 360
17
+
18
+ # @return [Context::Context] 暦コンテキスト
19
+ attr_reader :context
20
+ # @return [True] 有効
21
+ # @return [False] 無効
22
+ attr_reader :valid
23
+ # @return [Cycle::AbstractRemainder] 「有没之気」判定
24
+ attr_reader :limit
25
+ # @return [Integer] 年
26
+ attr_reader :year
27
+ # @return [Array<Cycle::AbstractSolarTerm>] 二十四節気
28
+ attr_reader :solar_terms
29
+ # @return [Class] 没余クラス
30
+ attr_reader :remainder_class
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [Context::Context] context 暦コンテキスト
36
+ # @param [Array<Cycle::AbstractSolarTerm>] solar_terms 二十四節気
37
+ #
38
+ def initialize(context:, solar_terms: [])
39
+ parameter = context.resolver.dropped_date_parameter.new
40
+ @context = context
41
+ @valid = parameter.valid
42
+ @limit = parameter.limit
43
+ @year = parameter.year
44
+ @remainder_class = parameter.remainder_class
45
+ @solar_terms = solar_terms
46
+ end
47
+
48
+ #
49
+ # 不正か
50
+ #
51
+ # @return [True] 不正
52
+ # @return [False] 不正なし
53
+ #
54
+ def invalid?
55
+ !@valid
56
+ end
57
+
58
+ #
59
+ # 没日が存在するか?
60
+ #
61
+ # @return [True] 存在あり
62
+ # @return [False] 存在なし
63
+ #
64
+ def exist?
65
+ !solar_term_remainder.invalid?
66
+ end
67
+
68
+ #
69
+ # 「没余」を返す
70
+ #
71
+ # @return [Cycle::AbstractRemainder] 没余
72
+ #
73
+ def get
74
+ # 1. 二十四節気の大余小余を取り出す
75
+ remainder = solar_term_remainder
76
+ # 2. 小余360、秒45(360/8)で乗算する
77
+ total = multiple_ideal_year(remainder: remainder)
78
+ # 3. 上記2と章歳(3068055)の差を求める
79
+ diff = (year - total).abs
80
+ # 4. 上記3を通余で徐算する
81
+ result = remainder_class.new(total: diff)
82
+ # 5. 上記4の商と上記1の大余が没日大余、余りが小余(没余)
83
+ day = remainder_class.new(day: remainder.day, minute: 0, second: 0)
84
+
85
+ day.add(result)
86
+ end
87
+
88
+ #
89
+ # 該当の二十四節気を取得する
90
+ #
91
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
92
+ #
93
+ def solar_term
94
+ solar_terms.each do |solar_term|
95
+ remainder = solar_term.remainder.clone
96
+ minute_later = remainder.class.new(
97
+ day: 0, minute: remainder.minute, second: remainder.second
98
+ )
99
+
100
+ return solar_term if minute_later >= limit
101
+ end
102
+
103
+ context.resolver.solar_term.new
104
+ end
105
+
106
+ private
107
+
108
+ #
109
+ # 二十四節気の大余小余を取得する
110
+ #
111
+ # @return [Type::Optional<Cycle::AbstractRemainder>] 大余小余
112
+ #
113
+ def solar_term_remainder
114
+ solar_term.remainder
115
+ end
116
+
117
+ #
118
+ # 理想上の年数を乗算する
119
+ #
120
+ # 宣明暦:小余360、秒45(360/8)で積算する
121
+ #
122
+ # @return [Cycle::AbstractRemainder] 大余小余
123
+ #
124
+ # @return [Integer] 乗算結果
125
+ #
126
+ def multiple_ideal_year(remainder:)
127
+ minute = remainder.minute * IDEAL_YEAR
128
+ second = remainder.second * (IDEAL_YEAR / remainder.base_minute)
129
+ minute + second
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../version/context'
3
+ require_relative '../../context/context'
4
4
 
5
5
  require_relative '../../era/western/calendar'
6
6
  require_relative '../../output/logger'
7
7
 
8
- require_relative '../era/gengou/scroll'
9
8
  require_relative '../era/version/version'
10
9
 
11
10
  require_relative '../base/gengou'
@@ -35,8 +34,8 @@ module Zakuro
35
34
  # * 引き当てたい日付が元旦ではない場合、その月日に従い元号を再度求める
36
35
  # * この再計算が必要になるのは、元号が切り替わる年のみである
37
36
  #
38
- class FullRange
39
- # @return [Context] 暦コンテキスト
37
+ class AbstractFullRange
38
+ # @return [Context::Context] 暦コンテキスト
40
39
  attr_reader :context
41
40
  # @return [Western::Calendar] 開始日
42
41
  attr_reader :start_date
@@ -51,18 +50,19 @@ module Zakuro
51
50
  #
52
51
  # 初期化
53
52
  #
54
- # @param [Context] context 暦コンテキスト
53
+ # @param [Context::Context] context 暦コンテキスト
54
+ # @param [Gengou::AbstractScroll] scroll 元号スクロール
55
55
  # @param [Western::Calendar] start_date 開始日
56
56
  # @param [Western::Calendar] last_date 終了日
57
57
  #
58
- def initialize(context:, start_date: Western::Calendar.new, last_date: Western::Calendar.new)
58
+ def initialize(context:, scroll:,
59
+ start_date: Western::Calendar.new, last_date: Western::Calendar.new)
59
60
  @start_date = start_date
60
61
  @last_date = last_date
61
62
  return if invalid?
62
63
 
63
- # TODO: 現時点では使用していない。特定の暦を指定できるようになった状態で使用する
64
64
  @context = context
65
- @scroll = Gengou::Scroll.new(start_date: start_date, last_date: last_date)
65
+ @scroll = scroll
66
66
  end
67
67
 
68
68
  #
@@ -72,7 +72,7 @@ module Zakuro
72
72
  # @return [False] 有効
73
73
  #
74
74
  def invalid?
75
- @start_date.invalid?
75
+ start_date.invalid?
76
76
  end
77
77
 
78
78
  #
@@ -100,33 +100,19 @@ module Zakuro
100
100
  # @return [Array<Base::Year>] 完全範囲
101
101
  #
102
102
  def version_ranges
103
- result = []
104
-
105
- start_year = @scroll.western_start_year
106
- last_year = @scroll.western_last_year
103
+ start_year = scroll.western_start_year
104
+ last_year = scroll.western_last_year
107
105
 
106
+ # TODO: context にデフォルト暦名が設定されている場合は使用しない
108
107
  versions = Version.get(start_year: start_year, last_year: last_year)
109
108
 
110
- versions.each_with_index do |version, index|
111
- context = Context.new(version_name: version.name)
112
- start_year = version.start_year
113
- last_year = version.last_year
114
- # 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
115
- last_year += 1 if (index + 1) == versions.size
116
-
117
- years = boundary_resolved_ranges(
118
- context: context, start_year: start_year, last_year: last_year
119
- )
120
- result.concat(years)
121
- end
122
-
123
- result
109
+ collect_version_ranges(versions: versions, start_year: start_year, last_year: last_year)
124
110
  end
125
111
 
126
112
  #
127
113
  # 年境界解決済みの範囲
128
114
  #
129
- # @param [Context] context 暦コンテキスト
115
+ # @param [Context::Context] context 暦コンテキスト
130
116
  # @param [Integer] start_year 開始西暦年
131
117
  # @param [Integer] last_year 終了西暦年
132
118
  #
@@ -145,7 +131,7 @@ module Zakuro
145
131
  #
146
132
  # 完全範囲内の年データを取得する
147
133
  #
148
- # @param [Context] context 暦コンテキスト
134
+ # @param [Context::Context] context 暦コンテキスト
149
135
  # @param [Integer] start_year 開始西暦年
150
136
  # @param [Integer] last_year 終了西暦年
151
137
  #
@@ -165,6 +151,36 @@ module Zakuro
165
151
 
166
152
  years
167
153
  end
154
+
155
+ #
156
+ # 暦別範囲を収集する
157
+ #
158
+ # @param [Array<Version::Range>] versions 暦の範囲
159
+ # @param [Integer] start_year 開始西暦年
160
+ # @param [Integer] last_year 終了西暦年
161
+ #
162
+ # @return [Array<Base::Year>] 完全範囲
163
+ #
164
+ def collect_version_ranges(versions:, start_year:, last_year:)
165
+ result = []
166
+
167
+ versions.each_with_index do |version, index|
168
+ specified_context = Context::Context.new(
169
+ version: version.name, options: context.option.hash
170
+ )
171
+ start_year = version.start_year
172
+ last_year = version.last_year
173
+ # 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
174
+ last_year += 1 if (index + 1) == versions.size
175
+
176
+ years = boundary_resolved_ranges(
177
+ context: specified_context, start_year: start_year, last_year: last_year
178
+ )
179
+ result.concat(years)
180
+ end
181
+
182
+ result
183
+ end
168
184
  end
169
185
  end
170
186
  end