zakuro 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/README.md +41 -8
  4. data/VERSION +1 -1
  5. data/doc/gengou.md +1 -1
  6. data/doc/operation/csv/month.csv +8 -9
  7. data/doc/operation/operation.xlsx +0 -0
  8. data/images/logo-text.png +0 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +2 -4
  10. data/lib/zakuro/calculation/base/year.rb +1 -1
  11. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +6 -0
  12. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +2 -2
  13. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +4 -2
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +1 -1
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +13 -7
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +18 -9
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +6 -2
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +5 -2
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +3 -3
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +12 -4
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +10 -4
  22. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +5 -2
  23. data/lib/zakuro/calculation/era/version/internal/crawler.rb +3 -3
  24. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +1 -1
  25. data/lib/zakuro/calculation/monthly/internal/date_comparer.rb +78 -0
  26. data/lib/zakuro/calculation/monthly/{meta → internal/meta}/all_solar_term.rb +1 -1
  27. data/lib/zakuro/calculation/monthly/{meta → internal/meta}/meta_collector.rb +2 -2
  28. data/lib/zakuro/calculation/monthly/{first_day.rb → internal/part/first_day.rb} +2 -2
  29. data/lib/zakuro/calculation/monthly/{meta.rb → internal/part/meta.rb} +1 -1
  30. data/lib/zakuro/calculation/monthly/internal/solar_term_selector.rb +203 -0
  31. data/lib/zakuro/calculation/monthly/month.rb +38 -74
  32. data/lib/zakuro/calculation/monthly/operated_month.rb +7 -2
  33. data/lib/zakuro/calculation/option/dropped_date/location.rb +8 -1
  34. data/lib/zakuro/calculation/range/dated_full_range.rb +6 -3
  35. data/lib/zakuro/calculation/range/dated_operation_range.rb +2 -1
  36. data/lib/zakuro/calculation/range/medieval_annual_range.rb +0 -2
  37. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  38. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +24 -10
  39. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +3 -3
  40. data/lib/zakuro/calculation/summary/internal/option/dropped_date.rb +102 -0
  41. data/lib/zakuro/calculation/summary/internal/option/vanished_date.rb +111 -0
  42. data/lib/zakuro/calculation/summary/internal/option.rb +4 -137
  43. data/lib/zakuro/calculation/summary/japan/range.rb +4 -5
  44. data/lib/zakuro/calculation/summary/western/range.rb +8 -1
  45. data/lib/zakuro/calculation/summary/western/single.rb +10 -5
  46. data/lib/zakuro/context/version_class_resolver.rb +5 -5
  47. data/lib/zakuro/era/japan/calendar.rb +4 -4
  48. data/lib/zakuro/era/japan/gengou/alignment/division.rb +2 -2
  49. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +2 -2
  50. data/lib/zakuro/era/japan/gengou/alignment.rb +35 -6
  51. data/lib/zakuro/era/japan/gengou/resource/parser.rb +17 -16
  52. data/lib/zakuro/era/japan/gengou/resource/validator.rb +3 -394
  53. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +2 -2
  54. data/lib/zakuro/era/japan/gengou.rb +8 -6
  55. data/lib/zakuro/era/japan/type/base/both/date.rb +51 -0
  56. data/lib/zakuro/era/japan/type/base/both/year.rb +53 -0
  57. data/lib/zakuro/era/japan/type/base/gengou.rb +177 -0
  58. data/lib/zakuro/era/japan/type/base/gengou_set.rb +78 -0
  59. data/lib/zakuro/era/japan/type/base/switch_date.rb +74 -0
  60. data/lib/zakuro/era/japan/type/base/version_range.rb +189 -0
  61. data/lib/zakuro/era/japan/type/validation/both/date.rb +99 -0
  62. data/lib/zakuro/era/japan/type/validation/both/year.rb +75 -0
  63. data/lib/zakuro/era/japan/type/validation/gengou.rb +93 -0
  64. data/lib/zakuro/era/japan/type/validation/gengou_set.rb +133 -0
  65. data/lib/zakuro/era/japan/type/validation/switch_date.rb +73 -0
  66. data/lib/zakuro/era/japan/type/validation/version_range.rb +109 -0
  67. data/lib/zakuro/era/japan/type/validation/version_root.rb +102 -0
  68. data/lib/zakuro/era/japan/version/resource/parser.rb +266 -0
  69. data/lib/zakuro/era/japan/version/resource/validator.rb +37 -0
  70. data/lib/zakuro/era/japan/version/resource/yaml/version.yaml +80 -0
  71. data/lib/zakuro/era/japan/version/resource.rb +22 -0
  72. data/lib/zakuro/era/japan/version.rb +4 -115
  73. data/lib/zakuro/era/western/calendar.rb +2 -2
  74. data/lib/zakuro/exception/zakuro_error.rb +1 -1
  75. data/lib/zakuro/merchant.rb +5 -5
  76. data/lib/zakuro/operation/month/parser.rb +2 -2
  77. data/lib/zakuro/operation/yaml/month.yaml +8 -40
  78. data/lib/zakuro/output/logger.rb +4 -4
  79. data/lib/zakuro/parameter/catalog/basis_date.rb +55 -0
  80. data/lib/zakuro/parameter/catalog/column.rb +57 -0
  81. data/lib/zakuro/parameter/catalog/option.rb +60 -0
  82. data/lib/zakuro/parameter/catalog/range.rb +81 -0
  83. data/lib/zakuro/parameter/condition.rb +108 -0
  84. data/lib/zakuro/result/core.rb +2 -2
  85. data/lib/zakuro/{tools → tool}/remainder_comparer.rb +3 -2
  86. data/lib/zakuro/{tools → tool}/stringifier.rb +3 -3
  87. data/lib/zakuro/{tools → tool}/typeconv.rb +2 -2
  88. data/lib/zakuro/{tools → tool}/typeof.rb +2 -2
  89. data/lib/zakuro/version/daien/const/number.rb +42 -39
  90. data/lib/zakuro/version/daien/const/remainder.rb +38 -35
  91. data/lib/zakuro/version/daien/cycle/remainder.rb +77 -74
  92. data/lib/zakuro/version/daien/cycle/solar_term.rb +18 -15
  93. data/lib/zakuro/version/daien/daien.rb +8 -5
  94. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +67 -64
  95. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +15 -12
  96. data/lib/zakuro/version/daien/option/vanished_date/parameter.rb +15 -12
  97. data/lib/zakuro/version/daien/range/annual_range.rb +27 -24
  98. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +209 -206
  99. data/lib/zakuro/version/daien/stella/lunar/localization.rb +32 -29
  100. data/lib/zakuro/version/daien/stella/lunar/location.rb +53 -50
  101. data/lib/zakuro/version/daien/stella/lunar/value.rb +65 -62
  102. data/lib/zakuro/version/daien/stella/origin/average_november.rb +23 -20
  103. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +42 -39
  104. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +44 -41
  105. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +74 -71
  106. data/lib/zakuro/version/daien/stella/solar/average.rb +68 -65
  107. data/lib/zakuro/version/daien/stella/solar/interval.rb +95 -92
  108. data/lib/zakuro/version/daien/stella/solar/location.rb +41 -38
  109. data/lib/zakuro/version/daien/stella/solar/value.rb +21 -18
  110. data/lib/zakuro/version/genka/const/number.rb +31 -28
  111. data/lib/zakuro/version/genka/const/remainder.rb +20 -17
  112. data/lib/zakuro/version/genka/cycle/remainder.rb +72 -69
  113. data/lib/zakuro/version/genka/cycle/solar_term.rb +18 -15
  114. data/lib/zakuro/version/genka/genka.rb +8 -5
  115. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +82 -79
  116. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +13 -10
  117. data/lib/zakuro/version/genka/option/vanished_date/parameter.rb +13 -10
  118. data/lib/zakuro/version/genka/range/annual_range.rb +57 -54
  119. data/lib/zakuro/version/genka/stella/origin/first_term.rb +44 -41
  120. data/lib/zakuro/version/genka/stella/origin/january.rb +38 -35
  121. data/lib/zakuro/version/genka/stella/solar/average.rb +24 -21
  122. data/lib/zakuro/version/gihou/const/number.rb +40 -37
  123. data/lib/zakuro/version/gihou/const/remainder.rb +32 -29
  124. data/lib/zakuro/version/gihou/cycle/remainder.rb +38 -35
  125. data/lib/zakuro/version/gihou/cycle/solar_term.rb +18 -15
  126. data/lib/zakuro/version/gihou/gihou.rb +8 -5
  127. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +68 -65
  128. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +13 -10
  129. data/lib/zakuro/version/gihou/option/vanished_date/parameter.rb +13 -10
  130. data/lib/zakuro/version/gihou/range/annual_range.rb +27 -24
  131. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +212 -209
  132. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +32 -29
  133. data/lib/zakuro/version/gihou/stella/lunar/location.rb +53 -50
  134. data/lib/zakuro/version/gihou/stella/lunar/value.rb +65 -62
  135. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +23 -20
  136. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +42 -39
  137. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +44 -41
  138. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +74 -71
  139. data/lib/zakuro/version/gihou/stella/solar/average.rb +67 -64
  140. data/lib/zakuro/version/gihou/stella/solar/interval.rb +95 -92
  141. data/lib/zakuro/version/gihou/stella/solar/location.rb +41 -38
  142. data/lib/zakuro/version/gihou/stella/solar/value.rb +21 -18
  143. data/lib/zakuro/version/gregorio/gregorio.rb +8 -5
  144. data/lib/zakuro/version/houryaku/houryaku.rb +8 -5
  145. data/lib/zakuro/version/joukyou/joukyou.rb +8 -5
  146. data/lib/zakuro/version/kansei/kansei.rb +8 -5
  147. data/lib/zakuro/version/senmyou/const/number.rb +40 -37
  148. data/lib/zakuro/version/senmyou/const/remainder.rb +35 -32
  149. data/lib/zakuro/version/senmyou/cycle/remainder.rb +74 -71
  150. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +18 -15
  151. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +69 -66
  152. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +15 -12
  153. data/lib/zakuro/version/senmyou/option/vanished_date/parameter.rb +15 -12
  154. data/lib/zakuro/version/senmyou/range/annual_range.rb +27 -24
  155. data/lib/zakuro/version/senmyou/senmyou.rb +8 -5
  156. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +206 -203
  157. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +32 -29
  158. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +60 -57
  159. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -63
  160. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +23 -20
  161. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +42 -39
  162. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +44 -41
  163. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +74 -71
  164. data/lib/zakuro/version/senmyou/stella/solar/average.rb +67 -64
  165. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +93 -90
  166. data/lib/zakuro/version/senmyou/stella/solar/location.rb +41 -38
  167. data/lib/zakuro/version/senmyou/stella/solar/value.rb +23 -20
  168. data/lib/zakuro/version/tenpou/tenpou.rb +8 -5
  169. metadata +40 -15
  170. data/lib/zakuro/condition.rb +0 -306
  171. data/lib/zakuro/era/japan/gengou/resource/type.rb +0 -356
  172. /data/lib/zakuro/calculation/monthly/{operated_solar_term.rb → internal/operated_solar_term.rb} +0 -0
  173. /data/lib/zakuro/calculation/monthly/{const.rb → internal/part/const.rb} +0 -0
  174. /data/lib/zakuro/calculation/monthly/{month_label.rb → internal/part/month_label.rb} +0 -0
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Monthly
9
+ #
10
+ # DateComparer 日付比較
11
+ #
12
+ module DateComparer
13
+ class << self
14
+ #
15
+ # 範囲内か
16
+ #
17
+ # @param [Western::Calendar] date 日付
18
+ # @param [Western::Calendar] start_date 開始日
19
+ # @param [Western::Calendar] last_date 終了日
20
+ #
21
+ # @return [True] 範囲内
22
+ # @return [False] 範囲外
23
+ #
24
+ def include?(date:, start_date:, last_date:)
25
+ return false if start_date.invalid?
26
+
27
+ return false if date < start_date
28
+
29
+ return false if date > last_date
30
+
31
+ true
32
+ end
33
+
34
+ #
35
+ # 範囲内か
36
+ #
37
+ # @param [Japan::Calendar] date 日付
38
+ # @param [Base::Gengou] gengou 元号
39
+ # @param [MonthLabel] month_label 月表示名
40
+ #
41
+ # @return [True] 範囲内
42
+ # @return [False] 範囲外
43
+ #
44
+ def include_by_japan_date?(date:, gengou:, month_label:)
45
+ linear_gengou = gengou.match_by_name(name: date.gengou)
46
+
47
+ return false if linear_gengou.invalid?
48
+
49
+ return false unless linear_gengou.name == date.gengou
50
+
51
+ return false unless linear_gengou.year == date.year
52
+
53
+ same_by_japan_date?(month_label: month_label, date: date)
54
+ end
55
+
56
+ private
57
+
58
+ #
59
+ # 同一の月情報かを検証する
60
+ #
61
+ # @param [MonthLabel] month_label 月表示名
62
+ # @param [Japan::Calendar] date 日付
63
+ #
64
+ # @return [True] 同一の月
65
+ # @return [False] 異なる月
66
+ #
67
+ def same_by_japan_date?(month_label:, date: Japan::Calendar.new)
68
+ return false unless month_label.number == date.month
69
+
70
+ return false unless month_label.leaped == date.leaped
71
+
72
+ true
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -48,7 +48,7 @@ module Zakuro
48
48
 
