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
@@ -4,7 +4,7 @@ require_relative '../cycle/zodiac'
4
4
 
5
5
  require_relative '../../era/western/calendar'
6
6
 
7
- require_relative '../../version/context'
7
+ require_relative '../../context/context'
8
8
 
9
9
  # :nodoc:
10
10
  module Zakuro
@@ -16,7 +16,7 @@ module Zakuro
16
16
  # Year 年
17
17
  #
18
18
  class Year
19
- # @return [Context] 暦コンテキスト
19
+ # @return [Context::Context] 暦コンテキスト
20
20
  attr_reader :context
21
21
  # @return [Array<Month>] 年内の全ての月
22
22
  attr_reader :months
@@ -26,11 +26,11 @@ module Zakuro
26
26
  #
27
27
  # 初期化
28
28
  #
29
- # @param [Context] context 暦コンテキスト
29
+ # @param [Context::Context] context 暦コンテキスト
30
30
  # @param [Array<Month>] months 年内の全ての月
31
31
  # @param [Integer] total_days 年の日数
32
32
  #
33
- def initialize(context: Context.new, months: [], total_days: 0)
33
+ def initialize(context: Context::Context.new, months: [], total_days: 0)
34
34
  @context = context
35
35
  @months = months
36
36
  @total_days = total_days
@@ -72,7 +72,7 @@ module Zakuro
72
72
 
73
73
  return Western::Calendar.new if months.size.zero?
74
74
 
75
- @months[0].western_date
75
+ months[0].western_date
76
76
  end
77
77
 
78
78
  #
@@ -95,7 +95,7 @@ module Zakuro
95
95
  def push(month:)
96
96
  return if duplicated?(month: month)
97
97
 
98
- @months.push(month)
98
+ months.push(month)
99
99
 
100
100
  nil
101
101
  end
@@ -111,7 +111,7 @@ module Zakuro
111
111
  # @return [True] 重複していない
112
112
  #
113
113
  def duplicated?(month:)
114
- @months.each do |existed|
114
+ months.each do |existed|
115
115
  return true if existed.same?(other: month)
116
116
  end
117
117
  false
@@ -43,16 +43,16 @@ module Zakuro
43
43
  # 初期化
44
44
  #
45
45
  # @param [Integer] base_day 1大余に必要な小余(暦によって基数が異なる)
46
- # @param [Integer] base_mitune 1小余に必要な秒(暦によって基数が異なる)
46
+ # @param [Integer] base_minute 1小余に必要な秒(暦によって基数が異なる)
47
47
  # @param [Integer] day 大余("日"に相当)
48
48
  # @param [Integer] minute 小余("分"に相当)
49
49
  # @param [Integer] second 秒
50
50
  # @param [Integer] total 繰り上げなしの小余
51
51
  #
52
- def initialize(base_day: -1, base_mitune: -1, day: -1, minute: -1, second: -1, total: -1)
52
+ def initialize(base_day: -1, base_minute: -1, day: -1, minute: -1, second: -1, total: -1)
53
53
  @base_limit = LIMIT
54
54
  @base_day = base_day
55
- @base_minute = base_mitune
55
+ @base_minute = base_minute
56
56
  @limited = true
57
57
 
58
58
  set(day: day, minute: minute, second: second, total: total)
@@ -75,8 +75,8 @@ module Zakuro
75
75
  @second = second
76
76
 
77
77
  if total != -1
78
- @day = (total.to_f / @base_day).floor
79
- @minute = (total % @base_day)
78
+ @day = (total.to_f / base_day).floor
79
+ @minute = (total % base_day)
80
80
  @second = 0
81
81
  end
82
82
 
@@ -113,6 +113,8 @@ module Zakuro
113
113
  # @return [True] 無効
114
114
  # @return [False] 有効
115
115
  #
116
+ # @raise [ArgumentError] 引数エラー
117
+ #
116
118
  def invalid?(param: self)
117
119
  raise ArgumentError, 'unmatch parameter type' unless param.is_a?(AbstractRemainder)
