zakuro 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/VERSION +1 -1
  4. data/lib/zakuro/calculation/base/gengou.rb +5 -5
  5. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  6. data/lib/zakuro/calculation/base/operated_year.rb +23 -21
  7. data/lib/zakuro/calculation/base/year.rb +3 -3
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
  9. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  10. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  11. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
  12. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  13. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
  22. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  23. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  24. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  25. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  26. data/lib/zakuro/calculation/monthly/initialized_month.rb +39 -37
  27. data/lib/zakuro/calculation/monthly/month.rb +15 -15
  28. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  29. data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
  30. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  31. data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
  32. data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
  33. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  34. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  35. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  36. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  37. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  38. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  39. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  40. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +5 -5
  41. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  42. data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
  43. data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
  44. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  45. data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
  46. data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
  47. data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
  48. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
  49. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  50. data/lib/zakuro/calculation/summary/western/range.rb +95 -92
  51. data/lib/zakuro/calculation/summary/western/single.rb +78 -76
  52. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -124
  53. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
  54. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  55. data/lib/zakuro/condition.rb +121 -111
  56. data/lib/zakuro/context/context.rb +1 -1
  57. data/lib/zakuro/context/option.rb +31 -29
  58. data/lib/zakuro/context/version_class_resolver.rb +26 -24
  59. data/lib/zakuro/era/japan/calendar.rb +35 -33
  60. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -4
  61. data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
  62. data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
  63. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
  64. data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
  65. data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -36
  66. data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -37
  67. data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
  68. data/lib/zakuro/era/japan/gengou.rb +28 -26
  69. data/lib/zakuro/era/japan/version.rb +18 -16
  70. data/lib/zakuro/era/western/calendar.rb +102 -90
  71. data/lib/zakuro/exception/case/preset.rb +2 -2
  72. data/lib/zakuro/exception/exception.rb +15 -13
  73. data/lib/zakuro/exception/zakuro_error.rb +1 -1
  74. data/lib/zakuro/gateway/locale/date.rb +2 -2
  75. data/lib/zakuro/gateway/locale/range.rb +3 -3
  76. data/lib/zakuro/gateway/range.rb +1 -1
  77. data/lib/zakuro/gateway/single.rb +13 -2
  78. data/lib/zakuro/merchant.rb +1 -1
  79. data/lib/zakuro/operation/month/parser.rb +252 -251
  80. data/lib/zakuro/operation/month/type.rb +17 -8
  81. data/lib/zakuro/operation/month/validator.rb +148 -144
  82. data/lib/zakuro/operation/operation.rb +38 -36
  83. data/lib/zakuro/output/response.rb +112 -113
  84. data/lib/zakuro/result/operation/month/annotation.rb +2 -2
  85. data/lib/zakuro/result/operation/month/history.rb +2 -2
  86. data/lib/zakuro/result/operation/month.rb +31 -0
  87. data/lib/zakuro/result/operation.rb +39 -0
  88. data/lib/zakuro/result/result.rb +3 -3
  89. data/lib/zakuro/tools/stringifier.rb +66 -64
  90. data/lib/zakuro/tools/typeconv.rb +17 -15
  91. data/lib/zakuro/tools/typeof.rb +15 -13
  92. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  93. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  94. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
  95. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  96. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
  97. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  98. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  99. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  100. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  101. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  102. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  103. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  104. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  105. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  106. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  107. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  108. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  109. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  110. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  111. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
  112. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  113. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
  114. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  115. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  116. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  117. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  118. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  119. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  120. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  121. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  122. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  123. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
  124. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  125. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
  126. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  127. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  128. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  129. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  130. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  131. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  132. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  133. metadata +12 -9
  134. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
  135. data/lib/zakuro/result/operation/bundle.rb +0 -44
  136. data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -26,70 +26,72 @@ module Zakuro
26
26
  # @return [Output::Logger] ロガー
27
27
  LOGGER = Output::Logger.new(location: 'specifier')
28
28
 