49
49
  first = all_solar_terms[0].clone
50
50
 
51
- return all_solar_terms if before_solar_terms.size.zero?
51
+ return all_solar_terms if before_solar_terms.empty?
52
52
 
53
53
  # 最初の二十四節気が月初日と同日であれば何もしない
54
54
  return all_solar_terms if first.remainder.day == remainder.day
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../era/western/calendar'
3
+ require_relative '../../../../era/western/calendar'
4
4
 
5
- require_relative '../month'
5
+ require_relative '../../month'
6
6
 
7
7
  require_relative './all_solar_term'
8
8
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../era/western/calendar'
3
+ require_relative '../../../../era/western/calendar'
4
4
 
5
- require_relative '../cycle/abstract_remainder'
5
+ require_relative '../../../cycle/abstract_remainder'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../cycle/abstract_remainder'
3
+ require_relative '../../../cycle/abstract_remainder'
4
4
 
5
5
  # :nodoc:
6
6
  module Zakuro
@@ -0,0 +1,203 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../cycle/abstract_solar_term'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Monthly
11
+ #
12
+ # SolarTermSelector 二十四節気検索
13
+ #
14
+ class SolarTermSelector
15
+ # @return [Integer] 月最後の二十四節気を検索する大余の範囲上限
16
+ LAST_DAY_LIMIT = 20
17
+
18
+ # @return [Context::Context] 暦コンテキスト
19
+ attr_reader :context
20
+ # @return [Array<Cyle::AbstractSolarTerm>] 二十四節気
21
+ attr_reader :solar_terms
22
+
23
+ #
24
+ # 初期化
25
+ #
26
+ # @param [Context::Context] context 暦コンテキスト
27
+ # @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
28
+ #
29
+ def initialize(context: Context::Context.new, solar_terms: [])
30
+ @context = context
31
+ @solar_terms = solar_terms
32
+ end
33
+
34
+ #
35
+ # 二十四節気が未設定かどうかを検証する
36
+ #
37
+ # @return [True] 設定なし
38
+ # @return [False] 設定あり
39
+ #
40
+ def empty?
41
+ solar_terms.empty?
42
+ end
43
+
44
+ #
45
+ # 中気を返す
46
+ #
47
+ # @return [Cycle::AbstractSolarTerm] 中気
48
+ #
49
+ def even_term
50
+ solar_terms.each do |term|
51
+ return term if term.index.even?
52
+ end
53
+
54
+ context.resolver.solar_term.new
55
+ end
56
+
57
+ #
58
+ # 節気を返す
59
+ #
60
+ # @return [Cycle::AbstractSolarTerm] 節気
61
+ #
62
+ def odd_term
63
+ solar_terms.each do |term|
64
+ return term if term.index.odd?
65
+ end
66
+
67
+ context.resolver.solar_term.new
68
+ end
69
+
70
+ #
71
+ # 二十四節気を追加する
72
+ #
73
+ # @param [Cycle::AbstractSolarTerm] term 二十四節気
74
+ #
75
+ def add_term(term:)
76
+ solar_terms.push(term)
77
+ end
78
+
79
+ #
80
+ # 二十四節気を正しい順序にソートする
81
+ #
82
+ def sort
83
+ sorted = (solar_terms.sort do |termx, termy|
84
+ termx.index <=> termy.index
85
+ end)
86
+
87
+ unless reset_term?(solar_terms: sorted)
88
+ @solar_terms = sorted
89
+ return
90
+ end
91
+
92
+ @solar_terms = reset(terms: sorted)
93
+ end
94
+
95
+ #
96
+ # 大余に対応する二十四節気
97
+ #
98
+ # @param [Integer] day 大余
99
+ #
100
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
101
+ #
102
+
103
+ #
104
+ # 大余に対応する二十四節気
105
+ #
106
+ # @param [Integer] day 大余
107
+ # @param [Meta] meta メタ情報
108
+ #
109
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
110
+ #
111
+ def solar_term_by_day(day:, meta:)
112
+ target = context.resolver.remainder.new(day: day, minute: 0, second: 0)
113
+
114
+ meta.all_solar_terms.each_cons(2) do |current_solar_term, next_solar_term|
115
+ in_range = Tool::RemainderComparer.in_range?(
116
+ target: target, start: current_solar_term.remainder, last: next_solar_term.remainder
117
+ )
118
+ return current_solar_term if in_range
119
+ end
120
+
121
+ last_solar_term(target: target, meta: meta)
122
+ end
123
+
124
+ private
125
+
126
+ #
127
+ # 二十四節気の折り返し(23 -> 0)があるか
128
+ #
129
+ # @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
130
+ #
131
+ # @return [True] 折り返しあり
132
+ # @return [False] 折り返しなし
133
+ #
134
+ def reset_term?(solar_terms: [])
135
+ first = false
136
+ last = false
137
+
138
+ solar_terms.each do |term|
139
+ index = term.index
140
+ case index
141
+ when Cycle::AbstractSolarTerm::FIRST_INDEX
142
+ first = true
143
+ when Cycle::AbstractSolarTerm::LAST_INDEX
144
+ last = true
145
+ end
146
+ end
147
+
148
+ first && last
149
+ end
150
+
151
+ #
152
+ # 二十四節気を終端で折り返す
153
+ #
154
+ # @param [Array<Cyle::AbstractSolarTerm>] terms 二十四節気
155
+ #
156
+ # @return [Array<Cyle::AbstractSolarTerm>] 折り返し済みの二十四節気
157
+ #
158
+ def reset(terms: [])
159
+ first = []
160
+ second = []
161
+
162
+ terms.each do |term|
163
+ # NOTE: 二十四節気は最大3つとすると、 「23, 0」「22, 23, 0」「23, 0, 1」 での折り返しが考えられる
164
+ if term.index >= (Cycle::AbstractSolarTerm::LAST_INDEX - 2)
165
+ second.push(term)
166
+ next
167
+ end
168
+
169
+ first.push(term)
170
+ end
171
+
172
+ # 0以前を先頭にする
173
+ second += first
174
+
175
+ second
176
+ end
177
+
178
+ #
179
+ # 最後の二十四節気を返す
180
+ #
181
+ # @param [Cycle::AbstractRemainder] target 対象の大余情報
182
+ # @param [Meta] meta メタ情報
183
+ #
184
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
185
+ #
186
+ def last_solar_term(target:, meta:)
187
+ last = meta.all_solar_terms[-1]
188
+
189
+ empty_solar_term = context.resolver.solar_term.new
190
+
191
+ return empty_solar_term unless last
192
+
193
+ if Tool::RemainderComparer.in_limit?(target: target, start: last.remainder,
194
+ limit: LAST_DAY_LIMIT)
195
+ return last
196
+ end
197
+
198
+ empty_solar_term
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../cycle/abstract_solar_term'
4
+
3
5
  require_relative '../base/gengou'
