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
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative './year'
4
4
 
5
- require_relative '../../version/context'
5
+ require_relative '../../context/context'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
@@ -17,11 +17,11 @@ module Zakuro
17
17
  #
18
18
  # 初期化
19
19
  #
20
- # @param [Context] context 暦コンテキスト
20
+ # @param [Context::Context] context 暦コンテキスト
21
21
  # @param [Array<OperatedMonth>] months 年内の全ての月
22
22
  # @param [Integer] total_days 年の日数
23
23
  #
24
- def initialize(context: Context.new, months: [], total_days: 0)
24
+ def initialize(context: Context::Context.new, months: [], total_days: 0)
25
25
  super(context: context, months: months, total_days: total_days)
26
26
  end
27
27
 
@@ -56,7 +56,7 @@ module Zakuro
56
56
  # @return [Array<OperatedMonth>] 昨年に属する月
57
57
  #
58
58
  def shift_last_year_months
59
- result, @months = OperatedYear.devide_with(method: :last_year?, arr: months)
59
+ result, @months = self.class.devide_with(method: :last_year?, arr: months)
60
60
 
61
61
  result
62
62
  end
@@ -67,36 +67,38 @@ module Zakuro
67
67
  # @return [Array<OperatedMonth>] 来年に属する月
68
68
  #
69
69
  def pop_next_year_months
70
- result, @months = OperatedYear.devide_with(method: :next_year?, arr: months)
70
+ result, @months = self.class.devide_with(method: :next_year?, arr: months)
71
71
 
72
72
  result
73
73
  end
74
74
 
75
75
  # :reek:TooManyStatements { max_statements: 8 }
76
76
 
77
- #
78
- # メソッドで配列を分離する
79
- #
80
- # @param [Symbol] method 条件メソッド
81
- # @param [Array<Object>] arr 配列
82
- #
83
- # @return [Array<Object>] 一致配列
84
- # @return [Array<Object>] 不一致配列
85
- #
86
- def self.devide_with(method:, arr: [])
87
- match = []
88
- unmatch = []
77
+ class << self
78
+ #
79
+ # メソッドで配列を分離する
80
+ #
81
+ # @param [Symbol] method 条件メソッド
82
+ # @param [Array<Object>] arr 配列
83
+ #
84
+ # @return [Array<Object>] 一致配列
85
+ # @return [Array<Object>] 不一致配列
86
+ #
87
+ def devide_with(method:, arr: [])
88
+ match = []
89
+ unmatch = []
90
+
91
+ arr.each do |item|
92
+ if !item.moved? && item.send(method)
93
+ match.push(item)
94
+ next
95
+ end
89
96
 
90
- arr.each do |item|
91
- if !item.moved? && item.send(method)
92
- match.push(item)
93
- next
97
+ unmatch.push(item)
94
98
  end
95
99
 
96
- unmatch.push(item)
100
+ [match, unmatch]
97
101
  end
98
-
99
- [match, unmatch]
100
102
  end
101
103
  end
102
104
  end
@@ -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
@@ -72,15 +72,7 @@ module Zakuro
72
72
  def ignite(month:)
73
73
  return false unless ignitable?(month: month)
74
74
 
75
- japan_start_date = @range.japan_start_date
76
-
77
- western_start_date = @range.western_start_date
78
-
79
- # 今月初日(和暦日が1月2日であれば、開始日の1日前が初日)
80
- @monthly_start_date = western_start_date.clone - japan_start_date.day + 1
81
-
82
- # 今月末
83
- @monthly_last_date = @monthly_start_date.clone + month.days - 1
75
+ first_monthly_date(month: month)
84
76
 
85
77
  update_current_gengou
86
78
 
@@ -93,9 +85,9 @@ module Zakuro
93
85
  # @param [Monthly::Month] month 月
94
86
  #
95
87
  def advance(month:)
96
- @monthly_start_date = @monthly_last_date.clone + 1
88
+ @monthly_start_date = monthly_last_date.clone + 1
97
89
 
98
- @monthly_last_date = @monthly_start_date.clone + month.days - 1
90
+ @monthly_last_date = monthly_start_date.clone + month.days - 1
99
91
 
100
92
  next_year if month.number == 1 && !month.leaped?
101
93
 
@@ -108,15 +100,15 @@ module Zakuro
108
100
  # @return [Base::Gengou] 元号
109
101
  #
110
102
  def to_gengou
111
- start_date = @monthly_start_date.clone
112
- last_date = @monthly_last_date.clone
103
+ start_date = monthly_start_date.clone
104
+ last_date = monthly_last_date.clone
113
105
 
114
106
  # 行を超えた元号切り替え処理
115
107
  continue_year
116
108
 
117
109
  Publisher.run(
118
110
  start_date: start_date, last_date: last_date,
119
- first_gengou: @first_gengou, second_gengou: @second_gengou
111
+ first_gengou: first_gengou, second_gengou: second_gengou
120
112
  )
121
113
  end
122
114
 
@@ -126,7 +118,7 @@ module Zakuro
126
118
  # @return [Integer] 開始西暦年
127
119
  #
128
120
  def western_start_year
129
- @range.western_start_year
121
+ range.western_start_year
130
122
  end
131
123
 
132
124
  #
@@ -135,30 +127,47 @@ module Zakuro
135
127
  # @return [Integer] 終了西暦年
136
128
  #
137
129
  def western_last_year
138
- @range.western_last_year
130
+ range.western_last_year
139
131
  end
140
132
 
141
133
  private
142
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
+
143
152
  #
144
153
  # 行を跨ぐ元号年を継続させる
145
154
  #
146
155
  def continue_year
147
- @connector.update(lines: [@first_gengou, @second_gengou])
156
+ connector.update(lines: [first_gengou, second_gengou])
148
157
  end
149
158
 
150
159
  #
151
160
  # 現在月に合わせて元号を更新する
152
161
  #
153
162
  def update_current_gengou
154
- start_date = @monthly_start_date
155
- last_date = @monthly_last_date
156
- first_gengou = @range.collect_first(start_date: start_date, last_date: last_date)
157
- second_gengou = @range.collect_second(start_date: start_date,
158
- last_date: last_date)
159
-
160
- @first_gengou = replace_gengou(source: @first_gengou, destination: first_gengou)
161
- @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)
162
171
  end
163
172
 
164
173
  #
@@ -189,9 +198,9 @@ module Zakuro
189
198
  # @return [True] 開始不可
190
199
  #
191
200
  def ignitable?(month:)
192
- return false unless @monthly_start_date.invalid?
201
+ return false unless monthly_start_date.invalid?
193
202
 
194
- japan_start_date = @range.japan_start_date
203
+ japan_start_date = range.japan_start_date
195
204
 
196
205
  japan_start_date.same_month?(leaped: month.leaped?, month: month.number)
197
206
  end
@@ -200,8 +209,8 @@ module Zakuro
200
209
  # 次年にする
201
210
  #
202
211
  def next_year
203
- @first_gengou.each(&:next_year)
204
- @second_gengou.each(&:next_year)
212
+ first_gengou.each(&:next_year)
213
+ second_gengou.each(&:next_year)
205
214
  end
206
215
  end
207
216
  end