29
- #
30
- # 取得する
31
- #
32
- # @param [Array<Calculation::Base::Year>] years 範囲
33
- # @param [Western::Calendar] date 西暦日
34
- #
35
- # @return [Result::Data::SingleDay] 和暦日
36
- #
37
- def self.get(years: [], date: Western::Calendar.new)
38
- year, month = specify(years: years, date: date)
39
-
40
- day = Day.get(month: month, date: date)
41
-
42
- options = Option.create(month: month, day: day)
43
-
44
- Output::Response::SingleDay.create(
45
- year: year, month: month, day: day, options: options
46
- )
47
- end
29
+ class << self
30
+ #
31
+ # 取得する
32
+ #
33
+ # @param [Array<Calculation::Base::Year>] years 範囲
34
+ # @param [Western::Calendar] date 西暦日
35
+ #
36
+ # @return [Result::Data::SingleDay] 和暦日
37
+ #
38
+ def get(years: [], date: Western::Calendar.new)
39
+ year, month = specify(years: years, date: date)
40
+
41
+ day = Day.get(month: month, date: date)
42
+
43
+ options = Option.create(month: month, day: day)
48
44
 
49
- #
50
- # 年を特定する
51
- #
52
- # @param [Array<Year>] years 範囲
53
- # @param [Western::Calendar] date 西暦日
54
- #
55
- # @return [Base::Year] 対象年
56
- # @return [Monthly::Month] 対象月
57
- #
58
- # @raise [ArgumentError] 引数エラー
59
- #
60
- def self.specify(years:, date:)
61
- years.each do |year|
62
- month = specify_month(year: year, date: date)
63
- return year, month unless month.invalid?
45
+ Output::Response::SingleDay.create(
46
+ year: year, month: month, day: day, options: options
47
+ )
64
48
  end
65
49
 
66
- raise ArgumentError, "invalid year range. date: #{date.format}"
67
- end
68
- private_class_method :specify
69
-
70
- # :reek:TooManyStatements { max_statements: 7 }
71
-
72
- #
73
- # 月を特定する
74
- #
75
- # @param [Base::Year] year 年
76
- # @param [Western::Calendar] date 西暦日
77
- #
78
- # @return [Monthly::Month] 対象月
79
- #
80
- def self.specify_month(year:, date:)
81
- months = year.months
82
-
83
- months.each do |month|
84
- western_date = month.western_date
85
- next if western_date.invalid?
86
-
87
- return month if month.include?(date: date)
50
+ private
51
+
52
+ #
53
+ # 年を特定する
54
+ #
55
+ # @param [Array<Year>] years 範囲
56
+ # @param [Western::Calendar] date 西暦日
57
+ #
58
+ # @return [Base::Year] 対象年
59
+ # @return [Monthly::Month] 対象月
60
+ #
61
+ # @raise [ArgumentError] 引数エラー
62
+ #
63
+ def specify(years:, date:)
64
+ years.each do |year|
65
+ month = specify_month(year: year, date: date)
66
+ return year, month unless month.invalid?
67
+ end
68
+
69
+ raise ArgumentError, "invalid year range. date: #{date.format}"
88
70
  end
89
71
 
90
- Monthly::Month.new
72
+ # :reek:TooManyStatements { max_statements: 7 }
73
+
74
+ #
75
+ # 月を特定する
76
+ #
77
+ # @param [Base::Year] year 年
78
+ # @param [Western::Calendar] date 西暦日
79
+ #
80
+ # @return [Monthly::Month] 対象月
81
+ #
82
+ def specify_month(year:, date:)
83
+ months = year.months
84
+
85
+ months.each do |month|
86
+ western_date = month.western_date
87
+ next if western_date.invalid?
88
+
89
+ return month if month.include?(date: date)
90
+ end
91
+
92
+ Monthly::Month.new
93
+ end
91
94
  end
92
- private_class_method :specify_month
93
95
  end
94
96
  end
95
97
  end
@@ -42,7 +42,7 @@ module Zakuro
42
42
  # @return [Float] 絶対値
43
43
  #
44
44
  def floor
45
- @abs.floor
45
+ abs.floor
46
46
  end
47
47
 
48
48
  #
@@ -51,7 +51,7 @@ module Zakuro
51
51
  # @return [Float] 符号つき浮動小数点数
52
52
  #
53
53
  def get
54
- @sign * @abs
54
+ sign * abs
55
55
  end
