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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd91623531440c342355fd005938af7cc10d07ae858dfb83d51704c6c1eab92c
4
- data.tar.gz: 0a1bfca6ded7403960512c9854c5b22e95b761fb1c8d04fd530cb4806c2eaf66
3
+ metadata.gz: 4aab5a0f52f7180542260fa41204ea918b54601f525029e8e056efcd94cbf725
4
+ data.tar.gz: 6b72f7bbe79473ecbf0332c0f38aeea020d6cee6dfc42c667784c5ba6cb274d1
5
5
  SHA512:
6
- metadata.gz: 76d1ad94413f1b0101964e6ac292e8e4074e2441418a1e31ad3f46d01397e5dba54afaf4799f1a45b310cb32bc17dc27bcf0d6a76348486dacb8a45ecf0df7e3
7
- data.tar.gz: f97b9d72fde20c6bcf991f8136b8c9ee935516c27243f7a46ad60c1c38abe32cecb825a51083f01b605d9f4a00810df7c29be09a6564b2881000dd9ae6713786
6
+ metadata.gz: b990f830dd4bb46a340ae3fadfd2b303bd2a5e686351b2f4463dced260182114a5886ff35e10558d27c99752e9dae6a6bff9805e61ae635076e144341770b665
7
+ data.tar.gz: cc8546a484bba5a35049072b6a048751c9fa13a5609bd677345c9c1d69de2b41362de4695e19f3ec91b67da0de097058bcf16e618534502d1e23b4225763a05d
data/README.md CHANGED
@@ -133,7 +133,7 @@ puts merchant.commit.to_json
133
133
  | 項目名 | キー名 | - | - | データ型 | 参考値 | 備考   |
134
134
  |----------|-----------|---|---|-----------------------------------|--------|---------------------------------------|
135
135
  | 日付情報 | data | | | Zakuro::Result::Data::SingleDay | - | 運用値(計算値は運用情報内を参照のこと)|
136
- | 運用情報 | operation | | | Zakuro::Result::Operation::Bundle | - | - |
136
+ | 運用情報 | operation | | | Zakuro::Result::Operation | - | - |
137
137
 
138
138
  ### Zakuro::Result::Range
139
139
 
@@ -180,10 +180,10 @@ puts merchant.commit.to_json
180
180
  | 項目名 | キー名 | - | - | データ型 | 参考値 | 備考 |
181
181
  |--------------|----------|------------|-------------|--------------------------------------------|---------|----------------------|
182
182
  | 運用有無 | operated |   |   | True/False | true |   |
183
- | 月別履歴情報 | month |   |   | Zakuro::Result::Operation::Month::Bundle |   |   |
183
+ | 月別履歴情報 | month |   |   | Zakuro::Result::Operation::Month |   |   |
184
184
  | 計算値 | original |   |   | Zakuro::Result::Data::SingleDay |   | 運用値差替前の計算値 |
185
185
 
186
- ### Zakuro::Result::Operation::Month::Bundle
186
+ ### Zakuro::Result::Operation::Month
187
187
 
188
188
  | 項目名 | キー名 | - | - | データ型 | 参考値 | 備考 |
189
189
  |--------------------------|----------|------------|----------|--------------------------------------------|--------------|---------------------------------------------|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.8.0
@@ -45,7 +45,7 @@ module Zakuro
45
45
  # @return [LinearGengou] 1行目元号
46
46
  #
47
47
  def match_first_line(date: Western::Calendar)
48
- @first_line.each do |line|
48
+ first_line.each do |line|
49
49
  return line.clone if line.include?(date: date)
50
50
  end
51
51
 
@@ -60,7 +60,7 @@ module Zakuro
60
60
  # @return [LinearGengou] 2行目元号
61
61
  #
62
62
  def match_second_line(date: Western::Calendar)
63
- @second_line.each do |line|
63
+ second_line.each do |line|
64
64
  return line.clone if line.include?(date: date)
65
65
  end
66
66
 
@@ -91,7 +91,7 @@ module Zakuro
91
91
  # @return [LinearGengou] 1行目元号
92
92
  #
93
93
  def match_first_line_by_name(name:)