4
- require_relative './first_day'
5
- require_relative './meta'
6
- require_relative './month_label'
7
- require_relative './meta/meta_collector'
6
+ require_relative './internal/part/first_day'
7
+ require_relative './internal/part/meta'
8
+ require_relative './internal/part/month_label'
9
+ require_relative './internal/meta/meta_collector'
10
+
11
+ require_relative './internal/solar_term_selector'
12
+ require_relative './internal/date_comparer'
8
13
 
9
14
  # :nodoc:
10
15
  module Zakuro
@@ -22,8 +27,8 @@ module Zakuro
22
27
  attr_reader :month_label
23
28
  # @return [FirstDay] 月初日(朔日)
24
29
  attr_reader :first_day
25
- # @return [Array<AbstractSolarTerm>] 二十四節気
26
- attr_reader :solar_terms
30
+ # @return [SolarTermSelector] 二十四節気検索
31
+ attr_reader :solar_term_selector
27
32
  # @return [Base::Gengou] 元号
28
33
  attr_reader :gengou
29
34
  # @return [Meta] 付加情報
@@ -37,7 +42,7 @@ module Zakuro
37
42
  # @param [Context::Context] context 暦コンテキスト
38
43
  # @param [MonthLabel] month_label 月表示名
39
44
  # @param [FirstDay] first_day 月初日(朔日)