56
56
 
57
57
  #
@@ -26,26 +26,28 @@ module Zakuro
26
26
  @date = date
27
27
  end
28
28
 
29
- #
30
- # 検証する
31
- #
32
- # @param [Date] date 日付
33
- #
34
- # @return [Array<Exception::Case::Preset>] エラープリセット配列
35
- #
36
- def self.validate(date:)
37
- failed = []
38
- return failed unless date
29
+ class << self
30
+ #
31
+ # 検証する
32
+ #
33
+ # @param [Date] date 日付
34
+ #
35
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
36
+ #
37
+ def validate(date:)
38
+ failed = []
39
+ return failed unless date
40
+
41
+ return failed if date.is_a?(Date) || date.is_a?(String)
39
42
 
40
- return failed if date.is_a?(Date) || date.is_a?(String)
41
-
42
- failed.push(
43
- Exception::Case::Preset.new(
44
- date.class,
45
- template: Exception::Case::Pattern::INVALID_DATE_TYPE
43
+ failed.push(
44
+ Exception::Case::Preset.new(
45
+ date.class,
46
+ template: Exception::Case::Pattern::INVALID_DATE_TYPE
47
+ )
46
48
  )
47
- )
48
- failed
49
+ failed
50
+ end
49
51
  end
50
52
  end
51
53
 
@@ -72,31 +74,33 @@ module Zakuro
72
74
 
73
75
  # :reek:TooManyStatements { max_statements: 7 }
74
76
 
75
- #
76
- # 検証する
77
- #
78
- # @param [Hash<Symbol, Object>] hash パラメータ
79
- #
80
- # @return [Array<Exception::Case::Preset>] エラープリセット
81
- #
82
- def self.validate(hash:)
83
- failed = []
84
- return failed unless hash
85
-
86
- unless hash.is_a?(Hash)
87
- failed.push(
88
- Exception::Case::Preset.new(
89
- hash.class,
90
- template: Exception::Case::Pattern::INVALID_RANGE_TYPE
77
+ class << self
78
+ #
79
+ # 検証する
80
+ #
81
+ # @param [Hash<Symbol, Object>] hash パラメータ
82
+ #
83
+ # @return [Array<Exception::Case::Preset>] エラープリセット
84
+ #
85
+ def validate(hash:)
86
+ failed = []
87
+ return failed unless hash
88
+
89
+ unless hash.is_a?(Hash)
90
+ failed.push(
91
+ Exception::Case::Preset.new(
92
+ hash.class,
93
+ template: Exception::Case::Pattern::INVALID_RANGE_TYPE
94
+ )
91
95
  )
92
- )
93
- return failed
94
- end
96
+ return failed
97
+ end
95
98
 
96
- failed.concat(BasisDate.validate(date: hash[:start]))
97
- failed.concat(BasisDate.validate(date: hash[:last]))
99
+ failed.concat(BasisDate.validate(date: hash[:start]))
100
+ failed.concat(BasisDate.validate(date: hash[:last]))
98
101
 
99
- failed
102
+ failed
103
+ end
100
104
  end
101
105
 
102
106
  #
@@ -131,29 +135,31 @@ module Zakuro
131
135
  @columns = columns
132
136
  end
133
137
 
134
- #
135
- # 検証する
136
- #
137
- # @param [Array<String>] columns 列
138
- #
139
- # @return [Array<Exception::Case::Preset>] エラープリセット配列
140
- #
141
- def self.validate(columns:)
142
- # TODO: 列内容のバリデーション
143
- failed = []
138
+ class << self
139
+ #
140
+ # 検証する
141
+ #
142
+ # @param [Array<String>] columns 列
143
+ #
144
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
145
+ #
146
+ def validate(columns:)
147
+ # TODO: 列内容のバリデーション
148
+ failed = []
144
149
 
145
- return failed unless columns
150
+ return failed unless columns
146
151
 
147
- return failed if columns.is_a?(Array)
152
+ return failed if columns.is_a?(Array)
148
153
 
149
- failed.push(
150
- Exception::Case::Preset.new(
151
- hash.class,
152
- template: Exception::Case::Pattern::INVALID_COLUMN_TYPE
154
+ failed.push(
155
+ Exception::Case::Preset.new(
156
+ hash.class,
157
+ template: Exception::Case::Pattern::INVALID_COLUMN_TYPE
158
+ )
153
159
  )
154
- )
155
160
 
156
- failed
161
+ failed
162
+ end
157
163
  end
158
164
  end
159
165
 
@@ -180,26 +186,28 @@ module Zakuro
180
186
 
181
187
  # TODO: オプションキーのバリデーション
182
188
 
183
- #
184
- # 検証する
185
- #
186
- # @param [Hash<Symbol, Object>] options オプション
187
- #
188
- # @return [Array<Exception::Case::Preset>] エラープリセット配列
189
- #
190
- def self.validate(options:)
191
- failed = []
192
- return failed unless options
189
+ class << self
190
+ #
191
+ # 検証する
192
+ #
193
+ # @param [Hash<Symbol, Object>] options オプション
194
+ #
195
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
196
+ #
197
+ def validate(options:)
198
+ failed = []
199
+ return failed unless options
193
200
 
194
- return failed if options.is_a?(Hash)
201
+ return failed if options.is_a?(Hash)
195
202
 
196
- failed.push(
197
- Exception::Case::Preset.new(
198
- hash.class,
199
- template: Exception::Case::Pattern::INVALID_OPTION_TYPE
203
+ failed.push(
204
+ Exception::Case::Preset.new(
205
+ hash.class,
206
+ template: Exception::Case::Pattern::INVALID_OPTION_TYPE
207
+ )
200
208
  )
201
- )
202
- failed
209
+ failed
210
+ end
203
211
  end
204
212
  end
205
213
  end
@@ -235,46 +243,48 @@ module Zakuro
235
243
 
236
244
  # :reek:TooManyStatements { max_statements: 8 }
237
245
 
238
- #
239
- # 検証する
240
- #
241
- # @param [Hash<Symbol, Object>] hash パラメータ
242
- #
243
- # @return [Array<Exception::Case::Preset>] エラープリセット配列
244
- #
245
- def self.validate(hash:)
246
- failed = []
247
-
248
- unless hash.is_a?(Hash)
249
- failed.push(
250
- Exception::Case::Preset.new(
251
- hash.class,
252
- template: Exception::Case::Pattern::INVALID_CONDITION_TYPE
246
+ class << self
247
+ #
248
+ # 検証する
249
+ #
250
+ # @param [Hash<Symbol, Object>] hash パラメータ
251
+ #
252
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
253
+ #
254
+ def validate(hash:)
255
+ failed = []
256
+
257
+ unless hash.is_a?(Hash)
258
+ failed.push(
259
+ Exception::Case::Preset.new(
260
+ hash.class,
261
+ template: Exception::Case::Pattern::INVALID_CONDITION_TYPE
262
+ )
253
263
  )
254
- )
255
- return failed
256
- end
264
+ return failed
265
+ end
257
266
 
258
- failed.concat(validate_hash(hash: hash))
267
+ failed.concat(validate_hash(hash: hash))
259
268
 
260
- failed
261
- end
269
+ failed
270
+ end
262
271
 
263
- #
264
- # ハッシュ内を検証する
265
- #
266
- # @param [Hash<Symbol, Object>] hash パラメータ
267
- #
268
- # @return [Array<Exception::Case::Preset>] エラープリセット配列
269
- #
270
- def self.validate_hash(hash:)
271
- failed = []
272
- failed.concat(Catalog::BasisDate.validate(date: hash[:date]))
273
- failed.concat(Catalog::Range.validate(hash: hash[:range]))
274
- failed.concat(Catalog::Columns.validate(columns: hash[:columns]))
275
- failed.concat(Catalog::Options.validate(options: hash[:options]))
276
-
277
- failed
272
+ #
273
+ # ハッシュ内を検証する
274
+ #
275
+ # @param [Hash<Symbol, Object>] hash パラメータ
276
+ #
277
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
278
+ #
279
+ def validate_hash(hash:)
280
+ failed = []
281
+ failed.concat(Catalog::BasisDate.validate(date: hash[:date]))
282
+ failed.concat(Catalog::Range.validate(hash: hash[:range]))
283
+ failed.concat(Catalog::Columns.validate(columns: hash[:columns]))
284
+ failed.concat(Catalog::Options.validate(options: hash[:options]))
285
+
286
+ failed
287
+ end
278
288
  end
279
289
 
280
290
  #
@@ -37,7 +37,7 @@ module Zakuro
37
37
  # @return [False] 不正なし
38
38
  #
39
39
  def invalid?
40
- !@option.version?
40
+ !option.version?
41
41
  end
42
42
  end
43
43
  end
@@ -82,35 +82,37 @@ module Zakuro
82
82
  false
83
83
  end
84
84
 
85
- #
86
- # 暦名を返す
87
- #
88
- # @param [String] version 暦名
89
- #
90
- # @return [String] 暦名
91
- #
92
- def self.version(version: INVALID_VERSION_NAME)
93
- return INVALID_VERSION_NAME unless version
94
-
95
- return INVALID_VERSION_NAME if version.empty?
96
-
97
- return INVALID_VERSION_NAME unless VERSION_NAMES.include?(version)
98
-
99
- version
100
- end
101
-
102
- #
103
- # 有効な暦か
104
- #
105
- # @param [String] version 暦名
106
- #
107
- # @return [True] 有効
108
- # @return [False] 無効
109
- #
110
- def self.version?(version: INVALID_VERSION_NAME)
111
- return false if version == INVALID_VERSION_NAME
112
-
113
- true
85
+ class << self
86
+ #
87
+ # 暦名を返す
88
+ #
89
+ # @param [String] version 暦名
90
+ #
91
+ # @return [String] 暦名
92
+ #
93
+ def version(version: INVALID_VERSION_NAME)
94
+ return INVALID_VERSION_NAME unless version
95
+
96
+ return INVALID_VERSION_NAME if version.empty?
97
+
98
+ return INVALID_VERSION_NAME unless VERSION_NAMES.include?(version)
99
+
100
+ version
101
+ end
102
+
103
+ #
104
+ # 有効な暦か
105
+ #
106
+ # @param [String] version 暦名
107
+ #
108
+ # @return [True] 有効
109
+ # @return [False] 無効
110
+ #
111
+ def version?(version: INVALID_VERSION_NAME)
112
+ return false if version == INVALID_VERSION_NAME
113
+
114
+ true
115
+ end
114
116
  end
115
117
  end
116
118
  end
@@ -48,33 +48,13 @@ module Zakuro
48
48
  @version_name = version_name
49
49
  end
50
50
 
51
- #
52
- # 該当の暦のクラスを取得する
53
- #
54
- # @param [String] version_name 暦名
55
- # @param [String] class_name クラス名
56
- #
57
- # @return [Object] 該当クラス
58
- #
59
- # @raise [ArgumentError] 引数エラー
60
- #
61
- def self.get_class(version_name:, class_name:)
62
- constant = CLASSES.fetch(class_name, '')
63
-
64
- raise ArgumentError.new, 'invalid class name' if constant == ''
65
-
66
- resolved_constant = constant.gsub('$VERSION', version_name)
67
-
68
- Object.const_get(resolved_constant)
69
- end
70
-
71
51
  #
72
52
  # 大余小余(暦別)クラスを返す
73
53
  #
74
54
  # @return [Class] 大余小余(暦別)クラス
75
55
  #
76
56
  def remainder
77
- VersionClassResolver.get_class(version_name: @version_name, class_name: 'remainder')
57
+ self.class.get_class(version_name: @version_name, class_name: 'remainder')
78
58
  end
79
59
 
80
60
  #
@@ -83,7 +63,7 @@ module Zakuro
83
63
  # @return [Class] 二十四節気クラス
84
64
  #
85
65
  def solar_term
86
- VersionClassResolver.get_class(version_name: @version_name, class_name: 'solar_term')
66
+ self.class.get_class(version_name: @version_name, class_name: 'solar_term')
87
67
  end
88
68
 
89
69
  #
@@ -92,7 +72,7 @@ module Zakuro
92
72
  # @return [Class] 年間範囲クラス
93
73
  #
94
74
  def annual_range
95
- VersionClassResolver.get_class(version_name: @version_name, class_name: 'annual_range')
75
+ self.class.get_class(version_name: @version_name, class_name: 'annual_range')
96
76
  end
97
77
 
98
78
  #
@@ -101,10 +81,32 @@ module Zakuro
101
81
  # @return [Class] 没日引数クラス
102
82
  #
103
83
  def dropped_date_parameter
104
- VersionClassResolver.get_class(
84
+ self.class.get_class(
105
85
  version_name: @version_name, class_name: 'dropped_date_parameter'
106
86
  )
107
87
  end
88
+
89
+ class << self
90
+ #
91
+ # 該当の暦のクラスを取得する
92
+ #
93
+ # @param [String] version_name 暦名
94
+ # @param [String] class_name クラス名
95
+ #
96
+ # @return [Object] 該当クラス
97
+ #
98
+ # @raise [ArgumentError] 引数エラー
99
+ #
100
+ def get_class(version_name:, class_name:)
101
+ constant = CLASSES.fetch(class_name, '')
102
+
103
+ raise ArgumentError.new, 'invalid class name' if constant == ''
104
+
105
+ resolved_constant = constant.gsub('$VERSION', version_name)
106
+
107
+ Object.const_get(resolved_constant)
108
+ end
109
+ end
108
110
  end
109
111
  end
110
112
  end
@@ -88,45 +88,47 @@ module Zakuro
88
88
  @month == month
89
89
  end
90
90
 
91
- #
92
- # 年月日情報(和暦)を生成する
93
- #
94
- # @param [Regexp] regex 正規表現
95
- # @param [String] text 和暦日文字列
96
- #
97
- # @return [Calendar] 年月日情報(和暦)
98
- #
99
- def self.parse(regex: FORMAT, text: '')
100
- return Calendar.new unless valid_date_string(regex: regex, text: text)
91
+ class << self
92
+ #
93
+ # 年月日情報(和暦)を生成する
94
+ #
95
+ # @param [Regexp] regex 正規表現
96
+ # @param [String] text 和暦日文字列
97
+ #
98
+ # @return [Calendar] 年月日情報(和暦)
99
+ #
100
+ def parse(regex: FORMAT, text: '')
101
+ return Calendar.new unless valid_date_string(regex: regex, text: text)
101
102
 
102
- matched = text.match(regex)
103
+ matched = text.match(regex)
103
104
 
104
- Calendar.new(
105
- gengou: matched[1],
106
- year: Tools::Typeconv.to_i(text: matched[2], default: INVALID),
107
- leaped: matched[3] ? true : false,
108
- month: Tools::Typeconv.to_i(text: matched[4], default: INVALID),
109
- day: Tools::Typeconv.to_i(text: matched[5], default: INVALID)
110
- )
111
- end
105
+ Calendar.new(
106
+ gengou: matched[1],
107
+ year: Tools::Typeconv.to_i(text: matched[2], default: INVALID),
108
+ leaped: matched[3] ? true : false,
109
+ month: Tools::Typeconv.to_i(text: matched[4], default: INVALID),
110
+ day: Tools::Typeconv.to_i(text: matched[5], default: INVALID)
111
+ )
112
+ end
112
113
 
113
- #
114
- # 日付文字列を検証する
115
- #
116
- # @param [Regexp] regex 正規表現
117
- # @param [String] text 和暦日文字列
118
- #
119
- # @return [True] 正しい
120
- # @return [True] 正しくない
121
- #
122
- def self.valid_date_string(regex: FORMAT, text: '')
123
- return false unless text
114
+ #
115
+ # 日付文字列を検証する
116
+ #
117
+ # @param [Regexp] regex 正規表現
118
+ # @param [String] text 和暦日文字列
119
+ #
120
+ # @return [True] 正しい
121
+ # @return [True] 正しくない
122
+ #
123
+ def valid_date_string(regex: FORMAT, text: '')
124
+ return false unless text
124
125
 
125
- matched = text.match(regex)
126
+ matched = text.match(regex)
126
127
 
127
- return false unless matched
128
+ return false unless matched
128
129
 
129
- matched.size == 6
130
+ matched.size == 6
131
+ end
130
132
  end
131
133
  end
132
134
  end