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
@@ -14,7 +14,7 @@ module Zakuro
14
14
  # Month 月情報
15
15
  #
16
16
  class Month
17
- # @return [Context] 暦コンテキスト
17
+ # @return [Context::Context] 暦コンテキスト
18
18
  attr_reader :context
19
19
  # @return [MonthLabel] 月表示名
20
20
  attr_reader :month_label
@@ -28,14 +28,14 @@ module Zakuro
28
28
  #
29
29
  # 初期化
30
30
  #
31
- # @param [Context] context 暦コンテキスト
31
+ # @param [Context::Context] context 暦コンテキスト
32
32
  # @param [MonthLabel] month_label 月表示名
33
33
  # @param [FirstDay] first_day 月初日(朔日)
34
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
35
35
  # @param [Base::Gengou] gengou 元号
36
36
  #
37
- def initialize(context: Context.new, month_label: MonthLabel.new, first_day: FirstDay.new,
38
- solar_terms: [], gengou: Base::Gengou.new)
37
+ def initialize(context: Context::Context.new, month_label: MonthLabel.new,
38
+ first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new)
39
39
  @context = context
40
40
  @month_label = month_label
41
41
  @first_day = first_day
@@ -50,7 +50,7 @@ module Zakuro
50
50
  # @return [False] 不正なし
51
51
  #
52
52
  def invalid?
53
- @context.invalid?
53
+ context.invalid?
54
54
  end
55
55
 
56
56
  #
@@ -68,7 +68,7 @@ module Zakuro
68
68
  # @return [Western::Calendar] 西暦日
69
69
  #
70
70
  def western_date
71
- @first_day.western_date
71
+ first_day.western_date
72
72
  end
73
73
 
74
74
  #
@@ -77,7 +77,7 @@ module Zakuro
77
77
  # @return [Remainder] 大余小余
78
78
  #
79
79
  def remainder
80
- @first_day.remainder
80
+ first_day.remainder
81
81
  end
82
82
 
83
83
  #
@@ -87,7 +87,7 @@ module Zakuro
87
87
  # @return [False] 小の月(29日)
88
88
  #
89
89
  def many_days?
90
- @month_label.is_many_days
90
+ month_label.is_many_days
91
91
  end
92
92
 
93
93
  #
@@ -96,7 +96,7 @@ module Zakuro
96
96
  # @return [Integer] 日数
97
97
  #
98
98
  def days
99
- @month_label.days
99
+ month_label.days
100
100
  end
101
101
 
102
102
  #
@@ -105,7 +105,7 @@ module Zakuro
105
105
  # @return [String] 月の名前(大小)
106
106
  #
107
107
  def days_name
108
- @month_label.days_name
108
+ month_label.days_name
109
109
  end
110
110
 
111
111
  #
@@ -114,7 +114,7 @@ module Zakuro
114
114
  # @return [Integer] 月(xx月のxx)
115
115
  #
116
116
  def number
117
- @month_label.number
117
+ month_label.number
118
118
  end
119
119
 
120
120
  #
@@ -124,7 +124,7 @@ module Zakuro
124
124
  # @return [False] 平月
125
125
  #
126
126
  def leaped?
127
- @month_label.leaped
127
+ month_label.leaped
128
128
  end
129
129
 
130
130
  #
@@ -147,7 +147,7 @@ module Zakuro
147
147
  # @return [False] 設定あり
148
148
  #
149
149
  def empty_solar_term?
150
- @solar_terms.empty?
150
+ solar_terms.empty?
151
151
  end
152
152
 
153
153
  #
@@ -156,7 +156,7 @@ module Zakuro
156
156
  # @return [SolarTerm] 中気
157
157
  #
158
158
  def even_term
159
- @solar_terms.each do |term|
159
+ solar_terms.each do |term|
160
160
  return term if term.index.even?
161
161
  end
162
162
 
@@ -169,7 +169,7 @@ module Zakuro
169
169
  # @return [SolarTerm] 節気
170
170
  #
171
171
  def odd_term