40
- # @param [Array<AbstractSolarTerm>] solar_terms 二十四節気
45
+ # @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
41
46
  # @param [Base::Gengou] gengou 元号
42
47
  # @param [Meta] meta 付加情報
43
48
  #
@@ -47,7 +52,7 @@ module Zakuro
47
52
  @context = context
48
53
  @month_label = month_label
49
54
  @first_day = first_day
50
- @solar_terms = solar_terms
55
+ @solar_term_selector = SolarTermSelector.new(context: context, solar_terms: solar_terms)
51
56
  @gengou = gengou
52
57
  @meta = meta
53
58
  end
@@ -158,7 +163,7 @@ module Zakuro
158
163
  # @return [False] 設定あり
159
164
  #
160
165
  def empty_solar_term?
161
- solar_terms.empty?
166
+ solar_term_selector.empty?
162
167
  end
163
168
 
164
169
  #
@@ -167,11 +172,7 @@ module Zakuro
167
172
  # @return [Cycle::AbstractSolarTerm] 中気
168
173
  #
169
174
  def even_term
170
- solar_terms.each do |term|
171
- return term if term.index.even?
172
- end
173
-
174
- context.resolver.solar_term.new
175
+ solar_term_selector.even_term
175
176
  end
176
177
 
177
178
  #