94
- @first_line.each do |line|
94
+ first_line.each do |line|
95
95
  return line.clone if line.name == name
96
96
  end
97
97
 
@@ -106,7 +106,7 @@ module Zakuro
106
106
  # @return [LinearGengou] 2行目元号
107
107
  #
108
108
  def match_second_line_by_name(name:)
109
- @second_line.each do |line|
109
+ second_line.each do |line|
110
110
  return line.clone if line.name == name
111
111
  end
112
112
 
@@ -120,7 +120,7 @@ module Zakuro
120
120
  # @return [False] 不正なし
121
121
  #
122
122
  def invalid?
123
- @first_line.size.zero? && @second_line.size.zero?
123
+ first_line.size.zero? && second_line.size.zero?
124
124
  end
125
125
  end
126
126
  end
@@ -46,7 +46,7 @@ module Zakuro
46
46
  # @return [False] 不正なし
47
47
  #
48
48
  def invalid?
49
- @name == '' || @year == INVALID_YEAR
49
+ name == '' || year == INVALID_YEAR
50
50
  end
51
51
 
52
52
  #
@@ -60,13 +60,13 @@ module Zakuro
60
60
  def include?(date: Western::Calendar.new)
61
61
  return false if invalid?
62
62
 
63
- return false if @start_date.invalid?
63
+ return false if start_date.invalid?
64
64
 
65
- return false if @last_date.invalid?
65
+ return false if last_date.invalid?
66
66
 
67
- return false if date < @start_date
67
+ return false if date < start_date
68
68
 
69
- return false if date > @last_date
69
+ return false if date > last_date
70
70
 
71
71
  true
72
72
  end
@@ -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
@@ -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
@@ -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
 
@@ -127,7 +127,7 @@ module Zakuro
127
127
  # @return [String] 十干十二支名
128
128
  #
129
129
  def zodiac_name
130
- Cycle::Zodiac.day_name(day: @day)
130
+ Cycle::Zodiac.day_name(day: day)
131
131
  end
132
132
 
133
133
  #
@@ -139,9 +139,9 @@ module Zakuro
139
139
  # @return [False] 当月朔日と翌月朔日が異なる十干(「小」の月)
140
140
  #
141
141
  def same_remainder_divided_by_ten?(other:)
142
- day = @day % LIMIT
142
+ remainder_day = day % LIMIT
143
143
 
144
- (day % 10) == (other % 10)
144
+ (remainder_day % 10) == (other % 10)
145
145
  end
146
146
 
147
147
  #
@@ -153,12 +153,14 @@ module Zakuro
153
153
  #
154
154
  def add(other)
155
155
  invalid?(param: other)
156
- day = @day + other.day
157
- minute = @minute + other.minute
158
- second = @second + other.second
159
- 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
+ )
160
162
 
161
- clone.set(day: day, minute: minute, second: second)
163
+ clone.set(day: sum_day, minute: sum_minute, second: sum_second)
162
164
  end
163
165
 
164
166
  #
@@ -186,12 +188,14 @@ module Zakuro
186
188
  #
187
189
  def sub(other)
188
190
  invalid?(param: other)
189
- day = @day - other.day
190
- minute = @minute - other.minute
191
- second = @second - other.second
192
- 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
+ )
193
197
 
194
- clone.set(day: day, minute: minute, second: second)
198
+ clone.set(day: sum_day, minute: sum_minute, second: sum_second)
195
199
  end
196
200
 
197
201
  #
@@ -300,9 +304,9 @@ module Zakuro
300
304
  def up_on_new_moon
301
305
  cloned = clone
302
306
  limit = (base_day * 3) / 4
303
- if @minute >= limit
304
- day, minute, second = carry((@day + 1), @minute, @second)
305
- 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)
306
310
  end
307
311
 
308
312
  cloned
@@ -333,7 +337,7 @@ module Zakuro
333
337
  # @return [Integer] 小余
334
338
  #
335
339
  def to_minute
336
- @day * @base_day + @minute
340
+ day * base_day + minute
337
341
  end
338
342
 
339
343
  #
@@ -354,7 +358,7 @@ module Zakuro
354
358
  # @return [Float] 小余
355
359
  #
356
360
  def float_minute