172
- @solar_terms.each do |term|
172
+ solar_terms.each do |term|
173
173
  return term if term.index.odd?
174
174
  end
175
175
 
@@ -182,7 +182,7 @@ module Zakuro
182
182
  # @param [SolarTerm] term 二十四節気
183
183
  #
184
184
  def add_term(term:)
185
- @solar_terms.push(term)
185
+ solar_terms.push(term)
186
186
  end
187
187
 
188
188
  #
@@ -240,7 +240,7 @@ module Zakuro
240
240
  def include_by_japan_date?(date:)
241
241
  return false if invalid?
242
242
 
243
- linear_gengou = @gengou.match_by_name(name: date.gengou)
243
+ linear_gengou = gengou.match_by_name(name: date.gengou)
244
244
  return false if linear_gengou.invalid?
245
245
 
246
246
  return false unless linear_gengou.name == date.gengou
@@ -43,7 +43,7 @@ module Zakuro
43
43
  # @return [Integer] 日数
44
44
  #
45
45
  def days
46
- @is_many_days ? 30 : 29
46
+ is_many_days ? 30 : 29
47
47
  end
48
48
 
49
49
  #
@@ -52,7 +52,7 @@ module Zakuro
52
52
  # @return [String] 月の名前(大小)
53
53
  #
54
54
  def days_name
55
- @is_many_days ? '大' : '小'
55
+ is_many_days ? '大' : '小'
56
56
  end
57
57
 
58
58
  #
@@ -64,7 +64,7 @@ module Zakuro
64
64
  def back_to_last_month
65
65
  @number -= 1
66
66
 
67
- return false if @number.positive?
67
+ return false if number.positive?
68
68
 
69
69
  @number = 12
70
70
 
@@ -80,7 +80,7 @@ module Zakuro
80
80
  # @return [False] 異なる月
81
81
  #
82
82
  def same?(other:)
83
- @number == other.number && @leaped == other.leaped
83
+ number == other.number && leaped == other.leaped
84
84
  end
85
85
  end
86
86
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './month'
4
3
  require_relative '../../operation/operation'
4
+ require_relative './operated_solar_term'
5
+ require_relative './month'
5
6
 
6
7
  # :nodoc:
7
8
  module Zakuro
@@ -17,8 +18,8 @@ module Zakuro
17
18
  class OperatedMonth < Month
18
19
  # @return [Operation::MonthHistory] 変更履歴(月)
19
20
  attr_reader :history
20
- # @return [OperatedSolarTerms] 運用時二十四節気
21
- attr_reader :operated_solar_terms
21
+ # @return [OperatedSolarTerm] 運用時二十四節気
22
+ attr_reader :operated_solar_term
22
23
 
23
24
  # :reek:LongParameterList {max_params: 6}
24
25
  # rubocop:disable Metrics/ParameterLists
@@ -26,20 +27,20 @@ module Zakuro
26
27
  #
27
28
  # 初期化
28
29
  #
29
- # @param [Context] context 暦コンテキスト
30
- # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
30
+ # @param [Context::Context] context 暦コンテキスト
31
+ # @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
31
32
  # @param [MonthLabel] month_label 月表示名
32
33
  # @param [FirstDay] first_day 月初日(朔日)
33
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
34
35
  # @param [Operation::MonthHistory] history 変更履歴(月)
35
36
  #