@@ -180,11 +181,16 @@ module Zakuro
180
181
  # @return [Cycle::AbstractSolarTerm] 節気
181
182
  #
182
183
  def odd_term
183
- solar_terms.each do |term|
184
- return term if term.index.odd?
185
- end
184
+ solar_term_selector.odd_term
185
+ end
186
186
 
187
- context.resolver.solar_term.new
187
+ #
188
+ # 二十四節気を返す
189
+ #
190
+ # @return [Array<Cyle::AbstractSolarTerm>] 二十四節気
191
+ #
192
+ def solar_terms
193
+ solar_term_selector.solar_terms
188
194
  end
189
195
 
190
196
  #
@@ -193,7 +199,7 @@ module Zakuro
193
199
  # @param [SolarTerm] term 二十四節気
194
200
  #
195
201
  def add_term(term:)
196
- solar_terms.push(term)
202
+ solar_term_selector.add_term(term: term)
197
203
  end
198
204
 
199
205
  #
@@ -230,14 +236,9 @@ module Zakuro
230
236
  def include?(date:)
231
237
  return false if invalid?
232
238
 
233
- start_date = western_date
234
- return false if start_date.invalid?
235
-
236
- return false if date < start_date
237
-
238
- return false if date > last_date
239
-
240
- true
239
+ DateComparer.include?(
240
+ date: date, start_date: western_date, last_date: last_date
241
+ )
241
242
  end