118
120
 
@@ -125,7 +127,7 @@ module Zakuro
125
127
  # @return [String] 十干十二支名
126
128
  #
127
129
  def zodiac_name
128
- Cycle::Zodiac.day_name(day: @day)
130
+ Cycle::Zodiac.day_name(day: day)
129
131
  end
130
132
 
131
133
  #
@@ -137,9 +139,9 @@ module Zakuro
137
139
  # @return [False] 当月朔日と翌月朔日が異なる十干(「小」の月)
138
140
  #
139
141
  def same_remainder_divided_by_ten?(other:)
140
- day = @day % LIMIT
142
+ remainder_day = day % LIMIT
141
143
 
142
- (day % 10) == (other % 10)
144
+ (remainder_day % 10) == (other % 10)
143
145
  end
144
146
 
145
147
  #
@@ -151,12 +153,14 @@ module Zakuro
151
153
  #
152
154
  def add(other)
153
155
  invalid?(param: other)
154
- day = @day + other.day
155
- minute = @minute + other.minute
156
- second = @second + other.second
157
- day, minute, second = carry(day, minute, second)
156
+ sum_day = day + other.day
157
+ sum_minute = minute + other.minute
158
+ sum_second = second + other.second
159
+ sum_day, sum_minute, sum_second = carry(
160
+ sum_day, sum_minute, sum_second
161
+ )
158
162
 
159
- clone.set(day: day, minute: minute, second: second)
163
+ clone.set(day: sum_day, minute: sum_minute, second: sum_second)
160
164
  end
161
165
 
162
166
  #
@@ -184,12 +188,14 @@ module Zakuro
184
188
  #
185
189
  def sub(other)
186
190
  invalid?(param: other)
187
- day = @day - other.day
188
- minute = @minute - other.minute
189
- second = @second - other.second
190
- day, minute, second = carry(day, minute, second)
191
+ sum_day = day - other.day
192
+ sum_minute = minute - other.minute
193
+ sum_second = second - other.second
194
+ sum_day, sum_minute, sum_second = carry(
195
+ sum_day, sum_minute, sum_second
196
+ )
191
197
 
192
- clone.set(day: day, minute: minute, second: second)
198
+ clone.set(day: sum_day, minute: sum_minute, second: sum_second)
193
199
  end
194
200
 
195
201
  #
@@ -298,9 +304,9 @@ module Zakuro
298
304
  def up_on_new_moon
299
305
  cloned = clone
300
306
  limit = (base_day * 3) / 4
301
- if @minute >= limit
302
- day, minute, second = carry((@day + 1), @minute, @second)
303
- return cloned.set(day: day, minute: minute, second: second)
307
+ if minute >= limit
308
+ sum_day, sum_minute, sum_second = carry((day + 1), minute, second)
309
+ return cloned.set(day: sum_day, minute: sum_minute, second: sum_second)
304
310
  end
305
311
 
306
312
  cloned
@@ -331,7 +337,7 @@ module Zakuro
331
337
  # @return [Integer] 小余
332
338
  #
333
339
  def to_minute
334
- @day * @base_day + @minute
340
+ day * base_day + minute
335
341
  end
336
342
 
337
343
  #
@@ -352,7 +358,7 @@ module Zakuro
352
358
  # @return [Float] 小余
353
359
  #
354
360
  def float_minute
355
- @minute + @second.to_f / @base_minute
361
+ minute + second.to_f / base_minute
356
362
  end
357
363
 
358
364
  #
@@ -361,10 +367,10 @@ module Zakuro
361
367
  # @return [AbstractRemainder] 大余
362
368
  #
363
369
  def round
364
- day = @day
365
- day += 1 if @minute >= (@base_day / 2)
370
+ sum_day = day
371
+ sum_day += 1 if minute >= (base_day / 2)
366
372
 
367
- initialize(day, 0, 0)
373
+ initialize(sum_day, 0, 0)
368
374
  end
369
375
 
370
376
  #
@@ -373,7 +379,7 @@ module Zakuro
373
379
  # @return [String] 文字化