357
- @minute + @second.to_f / @base_minute
361
+ minute + second.to_f / base_minute
358
362
  end
359
363
 
360
364
  #
@@ -363,10 +367,10 @@ module Zakuro
363
367
  # @return [AbstractRemainder] 大余
364
368
  #
365
369
  def round
366
- day = @day
367
- day += 1 if @minute >= (@base_day / 2)
370
+ sum_day = day
371
+ sum_day += 1 if minute >= (base_day / 2)
368
372
 
369
- initialize(day, 0, 0)
373
+ initialize(sum_day, 0, 0)
370
374
  end
371
375
 
372
376
  #
@@ -375,7 +379,7 @@ module Zakuro
375
379
  # @return [String] 文字化
376
380
  #
377
381
  def to_s
378
- "大余(日): #{@day}, 小余(分): #{@minute}, 小余(秒): #{@second}"
382
+ "大余(日): #{day}, 小余(分): #{minute}, 小余(秒): #{second}"
379
383
  end
380
384
 
381
385
  #
@@ -384,7 +388,7 @@ module Zakuro
384
388
  # @return [AbstractRemainder] 繰り上げ結果
385
389
  #
386
390
  def carry!
387
- @day, @minute, @second = carry(@day, @minute, @second)
391
+ @day, @minute, @second = carry(day, minute, second)
388
392
 
389
393
  self
390
394
  end
@@ -406,11 +410,11 @@ module Zakuro
406
410
  def carry_second(param_minute, param_second)
407
411
  sign = param_second.negative? ? -1 : 1
408
412
  abs = sign * param_second
409
- minute = param_minute + (sign * (abs / @base_minute).floor)
410
- second = sign * (abs % @base_minute)
413
+ minute = param_minute + (sign * (abs / base_minute).floor)
414
+ second = sign * (abs % base_minute)
411
415
 
412
416
  if sign.negative?
413
- second += @base_minute
417
+ second += base_minute
414
418
  minute -= 1
415
419
  end
416
420
 
@@ -421,11 +425,11 @@ module Zakuro
421
425
  sign = param_minute.negative? ? -1 : 1
422
426
  abs = sign * param_minute
423
427
 
424
- day = param_day + (sign * (abs / @base_day).floor)
425
- minute = sign * (abs % @base_day)
428
+ day = param_day + (sign * (abs / base_day).floor)
429
+ minute = sign * (abs % base_day)
426
430
 
427
431
  if sign.negative?
428
- minute += @base_day
432
+ minute += base_day
429
433
  day -= 1
430
434
  end
431
435
 
@@ -435,37 +439,39 @@ module Zakuro
435
439
  def carry_day(day, limited)
436
440
  sign = day.negative? ? -1 : 1
437
441
  abs = sign * day
438
- carried = sign * (abs % @base_limit) if limited
439
- carried += @base_limit if sign.negative?
442
+ carried = sign * (abs % base_limit) if limited
443
+ carried += base_limit if sign.negative?
440
444
  carried
441
445
  end
442
446
 
443
447
  def up?(other)
444
448
  invalid?(param: other)
445
- day = other.day
446
- minute = other.float_minute
449
+ other_day = other.day
450
+ other_minute = other.float_minute
447
451
 
448
- return true if @day > day
449
- return false if @day < day
452
+ return true if day > other_day
450
453
 
451
- float_minute > minute
454
+ return false if day < other_day
455
+
456
+ float_minute > other_minute
452
457
  end
453
458
 
454
459
  def eql?(other)
455
460
  invalid?(param: other)
456
461
 
457
- (@day == other.day && float_minute == other.float_minute)
462
+ (day == other.day && float_minute == other.float_minute)
458
463
  end
459
464
 
460
465
  def down?(other)
461
466
  invalid?(param: other)
462
- day = other.day
463
- minute = other.float_minute
467
+ other_day = other.day
468
+ other_minute = other.float_minute
469
+
470
+ return true if day < other_day
464
471
 
465
- return true if @day < day
466
- return false if @day > day
472
+ return false if day > other_day
467
473
 
468
- float_minute < minute
474
+ float_minute < other_minute
469
475
  end
470
476
  end
471
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