242
243
 
243
244
  #
@@ -251,14 +252,16 @@ module Zakuro
251
252
  def include_by_japan_date?(date:)
252
253
  return false if invalid?
253
254
 
254
- linear_gengou = gengou.match_by_name(name: date.gengou)
255
- return false if linear_gengou.invalid?
256
-
257
- return false unless linear_gengou.name == date.gengou
258
-
259
- return false unless linear_gengou.year == date.year
255
+ DateComparer.include_by_japan_date?(
256
+ date: date, gengou: gengou, month_label: month_label
257
+ )
258
+ end
260
259
 
261
- same_by_japan_date?(date: date)
260
+ #
261
+ # 二十四節気を正しい順序にソートする
262
+ #
263
+ def sort_solar_terms
264
+ solar_term_selector.sort
262
265
  end
263
266
 
264
267
  #
@@ -269,28 +272,7 @@ module Zakuro
269
272
  # @return [Cycle::AbstractSolarTerm] 二十四節気
270
273
  #
271
274
  def solar_term_by_day(day:)
272
- # TODO: refactor
273
- target = context.resolver.remainder.new(day: day, minute: 0, second: 0)
274
-
275
- meta.all_solar_terms.each_cons(2) do |current_solar_term, next_solar_term|
276
- in_range = Tools::RemainderComparer.in_range?(
277
- target: target, start: current_solar_term.remainder, last: next_solar_term.remainder
278
- )
279
- return current_solar_term if in_range
280
- end
281
-
282
- last_solar_term = meta.all_solar_terms[-1]
283
-
284
- empty_solar_term = context.resolver.solar_term.new
285
-
286
- return empty_solar_term unless last_solar_term
287
- # NOTE: 大余20を上限として範囲チェックする
288
- if Tools::RemainderComparer.in_limit?(target: target, start: last_solar_term.remainder,
289
- limit: 20)
290
- return last_solar_term
291
- end
292
-
293
- empty_solar_term
275
+ solar_term_selector.solar_term_by_day(day: day, meta: meta)
294
276
  end