36
- def initialize(context:, operated_solar_terms:, month_label: MonthLabel.new,
37
+ def initialize(context:, operated_solar_term:, month_label: MonthLabel.new,
37
38
  first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
38
39
  history: Operation::MonthHistory.new)
39
40
  super(context: context, month_label: month_label, first_day: first_day,
40
41
  solar_terms: solar_terms, gengou: gengou)
41
42
  @history = history
42
- @operated_solar_terms = operated_solar_terms
43
+ @operated_solar_term = operated_solar_term
43
44
  @moved = false
44
45
  end
45
46
 
@@ -61,110 +62,39 @@ module Zakuro
61
62
  diff = history.diffs.month
62
63
 
63
64
  @month_label = MonthLabel.new(
64
- number: OperatedMonth.rewrite_month_fields(
65
+ number: self.class.rewrite_month_fields(
65
66
  month_diff: diff, month_label: month_label, name: 'number'
66
67
  ),
67
- is_many_days: OperatedMonth.rewrite_month_fields(
68
+ is_many_days: self.class.rewrite_month_fields(
68
69
  month_diff: diff, month_label: month_label, name: 'is_many_days'
69
70
  ),
70
- leaped: OperatedMonth.rewrite_month_fields(
71
+ leaped: self.class.rewrite_month_fields(
71
72
  month_diff: diff, month_label: month_label, name: 'leaped'
72
73
  )
73
74
  )
74
75
  end
75
76
 
76
- def self.rewrite_month_fields(month_diff:, month_label:, name:)
77
- method_name = name.intern
78
-
79
- diff = month_diff.send(method_name)
80
- default = month_label.send(method_name)
81
- return default if diff.invalid?
82
-
83
- diff.dest
84
- end
85
-
86
77
  #
87
78
  # 二十四節気ごとの差分で書き換える
88
79
  #
89
80
  def rewrite_solar_terms
90
- matched, operated_solar_term = @operated_solar_terms.get(
81
+ matched, solar_term = operated_solar_term.get(
91
82
  western_date: first_day.western_date
92
83
  )
93
84
 
94
85
  return unless matched
95
86
 
96
- @solar_terms = OperatedMonth.create_operated_solar_terms(
97
- operated_solar_term: operated_solar_term,
87
+ @solar_terms = OperatedSolarTerm.create_operated_solar_term(
88
+ operated_solar_term: solar_term,
98
89
  solar_terms: solar_terms
99
90
  )
100
91
  end
101
92
 
102
- #
103
- # 運用情報によって改変した二十四節気を作成する
104
- #
105
- # @param [<Type>] operated_solar_term 運用情報(二十四節気)
106
- # @param [Array<SolarTerm>] solar_terms 二十四節気
107
- #
108
- # @return [Array<SolarTerm>] 二十四節気
109
- #
110
- def self.create_operated_solar_terms(operated_solar_term:, solar_terms:)
111
- index = operated_solar_term.index
112
-
113
- # 別の月に移動する二十四節気。割り当てない。
114
- result = remove_solar_term(index: index, solar_terms: solar_terms)
115
-
116
- return result if used_solar_term?(index: index, solar_terms: solar_terms)
117
-
118
- result.push(operated_solar_term)
119
-
120
- result
121
- end
122
-
123
- # :reek:ControlParameter
124
-
125
- #
126
- # 二十四節気が使用されているか
127
- #
128
- # @param [Integer] index 二十四節気番号
129
- # @param [Array<SolarTerm>] solar_terms 二十四節気
130
- #
131
- # @return [True] 使用
132
- # @return [False] 未使用
133
- #
134
- def self.used_solar_term?(index:, solar_terms:)
135
- solar_terms.each do |solar_term|
136
- return true if index == solar_term.index
137
- end
138
-
139
- false
140
- end
141
-
142
- # :reek:ControlParameter
143
-
144
- #
145
- # 対象の二十四節気を除外する
146
- #
147
- # @param [Integer] index 二十四節気番号
148
- # @param [Array<SolarTerm>] solar_terms 二十四節気
149
- #
150
- # @return [Array<SolarTerm>] 二十四節気(対象除外済)
151
- #
152
- def self.remove_solar_term(index:, solar_terms:)
153
- result = []
154
- solar_terms.each do |solar_term|
155
- next if index == solar_term.index
156
-
157
- result.push(solar_term)
158
- end
159
-
160
- result
161
- end
162
-
163
93
  #
164
94
  # 月初日ごとの差分で書き換える
165
95
  #
166
96
  def rewrite_first_day
167
- diffs = @history.diffs
97
+ diffs = history.diffs
168
98
  return if diffs.invalid_days?
169
99
 
170
100
  days = diffs.days
@@ -242,10 +172,31 @@ module Zakuro
242
172
  @moved = true
243
173
  end
244
174
 
175
+ class << self
176
+ #
177
+ # 計算結果を該当のフィールドの運用情報に書き換える
178
+ #
179
+ # @param [Operation::Diffs] month_diff 月差分
180
+ # @param [MonthLabel] month_label 月表示情報
181
+ # @param [String] name フィールド名
182
+ #
183
+ # @return [Object] 運用情報
184
+ #
185
+ def rewrite_month_fields(month_diff:, month_label:, name:)
186
+ method_name = name.intern
187
+
188
+ diff = month_diff.send(method_name)
189
+ default = month_label.send(method_name)
190
+ return default if diff.invalid?
191
+
192
+ diff.dest
193
+ end
194
+ end
195
+
245
196
  private
246
197
 
247
198
  def history_month_number
248
- @history.diffs.month.number
199
+ history.diffs.month.number
249
200
  end
250
201
  end
251
202
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Monthly
9
+ #
10
+ # OperatedSolarTerm 運用二十四節気
11
+ #
12
+ module OperatedSolarTerm
13
+ class << self
14
+ #
15
+ # 運用情報によって改変した二十四節気を作成する
16
+ #
17
+ # @param [<Type>] operated_solar_term 運用情報(二十四節気)
18
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
19
+ #
20
+ # @return [Array<SolarTerm>] 二十四節気
21
+ #
22
+ def create_operated_solar_term(operated_solar_term:, solar_terms:)
23
+ index = operated_solar_term.index
24
+
25
+ # 別の月に移動する二十四節気。割り当てない。
26
+ result = remove_solar_term(index: index, solar_terms: solar_terms)
27
+
28
+ return result if used_solar_term?(index: index, solar_terms: solar_terms)
29
+
30
+ result.push(operated_solar_term)
31
+
32
+ result
33
+ end
34
+
35
+ private
36
+
37
+ # :reek:ControlParameter
38
+
39
+ #
40
+ # 二十四節気が使用されているか
41
+ #
42
+ # @param [Integer] index 二十四節気番号
43
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
44
+ #
45
+ # @return [True] 使用
46
+ # @return [False] 未使用
47
+ #
48
+ def used_solar_term?(index:, solar_terms:)
49
+ solar_terms.each do |solar_term|
50
+ return true if index == solar_term.index
51
+ end
52
+
53
+ false
54
+ end
55
+
56
+ # :reek:ControlParameter
57
+
58
+ #
59
+ # 対象の二十四節気を除外する
60
+ #
61
+ # @param [Integer] index 二十四節気番号
62
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
63
+ #
64
+ # @return [Array<SolarTerm>] 二十四節気(対象除外済)
65
+ #
66
+ def remove_solar_term(index:, solar_terms:)
67
+ result = []
68
+ solar_terms.each do |solar_term|
69
+ next if index == solar_term.index
70
+
71
+ result.push(solar_term)
72
+ end
73
+
74
+ result
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Option
9
+ # :nodoc:
10
+ module DroppedDate
11
+ #
12
+ # AbstractParameter 没日引数
13
+ #
14
+ class AbstractParameter
15
+ # @return [True] 有効
16
+ # @return [False] 無効
17
+ attr_reader :valid
18
+ # @return [Integer] 年
19
+ attr_reader :year
20
+ # @return [Cycle::AbstractRemainder] 「有没之気」判定
21
+ attr_reader :limit
22
+ # @return [Class] 没余クラス
23
+ attr_reader :remainder_class
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [True, False] valid 有効/無効
29
+ # @param [Integer] year 年
30
+ # @param [Cycle::AbstractRemainder] limit 「有没之気」判定
31
+ # @param [Class] remainder_class 没余クラス
32
+ #
33
+ def initialize(valid: false, year: 0, limit: Cycle::AbstractRemainder.new,
34
+ remainder_class: Object)
35
+ @valid = valid
36
+ @year = year
37
+ @limit = limit
38
+ @remainder_class = remainder_class
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Option
9
+ # :nodoc:
10
+ module DroppedDate
11
+ #
12
+ # Location 没日位置
13
+ #
14
+ class Location
15
+ # @return [Integer] 理想上の年日数
16
+ IDEAL_YEAR = 360
17
+
18
+ # @return [Context::Context] 暦コンテキスト
19
+ attr_reader :context
20
+ # @return [True] 有効
21
+ # @return [False] 無効
22
+ attr_reader :valid
23
+ # @return [Cycle::AbstractRemainder] 「有没之気」判定
24
+ attr_reader :limit
25
+ # @return [Integer] 年
26
+ attr_reader :year
27
+ # @return [Array<Cycle::AbstractSolarTerm>] 二十四節気
28
+ attr_reader :solar_terms
29
+ # @return [Class] 没余クラス
30
+ attr_reader :remainder_class
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [Context::Context] context 暦コンテキスト
36
+ # @param [Array<Cycle::AbstractSolarTerm>] solar_terms 二十四節気
37
+ #
38
+ def initialize(context:, solar_terms: [])
39
+ parameter = context.resolver.dropped_date_parameter.new
40
+ @context = context
41
+ @valid = parameter.valid
42
+ @limit = parameter.limit
43
+ @year = parameter.year
44
+ @remainder_class = parameter.remainder_class
45
+ @solar_terms = solar_terms
46
+ end
47
+
48
+ #
49
+ # 不正か
50
+ #
51
+ # @return [True] 不正
52
+ # @return [False] 不正なし
53
+ #
54
+ def invalid?
55
+ !@valid
56
+ end
57
+
58
+ #
59
+ # 没日が存在するか?
60
+ #
61
+ # @return [True] 存在あり
62
+ # @return [False] 存在なし
63
+ #
64
+ def exist?
65
+ !solar_term_remainder.invalid?
66
+ end
67
+
68
+ #
69
+ # 「没余」を返す
70
+ #
71
+ # @return [Cycle::AbstractRemainder] 没余
72
+ #
73
+ def get
74
+ # 1. 二十四節気の大余小余を取り出す
75
+ remainder = solar_term_remainder
76
+ # 2. 小余360、秒45(360/8)で乗算する
77
+ total = multiple_ideal_year(remainder: remainder)
78
+ # 3. 上記2と章歳(3068055)の差を求める
79
+ diff = (year - total).abs
80
+ # 4. 上記3を通余で徐算する
81
+ result = remainder_class.new(total: diff)
82
+ # 5. 上記4の商と上記1の大余が没日大余、余りが小余(没余)
83
+ day = remainder_class.new(day: remainder.day, minute: 0, second: 0)
84
+
85
+ day.add(result)
86
+ end
87
+
88
+ #
89
+ # 該当の二十四節気を取得する
90
+ #
91
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
92
+ #
93
+ def solar_term
94
+ solar_terms.each do |solar_term|
95
+ remainder = solar_term.remainder.clone
96
+ minute_later = remainder.class.new(
97
+ day: 0, minute: remainder.minute, second: remainder.second
98
+ )
99
+
100
+ return solar_term if minute_later >= limit
101
+ end
102
+
103
+ context.resolver.solar_term.new
104
+ end
105
+
106
+ private
107
+
108
+ #
109
+ # 二十四節気の大余小余を取得する
110
+ #
111
+ # @return [Type::Optional<Cycle::AbstractRemainder>] 大余小余
112
+ #
113
+ def solar_term_remainder
114
+ solar_term.remainder
115
+ end
116
+
117
+ #
118
+ # 理想上の年数を乗算する
119
+ #
120
+ # 宣明暦:小余360、秒45(360/8)で積算する
121
+ #
122
+ # @return [Cycle::AbstractRemainder] 大余小余
123
+ #
124
+ # @return [Integer] 乗算結果
125
+ #
126
+ def multiple_ideal_year(remainder:)
127
+ minute = remainder.minute * IDEAL_YEAR
128
+ second = remainder.second * (IDEAL_YEAR / remainder.base_minute)
129
+ minute + second
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end