374
380
  #
375
381
  def to_s
376
- "大余(日): #{@day}, 小余(分): #{@minute}, 小余(秒): #{@second}"
382
+ "大余(日): #{day}, 小余(分): #{minute}, 小余(秒): #{second}"
377
383
  end
378
384
 
379
385
  #
@@ -382,7 +388,7 @@ module Zakuro
382
388
  # @return [AbstractRemainder] 繰り上げ結果
383
389
  #
384
390
  def carry!
385
- @day, @minute, @second = carry(@day, @minute, @second)
391
+ @day, @minute, @second = carry(day, minute, second)
386
392
 
387
393
  self
388
394
  end
@@ -404,11 +410,11 @@ module Zakuro
404
410
  def carry_second(param_minute, param_second)
405
411
  sign = param_second.negative? ? -1 : 1
406
412
  abs = sign * param_second
407
- minute = param_minute + (sign * (abs / @base_minute).floor)
408
- second = sign * (abs % @base_minute)
413
+ minute = param_minute + (sign * (abs / base_minute).floor)
414
+ second = sign * (abs % base_minute)
409
415
 
410
416
  if sign.negative?
411
- second += @base_minute
417
+ second += base_minute
412
418
  minute -= 1
413
419
  end
414
420
 
@@ -419,11 +425,11 @@ module Zakuro
419
425
  sign = param_minute.negative? ? -1 : 1
420
426
  abs = sign * param_minute
421
427
 
422
- day = param_day + (sign * (abs / @base_day).floor)
423
- minute = sign * (abs % @base_day)
428
+ day = param_day + (sign * (abs / base_day).floor)
429
+ minute = sign * (abs % base_day)
424
430
 
425
431
  if sign.negative?
426
- minute += @base_day
432
+ minute += base_day
427
433
  day -= 1
428
434
  end
429
435
 
@@ -433,37 +439,39 @@ module Zakuro
433
439
  def carry_day(day, limited)
434
440
  sign = day.negative? ? -1 : 1
435
441
  abs = sign * day
436
- carried = sign * (abs % @base_limit) if limited
437
- carried += @base_limit if sign.negative?
442
+ carried = sign * (abs % base_limit) if limited
443
+ carried += base_limit if sign.negative?
438
444
  carried
439
445
  end
440
446
 
441
447
  def up?(other)
442
448
  invalid?(param: other)
443
- day = other.day
444
- minute = other.float_minute
449
+ other_day = other.day
450
+ other_minute = other.float_minute
451
+
452
+ return true if day > other_day
445
453
 
446
- return true if @day > day
447
- return false if @day < day
454
+ return false if day < other_day
448
455
 
449
- float_minute > minute
456
+ float_minute > other_minute
450
457
  end
451
458
 
452
459
  def eql?(other)
453
460
  invalid?(param: other)
454
461
 
455
- (@day == other.day && float_minute == other.float_minute)
462
+ (day == other.day && float_minute == other.float_minute)
456
463
  end
457
464
 
458
465
  def down?(other)
459
466
  invalid?(param: other)
460
- day = other.day
461
- minute = other.float_minute
467
+ other_day = other.day
468
+ other_minute = other.float_minute
469
+
470
+ return true if day < other_day
462
471
 
463
- return true if @day < day
464
- return false if @day > day
472
+ return false if day > other_day
465
473
 
466
- float_minute < minute
474
+ float_minute < other_minute
467
475
  end
468
476
  end
469
477
  end
@@ -67,7 +67,7 @@ module Zakuro
67
67
  # @return [False] 正しい
68
68
  #
69
69
  def invalid?
70
- (@index == -1 || @remainder.invalid?)
70
+ (index == -1 || remainder.invalid?)
71
71
  end
72
72
 
73
73
  #
@@ -77,21 +77,7 @@ module Zakuro
77
77
  # @return [False] データあり
78
78
  #
79
79
  def empty?