295
277
 
296
278
  #
@@ -304,24 +286,6 @@ module Zakuro
304
286
  current_month: self
305
287
  )
306
288
  end
307
-
308
- private
309
-
310
- #
311
- # 同一の月情報かを検証する
312
- #
313
- # @param [Japan::Calendar] date 日付
314
- #
315
- # @return [True] 同一の月
316
- # @return [False] 異なる月
317
- #
318
- def same_by_japan_date?(date: Japan::Calendar.new)
319
- return false unless number == date.month
320
-
321
- return false unless leaped? == date.leaped
322
-
323
- true
324
- end
325
289
  end
326
290
  end
327
291
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../operation/operation'
4
- require_relative './operated_solar_term'
4
+ require_relative './internal/operated_solar_term'
5
5
  require_relative './month'
6
6
 
7
7
  # :nodoc:
@@ -54,6 +54,8 @@ module Zakuro
54
54
  rewrite_month
55
55
  rewrite_solar_terms
56
56
  rewrite_first_day
57
+
58
+ sort_solar_terms
57
59
  end
58
60
 
59
61
  #
@@ -85,10 +87,13 @@ module Zakuro
85
87
 
86
88
  return unless matched
87
89
 
88
- @solar_terms = OperatedSolarTerm.create_operated_solar_term(
90
+ operated_solar_terms = OperatedSolarTerm.create_operated_solar_term(
89
91
  operated_solar_term: solar_term,
90
92
  solar_terms: solar_terms
91
93
  )
94
+ @solar_term_selector = SolarTermSelector.new(
95
+ context: context, solar_terms: operated_solar_terms
96
+ )
92
97
  end
93
98
 
94
99
  #
@@ -62,7 +62,14 @@ module Zakuro
62
62
  # @return [False] 存在なし
63
63
  #
64
64
  def exist?
65
- !solar_term_remainder.invalid?
65
+ remainder = solar_term_remainder
66
+
67
+ return false if remainder.invalid?
68
+
69
+ minute_later = remainder.class.new(
70
+ day: 0, minute: remainder.minute, second: remainder.second
71
+ )
72
+ minute_later >= limit
66
73
  end
67
74
 
68
75
  #
@@ -19,11 +19,14 @@ module Zakuro
19
19
  # @param [Context::Context] context 暦コンテキスト
20
20
  # @param [Western::Calendar] start_date 開始日
21
21
  # @param [Western::Calendar] last_date 終了日
22
+ # @param [True, False] operated 運用値設定
23
+ # @param [True, False] restored 運用値から計算値に戻すか
22
24
  #
23
- def initialize(context:,
24
- start_date: Western::Calendar.new, last_date: Western::Calendar.new)
25
+ def initialize(context:, start_date: Western::Calendar.new,
26
+ last_date: Western::Calendar.new, operated: false, restored: false)
25
27
  scroll = Gengou::DatedScroll.new(
26
- start_date: start_date, last_date: last_date, operated: false
28
+ start_date: start_date, last_date: last_date, operated: operated,
29
+ restored: restored
27
30
  )
28
31
 
29
32
  super(context: context, scroll: scroll, start_date: start_date, last_date: last_date)
@@ -25,7 +25,8 @@ module Zakuro
25
25
  def initialize(context:, start_date: Western::Calendar.new,
26
26
  last_date: Western::Calendar.new, years: [])
27
27
  scroll = Gengou::DatedScroll.new(
28
- start_date: start_date, last_date: last_date, operated: true
28
+ start_date: start_date, last_date: last_date, operated: true,
29
+ restored: false
29
30
  )
30
31
  super(context: context, scroll: scroll, years: years)
31
32
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  require_relative '../../output/logger'
4
4
  require_relative '../monthly/initialized_month'
5
- require_relative '../monthly/month_label'
6
- require_relative '../monthly/first_day'
7
5
 
8
6
  # :nodoc:
9
7
  module Zakuro
@@ -25,7 +25,7 @@ module Zakuro
25
25
  #
26
26
  def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME)
