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
@@ -1,218 +0,0 @@
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 OperatedSolarTerms
16
- # @return [Array<Year>] 完全範囲(年データ)
17
- attr_reader :years
18
- # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
19
- #
20
- # * 移動元の二十四節気:無効な大余小余あり(削除対象)
21
- # * 移動先の二十四節気:移動元からの二十四節気(追加対象)
22
- #
23
- attr_reader :directions
24
- # @return [Context] 暦コンテキスト
25
- attr_reader :context
26
-
27
- #
28
- # 初期化
29
- #
30
- # @param [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:TooManyStatements { max_statements: 6 }
72
-
73
- #
74
- # 年内の全ての月の移動方向を作成する
75
- #
76
- # @param [Context] context 暦コンテキスト
77
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
78
- # @param [Array<Month>] months 年内の全ての月
79
- #
80
- def self.create_directions_with_months(context:, directions: {}, months: [])
81
- months.each do |month|
82
- history = Operation.specify_history(western_date: month.western_date)
83
-
84
- next if history.invalid?
85
-
86
- direction = history.diffs.solar_term
87
-
88
- next if direction.invalid?
89
-
90
- OperatedSolarTerms.create_directions_each_month(
91
- context: context, directions: directions, direction: direction, month: month
92
- )
93
- end
94
- end
95
-
96
- # :reek:LongParameterList {max_params: 4}
97
-
98
- #
99
- # 月毎の移動方向を作成する
100
- #
101
- # @param [Context] context 暦コンテキスト
102
- # @param [Month] 月
103
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
104
- # @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
105
- #
106
- def self.create_directions_each_month(context:, month:, directions: {},
107
- direction: Operation::SolarTerm::Diretion.new)
108
-
109
- month.solar_terms.each do |solar_term|
110
- OperatedSolarTerms.push_source(context: context, directions: directions,
111
- direction: direction, solar_term: solar_term)
112
- end
113
- OperatedSolarTerms.push_destination(context: context, directions: directions,
114
- destination: direction.destination)
115
- end
116
-
117
- # :reek:LongParameterList {max_params: 4}
118
-
119
- #
120
- # 移動先に有効な二十四節気(差し替える二十四節気)を指定する
121
- #
122
- # @param [Context] context 暦コンテキスト
123
- # @param [SolarTerm] solar_term 二十四節気(計算値)
124
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
125
- # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
126
- #
127
- def self.push_source(context:, solar_term:, directions: {},
128
- direction: Operation::SolarTerm::Direction.new)
129
- source = direction.source
130
-
131
- return if source.invalid?
132
-
133
- return unless source.index == solar_term.index
134
-
135
- # 移動先に移動元の二十四節気を指定する
136
- directions[source.to.format] = OperatedSolarTerms.created_source(
137
- context: context, direction: direction, solar_term: solar_term
138
- )
139
- end
140
-
141
- #
142
- # 移動先に有効な二十四節気(差し替える二十四節気)を生成する
143
- #
144
- # @param [Context] context 暦コンテキスト
145
- # @param [SolarTerm] solar_term 二十四節気(計算値)
146
- # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
147
- #
148
- # @return [SolarTerm] 二十四節気(運用値)
149
- #
150
- def self.created_source(context:, solar_term:,
151
- direction: Operation::SolarTerm::Direction.new)
152
- operated_solar_term = solar_term.clone
153
- remainder_class_name = context.resolver.remainder
154
-
155
- unless direction.invalid_days?
156
- # 二十四節気の大余をずらす
157
- operated_solar_term.remainder.add!(
158
- remainder_class_name.new(day: direction.days, minute: 0, second: 0)
159
- )
160
- end
161
-
162
- operated_solar_term
163
- end
164
-
165
- #
166
- # 移動元に無効な二十四節気(連番のみ指定)を指定する
167
- #
168
- # @param [Context] context 暦コンテキスト
169
- # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
170
- # @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
171
- #
172
- def self.push_destination(context:, directions: {},
173
- destination: Operation::SolarTerm::Destination.new)
174
- return if destination.invalid?
175
-
176
- solar_term_class = context.resolver.solar_term
177
- directions[destination.from.format] = solar_term_class.new(
178
- index: destination.index
179
- )
180
- end
181
-
182
- private
183
-
184
- #
185
- # 日付に対応する暦コンテキストを取得する
186
- #
187
- # @param [Western::Calendar] western_date 西暦日
188
- #
189
- # @return [Context] 暦コンテキスト
190
- #
191
- def current_context(western_date: Western::Calendar.new)
192
- @years.each do |year|
193
- return year.context if western_date >= year.new_year_date
194
- end
195
-
196
- Context.new
197
- end
198
-
199
- #
200
- # 二十四節気の移動元/移動先を生成する
201
- #
202
- # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
203
- #
204
- def create_directions
205
- directions = {}
206
-
207
- years.each do |year|
208
- OperatedSolarTerms.create_directions_with_months(
209
- context: year.context, directions: directions, months: year.months
210
- )
211
- end
212
-
213
- directions
214
- end
215
- end
216
- end
217
- end
218
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './history'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- #
8
- # Result 演算結果
9
- #
10
- module Result
11
- #
12
- # 運用情報
13
- #
14
- module Operation
15
- #
16
- # Month 運用情報(月)
17
- #
18
- module Month
19
- #
20
- # Bundle 月履歴集約情報
21
- #
22
- class Bundle
23
- # @return [History] 月別履歴情報(当月)
24
- attr_reader :current
25
- # @return [History] 月別履歴情報(影響を与えた月)
26
- attr_reader :parent
27
-
28
- def initialize(current: History.new, parent: History.new)
29
- @current = current
30
- @parent = parent
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../data/single_day'
4
-
5
- require_relative './month/bundle'
6
-
7
- # :nodoc:
8
- module Zakuro
9
- #
10
- # Result 演算結果
11
- #
12
- module Result
13
- #
14
- # 運用情報
15
- #
16
- module Operation
17
- #
18
- # Bundle 運用情報
19
- #
20
- class Bundle
21
- # @return [True] 運用あり
22
- # @return [False] 運用なし
23
- attr_reader :operated
24
- # @return [Month::Bundle] 月別履歴情報
25
- attr_reader :month
26
- # @return [Data::SingleDay] 計算値
27
- attr_reader :original
28
-
29
- #
30
- # 初期化
31
- #
32
- # @param [True, False] operated 運用有無
33
- # @param [Month::Bundle] month 月別履歴情報
34
- # @param [Data::SingleDay] original 計算値
35
- #
36
- def initialize(operated:, month:, original:)
37
- @operated = operated
38
- @month = month
39
- @original = original
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './version_class_resolver'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- #
8
- # Context 暦コンテキスト
9
- #
10
- class Context
11
- # @return [String] 暦名
12
- attr_reader :version_name
13
- # @return [VersionClassResolver] 暦リゾルバー
14
- attr_reader :resolver
15
-
16
- # @return [Array<String>] 暦名
17
- VERSION_NAMES = %w[Genka Gihou Daien Senmyou Joukyou Kansei Tenpou Gregorio].freeze
18
-
19
- #
20
- # 初期化
21
- #
22
- # @param [String] version_name 暦名
23
- #
24
- def initialize(version_name: '')
25
- @version_name = version_name
26
-
27
- if !invalid? && !VERSION_NAMES.include?(version_name)
28
- raise ArgumentError.new, 'invalid version'
29
- end
30
-
31
- @resolver = VersionClassResolver.new(version_name: version_name)
32
- end
33
-
34
- #
35
- # 不正か
36
- #
37
- # @return [True] 不正
38
- # @return [False] 不正なし
39
- #
40
- def invalid?
41
- @version_name.empty?
42
- end
43
- end
44
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './genka/cycle/remainder'
4
- require_relative './genka/cycle/solar_term'
5
- require_relative './genka/range/annual_range'
6
-
7
- require_relative './gihou/cycle/remainder'
8
- require_relative './gihou/cycle/solar_term'
9
- require_relative './gihou/range/annual_range'
10
-
11
- require_relative './daien/cycle/remainder'
12
- require_relative './daien/cycle/solar_term'
13
- require_relative './daien/range/annual_range'
14
-
15
- require_relative './senmyou/cycle/remainder'
16
- require_relative './senmyou/cycle/solar_term'
17
- require_relative './senmyou/range/annual_range'
18
-
19
- # :nodoc:
20
- module Zakuro
21
- #
22
- # VersionClassResolver 暦リゾルバー
23
- #
24
- class VersionClassResolver
25
- attr_reader :version_name
26
-
27
- CLASSES = {
28
- 'remainder' => 'Zakuro::$VERSION::Cycle::Remainder',
29
- 'solar_term' => 'Zakuro::$VERSION::Cycle::SolarTerm',
30
- 'annual_range' => 'Zakuro::$VERSION::Range::AnnualRange'
31
- }.freeze
32
-
33
- def initialize(version_name:)
34
- @version_name = version_name
35
- end
36
-
37
- def self.get_class(version_name:, class_name:)
38
- constant = CLASSES.fetch(class_name, '')
39
-
40
- raise ArgumentError.new, 'invalid class name' if constant == ''
41
-
42
- resolved_constant = constant.gsub('$VERSION', version_name)
43
-
44
- Object.const_get(resolved_constant)
45
- end
46
-
47
- #
48
- # 大余小余(暦別)クラスを返す
49
- #
50
- # @return [Class] 大余小余(暦別)クラス
51
- #
52
- def remainder
53
- VersionClassResolver.get_class(version_name: @version_name, class_name: 'remainder')
54
- end
55
-
56
- #
57
- # 二十四節気クラスを返す
58
- #
59
- # @return [Class] 二十四節気クラス
60
- #
61
- def solar_term
62
- VersionClassResolver.get_class(version_name: @version_name, class_name: 'solar_term')
63
- end
64
-
65
- #
66
- # 年間範囲クラスを返す
67
- #
68
- # @return [Class] 年間範囲クラス
69
- #
70
- def annual_range
71
- VersionClassResolver.get_class(version_name: @version_name, class_name: 'annual_range')
72
- end
73
- end
74
- end