80
- (@index == -1 && @remainder.invalid?)
81
- end
82
-
83
- #
84
- # 有効な二十四節気番号か
85
- #
86
- # @param [Integer] index 連番
87
- #
88
- # @return [True] 有効
89
- # @return [False] 無効
90
- #
91
- def self.index?(index)
92
- result = ORDER.fetch(index, -1)
93
-
94
- result != -1
80
+ (index == -1 && remainder.invalid?)
95
81
  end
96
82
 
97
83
  #
@@ -106,9 +92,9 @@ module Zakuro
106
92
  #
107
93
  def next_term
108
94
  @index += 1
109
- @index = 0 if @index >= ORDER.size
95
+ @index = 0 if index >= ORDER.size
110
96
 
111
- @remainder.add(@average)
97
+ remainder.add(average)
112
98
  end
113
99
 
114
100
  #
@@ -119,8 +105,9 @@ module Zakuro
119
105
  def next_by_index(index)
120
106
  return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index)
121
107
 
122
- loop do
123
- return if @index == index
108
+ (0..(ORDER.size - 1)).each do |_index|
109
+ inner_index = @index
110
+ break if inner_index == index
124
111
 
125
112
  next!
126
113
  end
@@ -134,8 +121,9 @@ module Zakuro
134
121
  def prev_by_index(index)
135
122
  return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index)
136
123
 
137
- loop do
138
- return if @index == index
124
+ (0..(ORDER.size - 1)).each do |_index|
125
+ inner_index = @index
126
+ break if inner_index == index
139
127
 
140
128
  prev_term!
141
129
  end
@@ -153,9 +141,9 @@ module Zakuro
153
141
  #
154
142
  def prev_term
155
143
  @index -= 1
156
- @index = 23 if @index.negative?
144
+ @index = 23 if index.negative?
157
145
 
158
- @remainder.sub(@average)
146
+ remainder.sub(average)
159
147
  end
160
148
 
161
149
  #
@@ -167,6 +155,22 @@ module Zakuro
167
155
  @index = obj.index.clone
168
156
  @remainder = obj.remainder.clone
169
157
  end
158
+
159
+ class << self
160
+ #
161
+ # 有効な二十四節気番号か
162
+ #
163
+ # @param [Integer] index 連番
164
+ #
165
+ # @return [True] 有効
166
+ # @return [False] 無効
167
+ #
168
+ def index?(index)
169
+ result = ORDER.fetch(index, -1)
170
+
171
+ result != -1
172
+ end
173
+ end
170
174
  end
171
175
  end
172
176
  end
@@ -77,28 +77,30 @@ module Zakuro
77
77
  # @return [Integer] 組み合わせ数
78
78
  LENGTH = ZODIAC_NAME_PATTERNS.length
79
79
 
80
- #
81
- # 大余を十干十二支に変換する
82
- #
83
- # @param [Integer] day 大余
84
- #
85
- # @return [String] 十干十二支
86
- #
87
- def self.day_name(day:)
88
- index = day % LENGTH
80
+ class << self
81
+ #
82
+ # 大余を十干十二支に変換する
83
+ #
84
+ # @param [Integer] day 大余
85
+ #
86
+ # @return [String] 十干十二支
87
+ #
88
+ def day_name(day:)
89
+ index = day % LENGTH
89
90
 
90
- ZODIAC_NAME_PATTERNS[index]
91
- end
91
+ ZODIAC_NAME_PATTERNS[index]
92
+ end
92
93
 
93
- #
94
- # 西暦年を十干十二支に変換する
95
- #
96
- # @param [Integer] western_year 西暦年
97
- #
98
- # @return [String] 十干十二支
99
- #
100
- def self.year_name(western_year: 0)
101
- ZODIAC_NAME_PATTERNS[(western_year - 4) % LENGTH]
94
+ #
95
+ # 西暦年を十干十二支に変換する
96
+ #
97
+ # @param [Integer] western_year 西暦年
98
+ #
99
+ # @return [String] 十干十二支
100
+ #
101
+ def year_name(western_year: 0)
102
+ ZODIAC_NAME_PATTERNS[(western_year - 4) % LENGTH]
103
+ end
102
104
  end