27
27
  scroll = Gengou::NamedScroll.new(
28
- start_name: start_name, last_name: last_name, operated: false
28
+ start_name: start_name, last_name: last_name, operated: false, restored: false
29
29
  )
30
30
  range = scroll.range
31
31
 
@@ -38,19 +38,33 @@ module Zakuro
38
38
  year.months.each_with_index do |month, index|
39
39
  scroll.run(month: month)
40
40
  gengou = scroll.to_gengou
41
- year.months[index] = Monthly::Month.new(
42
- context: month.context,
43
- month_label: month.month_label,
44
- first_day: Monthly::FirstDay.new(
45
- remainder: month.first_day.remainder,
46
- average_remainder: month.first_day.average_remainder,
47
- western_date: gengou.start_date.clone
48
- ),
49
- solar_terms: month.solar_terms, gengou: gengou,
50
- meta: month.meta
41
+ year.months[index] = replace_gengou(
42
+ month: month, gengou: gengou
51
43
  )
52
44
  end
53
45
  end
46
+
47
+ #
48
+ # 月情報のうち元号を差し替える
49
+ #
50
+ # @param [Monthly::Month] month 月情報
51
+ # @param [Base::Gengou] gengou 元号
52
+ #
53
+ # @return [Monthly::Month] 月情報
54
+ #
55
+ def replace_gengou(month:, gengou:)
56
+ Monthly::Month.new(
57
+ context: month.context,
58
+ month_label: month.month_label,
59
+ first_day: Monthly::FirstDay.new(
60
+ remainder: month.first_day.remainder,
61
+ average_remainder: month.first_day.average_remainder,
62
+ western_date: gengou.start_date.clone
63
+ ),
64
+ solar_terms: month.solar_terms, gengou: gengou,
65
+ meta: month.meta
66
+ )
67
+ end
54
68
  end
55
69
  end
56
70
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../monthly/meta/meta_collector'
3
+ require_relative '../../monthly/internal/meta/meta_collector'
4
4
 
5
- require_relative '../../../tools/remainder_comparer'
5
+ require_relative '../../../tool/remainder_comparer'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
@@ -62,7 +62,7 @@ module Zakuro
62
62
  # * 閏月は1回しか設定しない
63
63
  # * 最大2回設定する(中気・節気)
64
64
  4.times.each do |_index|
65
- in_range = Tools::RemainderComparer.in_range?(
65
+ in_range = Tool::RemainderComparer.in_range?(
66
66
  target: solar_term.remainder, start: current_month.remainder,
67
67
  last: next_month.remainder
68
68
  )