103
105
  end
104
106
  end
@@ -3,7 +3,6 @@
3
3
  require_relative '../../../era/western/calendar'
4
4
  require_relative '../../base/gengou'
5
5
  require_relative '../../base/linear_gengou'
6
- require_relative './internal/reserve/range'
7
6
  require_relative './internal/connector'
8
7
  require_relative './internal/publisher'
9
8
 
@@ -13,16 +12,16 @@ module Zakuro
13
12
  module Calculation
14
13
  # :nodoc:
15
14
  module Gengou
16
- # Scroll
15
+ # AbstractScroll
17
16
  #
18
17
  # 元号スクロール
19
18
  #
20
- class Scroll
19
+ class AbstractScroll
21
20
  # @return [Western::Calendar] 月初日
22
21
  attr_reader :monthly_start_date
23
22
  # @return [Western::Calendar] 月末日
24
23
  attr_reader :monthly_last_date
25
- # @return [Reserve::Range] 予約範囲
24
+ # @return [Reserve::AbstractRange] 予約範囲
26
25
  attr_reader :range
27
26
  # @return [Array<Counte>] 1行目元号
28
27
  attr_reader :first_gengou
@@ -34,13 +33,12 @@ module Zakuro
34
33
  #
35
34
  # 初期化
36
35
  #
37
- # @param [Western::Calendar] start_date 西暦開始日(最大範囲)
38
- # @param [Western::Calendar] last_date 西暦終了日(最大範囲)
36
+ # @param [Reserve::AbstractRange] range 予約範囲
39
37
  #
40
- def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
38
+ def initialize(range:)
41
39
  @monthly_start_date = Western::Calendar.new
42
40
  @monthly_last_date = Western::Calendar.new
43
- @range = Reserve::Range.new(start_date: start_date, last_date: last_date)
41
+ @range = range
44
42
  @first_gengou = []
45
43
  @second_gengou = []
46
44
  @ignited = false
@@ -74,15 +72,7 @@ module Zakuro
74
72
  def ignite(month:)
75
73
  return false unless ignitable?(month: month)
76
74
 
77
- japan_start_date = @range.japan_start_date
78
-
79
- western_start_date = @range.western_start_date
80
-
81
- # 今月初日(和暦日が1月2日であれば、開始日の1日前が初日)
82
- @monthly_start_date = western_start_date.clone - japan_start_date.day + 1
83
-
84
- # 今月末
85
- @monthly_last_date = @monthly_start_date.clone + month.days - 1
75
+ first_monthly_date(month: month)
86
76
 
87
77
  update_current_gengou
88
78
 
@@ -95,9 +85,9 @@ module Zakuro
95
85
  # @param [Monthly::Month] month 月
96
86
  #
97
87
  def advance(month:)
98
- @monthly_start_date = @monthly_last_date.clone + 1
88
+ @monthly_start_date = monthly_last_date.clone + 1
99
89
 
100
- @monthly_last_date = @monthly_start_date.clone + month.days - 1
90
+ @monthly_last_date = monthly_start_date.clone + month.days - 1
101
91
 
102
92
  next_year if month.number == 1 && !month.leaped?
103
93
 
@@ -110,15 +100,15 @@ module Zakuro
110
100
  # @return [Base::Gengou] 元号
111
101
  #
112
102
  def to_gengou
113
- start_date = @monthly_start_date.clone
114
- last_date = @monthly_last_date.clone
103
+ start_date = monthly_start_date.clone
104
+ last_date = monthly_last_date.clone
115
105
 
116
106
  # 行を超えた元号切り替え処理
117
107
  continue_year
118
108
 
119
109
  Publisher.run(
120
110
  start_date: start_date, last_date: last_date,
121
- first_gengou: @first_gengou, second_gengou: @second_gengou
111
+ first_gengou: first_gengou, second_gengou: second_gengou
122
112
  )
123
113
  end
124
114
 
@@ -128,7 +118,7 @@ module Zakuro
128
118
  # @return [Integer] 開始西暦年
129
119
  #
130
120
  def western_start_year
131
- @range.western_start_year
121
+ range.western_start_year
132
122
  end
133
123
 
134
124
  #
@@ -137,30 +127,47 @@ module Zakuro
137
127
  # @return [Integer] 終了西暦年
138
128
  #
139
129
  def western_last_year
140
- @range.western_last_year
130
+ range.western_last_year
141
131
  end
142
132
 
143
133
  private
144
134
 
135
+ #
136
+ # 最初の月初日/末日を設定する
137
+ #
138
+ # @param [Monthly::Month] month 月
139
+ #
140
+ def first_monthly_date(month:)
141
+ japan_start_date = range.japan_start_date
142
+
143
+ western_start_date = range.western_start_date
144
+
145
+ # 今月初日(和暦日が1月2日であれば、開始日の1日前が初日)
146
+ @monthly_start_date = western_start_date.clone - japan_start_date.day + 1
147
+
148
+ # 今月末
149
+ @monthly_last_date = monthly_start_date.clone + month.days - 1
150
+ end
151
+
145
152
  #
146
153
  # 行を跨ぐ元号年を継続させる
147
154
  #
148
155
  def continue_year
149
- @connector.update(lines: [@first_gengou, @second_gengou])
156
+ connector.update(lines: [first_gengou, second_gengou])
150
157
  end
151
158
 
152
159
  #
153
160
  # 現在月に合わせて元号を更新する
154
161
  #
155
162
  def update_current_gengou
156
- start_date = @monthly_start_date
157
- last_date = @monthly_last_date
158
- first_gengou = @range.collect_first(start_date: start_date, last_date: last_date)
159
- second_gengou = @range.collect_second(start_date: start_date,
160
- last_date: last_date)
161
-
162
- @first_gengou = replace_gengou(source: @first_gengou, destination: first_gengou)
163
- @second_gengou = replace_gengou(source: @second_gengou, destination: second_gengou)
163
+ start_date = monthly_start_date
164
+ last_date = monthly_last_date
165
+ dest_first_gengou = range.collect_first(start_date: start_date, last_date: last_date)
166
+ dest_second_gengou = range.collect_second(start_date: start_date,
167
+ last_date: last_date)
168
+
169
+ @first_gengou = replace_gengou(source: first_gengou, destination: dest_first_gengou)
170
+ @second_gengou = replace_gengou(source: second_gengou, destination: dest_second_gengou)
164
171
  end
165
172
 
166
173
  #
@@ -191,9 +198,9 @@ module Zakuro
191
198
  # @return [True] 開始不可
192
199
  #
193
200
  def ignitable?(month:)
194
- return false unless @monthly_start_date.invalid?
201
+ return false unless monthly_start_date.invalid?
195
202
 
196
- japan_start_date = @range.japan_start_date
203
+ japan_start_date = range.japan_start_date
197
204
 
198
205
  japan_start_date.same_month?(leaped: month.leaped?, month: month.number)
199
206
  end
@@ -202,8 +209,8 @@ module Zakuro
202
209
  # 次年にする
203
210
  #
204
211
  def next_year
205
- @first_gengou.each(&:next_year)
206
- @second_gengou.each(&:next_year)
212
+ first_gengou.each(&:next_year)
213
+ second_gengou.each(&:next_year)
207
214
  end
208
215
  end
209
216
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './abstract_scroll'
4
+ require_relative './internal/reserve/dated_range'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Gengou
12
+ # DatedScroll
13
+ #
14
+ # 元号スクロール
15
+ #
16
+ class DatedScroll < AbstractScroll
17
+ #
18
+ # 初期化
19
+ #
20
+ # @param [Western::Calendar] start_date 西暦開始日(最大範囲)
21
+ # @param [Western::Calendar] last_date 西暦終了日(最大範囲)
22
+ #
23
+ def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
24
+ range = Reserve::DatedRange.new(start_date: start_date, last_date: last_date)
25
+ super(range: range)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end