zakuro 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/VERSION +1 -1
- data/lib/zakuro/calculation/base/gengou.rb +5 -5
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +23 -21
- data/lib/zakuro/calculation/base/year.rb +3 -3
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
- data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
- data/lib/zakuro/calculation/era/version/version.rb +12 -10
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
- data/lib/zakuro/calculation/monthly/const.rb +18 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +39 -37
- data/lib/zakuro/calculation/monthly/month.rb +15 -15
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +5 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
- data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
- data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +95 -92
- data/lib/zakuro/calculation/summary/western/single.rb +78 -76
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -124
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/condition.rb +121 -111
- data/lib/zakuro/context/context.rb +1 -1
- data/lib/zakuro/context/option.rb +31 -29
- data/lib/zakuro/context/version_class_resolver.rb +26 -24
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
- data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -36
- data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -37
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
- data/lib/zakuro/era/japan/gengou.rb +28 -26
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +102 -90
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +15 -13
- data/lib/zakuro/exception/zakuro_error.rb +1 -1
- data/lib/zakuro/gateway/locale/date.rb +2 -2
- data/lib/zakuro/gateway/locale/range.rb +3 -3
- data/lib/zakuro/gateway/range.rb +1 -1
- data/lib/zakuro/gateway/single.rb +13 -2
- data/lib/zakuro/merchant.rb +1 -1
- data/lib/zakuro/operation/month/parser.rb +252 -251
- data/lib/zakuro/operation/month/type.rb +17 -8
- data/lib/zakuro/operation/month/validator.rb +148 -144
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/output/response.rb +112 -113
- data/lib/zakuro/result/operation/month/annotation.rb +2 -2
- data/lib/zakuro/result/operation/month/history.rb +2 -2
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +39 -0
- data/lib/zakuro/result/result.rb +3 -3
- data/lib/zakuro/tools/stringifier.rb +66 -64
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
- data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
- data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
- metadata +12 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/bundle.rb +0 -44
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './
|
3
|
+
require_relative './operated_solar_term'
|
4
4
|
require_relative '../../operation/operation'
|
5
5
|
require_relative '../base/operated_year'
|
6
6
|
require_relative '../../calculation/monthly/operated_month'
|
@@ -19,8 +19,8 @@ module Zakuro
|
|
19
19
|
class AbstractOperationRange
|
20
20
|
# @return [Array<Year>] 年データ(完全範囲)
|
21
21
|
attr_reader :years
|
22
|
-
# @return [
|
23
|
-
attr_reader :
|
22
|
+
# @return [OperatedSolarTerm] 運用時二十四節気
|
23
|
+
attr_reader :operated_solar_term
|
24
24
|
# @return [Context::Context] 暦コンテキスト
|
25
25
|
attr_reader :context
|
26
26
|
|
@@ -35,8 +35,8 @@ module Zakuro
|
|
35
35
|
@context = context
|
36
36
|
@years = years
|
37
37
|
@scroll = scroll
|
38
|
-
@
|
39
|
-
|
38
|
+
@operated_solar_term = OperatedSolarTerm.new(context: context, years: @years)
|
39
|
+
operated_solar_term.create
|
40
40
|
end
|
41
41
|
|
42
42
|
#
|
@@ -47,9 +47,9 @@ module Zakuro
|
|
47
47
|
def get
|
48
48
|
operated_years = rewrite
|
49
49
|
|
50
|
-
|
50
|
+
self.class.move(operated_years: operated_years)
|
51
51
|
|
52
|
-
|
52
|
+
self.class.commit(operated_years: operated_years)
|
53
53
|
|
54
54
|
Transfer::GengouScroller.set(scroll: @scroll, years: operated_years)
|
55
55
|
|
@@ -65,9 +65,9 @@ module Zakuro
|
|
65
65
|
operated_years = []
|
66
66
|
|
67
67
|
years.each do |year|
|
68
|
-
operated_year =
|
68
|
+
operated_year = self.class.rewrite_year(
|
69
69
|
year: year,
|
70
|
-
|
70
|
+
operated_solar_term: operated_solar_term
|
71
71
|
)
|
72
72
|
operated_years.push(operated_year)
|
73
73
|
end
|
@@ -75,115 +75,117 @@ module Zakuro
|
|
75
75
|
operated_years
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
#
|
89
|
-
# 運用情報では来年に属する月を来年に寄せる
|
90
|
-
#
|
91
|
-
# @param [Array<OperatedYear>] operated_years 運用結果範囲
|
92
|
-
#
|
93
|
-
def self.move_into_next_year(operated_years:)
|
94
|
-
operated_years.each_cons(2) do |current_year, next_year|
|
95
|
-
months = current_year.pop_next_year_months
|
96
|
-
|
97
|
-
next_year.unshift_months(months)
|
78
|
+
class << self
|
79
|
+
#
|
80
|
+
# 運用情報で年を跨ぐ月をその年に寄せる
|
81
|
+
#
|
82
|
+
# @param [Array<OperatedYear>] operated_years 運用結果範囲
|
83
|
+
#
|
84
|
+
def move(operated_years:)
|
85
|
+
move_into_next_year(operated_years: operated_years)
|
86
|
+
move_into_last_year(operated_years: operated_years)
|
98
87
|
end
|
99
|
-
end
|
100
88
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
89
|
+
#
|
90
|
+
# 運用情報では来年に属する月を来年に寄せる
|
91
|
+
#
|
92
|
+
# @param [Array<OperatedYear>] operated_years 運用結果範囲
|
93
|
+
#
|
94
|
+
def move_into_next_year(operated_years:)
|
95
|
+
operated_years.each_cons(2) do |current_year, next_year|
|
96
|
+
months = current_year.pop_next_year_months
|
97
|
+
|
98
|
+
next_year.unshift_months(months)
|
99
|
+
end
|
111
100
|
end
|
112
101
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
# 年を書き換える
|
127
|
-
#
|
128
|
-
# @param [Year] year 年
|
129
|
-
# @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
|
130
|
-
#
|
131
|
-
# @return [OperatedYear] 年
|
132
|
-
#
|
133
|
-
def self.rewrite_year(year:, operated_solar_terms:)
|
134
|
-
context = year.context
|
135
|
-
result = Base::OperatedYear.new(context: context)
|
136
|
-
year.months.each do |month|
|
137
|
-
result.push(month: resolve_month(
|
138
|
-
context: context, month: month,
|
139
|
-
operated_solar_terms: operated_solar_terms
|
140
|
-
))
|
102
|
+
#
|
103
|
+
# 運用情報では昨年に属する月を昨年に寄せる
|
104
|
+
#
|
105
|
+
# @param [Array<OperatedYear>] operated_years 運用結果範囲
|
106
|
+
#
|
107
|
+
def move_into_last_year(operated_years:)
|
108
|
+
rerversed_year = operated_years.reverse!
|
109
|
+
rerversed_year.each_cons(2) do |current_year, last_year|
|
110
|
+
months = current_year.shift_last_year_months
|
111
|
+
last_year.push_months(months)
|
112
|
+
end
|
113
|
+
|
114
|
+
rerversed_year.reverse!
|
141
115
|
end
|
142
116
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
# @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
|
152
|
-
#
|
153
|
-
# @return [Month] 月
|
154
|
-
#
|
155
|
-
def self.resolve_month(context:, month:, operated_solar_terms:)
|
156
|
-
history = Operation.specify_history(western_date: month.western_date)
|
117
|
+
#
|
118
|
+
# 年を確定させる
|
119
|
+
#
|
120
|
+
# @param [Array<OperatedYear>] operated_years 運用結果範囲
|
121
|
+
#
|
122
|
+
def commit(operated_years:)
|
123
|
+
operated_years.each(&:commit)
|
124
|
+
end
|
157
125
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
126
|
+
#
|
127
|
+
# 年を書き換える
|
128
|
+
#
|
129
|
+
# @param [Year] year 年
|
130
|
+
# @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
|
131
|
+
#
|
132
|
+
# @return [OperatedYear] 年
|
133
|
+
#
|
134
|
+
def rewrite_year(year:, operated_solar_term:)
|
135
|
+
context = year.context
|
136
|
+
result = Base::OperatedYear.new(context: context)
|
137
|
+
year.months.each do |month|
|
138
|
+
result.push(month: resolve_month(
|
139
|
+
context: context, month: month,
|
140
|
+
operated_solar_term: operated_solar_term
|
141
|
+
))
|
142
|
+
end
|
143
|
+
|
144
|
+
result
|
145
|
+
end
|
163
146
|
|
164
|
-
|
147
|
+
#
|
148
|
+
# 履歴情報の有無に応じた月にする
|
149
|
+
#
|
150
|
+
# @param [Context] context 暦コンテキスト
|
151
|
+
# @param [Month] month 月
|
152
|
+
# @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
|
153
|
+
#
|
154
|
+
# @return [Month] 月
|
155
|
+
#
|
156
|
+
def resolve_month(context:, month:, operated_solar_term:)
|
157
|
+
history = Operation.specify_history(western_date: month.western_date)
|
158
|
+
|
159
|
+
rewrite_month(
|
160
|
+
context: context, month: month, history: history,
|
161
|
+
operated_solar_term: operated_solar_term
|
162
|
+
)
|
163
|
+
end
|
165
164
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
165
|
+
# :reek:LongParameterList {max_params: 4}
|
166
|
+
|
167
|
+
#
|
168
|
+
# 月を運用結果に書き換える
|
169
|
+
#
|
170
|
+
# @param [Context] context 暦コンテキスト
|
171
|
+
# @param [Month] month 月
|
172
|
+
# @param [Operation::MonthHistory] history 変更履歴
|
173
|
+
# @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
|
174
|
+
#
|
175
|
+
# @return [Month] 月(運用結果)
|
176
|
+
#
|
177
|
+
def rewrite_month(context:, month:, history:, operated_solar_term:)
|
178
|
+
operated_month = Monthly::OperatedMonth.new(
|
179
|
+
context: context,
|
180
|
+
month_label: month.month_label, first_day: month.first_day,
|
181
|
+
solar_terms: month.solar_terms, history: history, gengou: month.gengou,
|
182
|
+
operated_solar_term: operated_solar_term
|
183
|
+
)
|
183
184
|
|
184
|
-
|
185
|
+
operated_month.rewrite unless history.invalid?
|
185
186
|
|
186
|
-
|
187
|
+
operated_month
|
188
|
+
end
|
187
189
|
end
|
188
190
|
end
|
189
191
|
end
|
@@ -23,82 +23,83 @@ module Zakuro
|
|
23
23
|
# @return [Output::Logger] ロガー
|
24
24
|
LOGGER = Output::Logger.new(location: 'medieval_annual_range')
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
class << self
|
27
|
+
#
|
28
|
+
# 一覧取得する
|
29
|
+
#
|
30
|
+
# * 対象年に対して、前年11月-当年11月までを出力する
|
31
|
+
# * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
|
32
|
+
#
|
33
|
+
# @param [Context::Context] context 暦コンテキスト
|
34
|
+
# @param [Monthly::AbstractLunarPhase] lunar_phase 月の位相
|
35
|
+
# @param [Solar::AbstractAverage] solar_average 定気(太陽軌道平均)
|
36
|
+
#
|
37
|
+
# @return [Array<Month>] 1年データ
|
38
|
+
#
|
39
|
+
def get(context:, lunar_phase:, solar_average:)
|
40
|
+
annual_range = initialized_annual_range(context: context, lunar_phase: lunar_phase)
|
40
41
|
|
41
|
-
|
42
|
+
apply_big_and_small_of_the_month(annual_range: annual_range)
|
42
43
|
|
43
|
-
|
44
|
+
solar_average.set(annual_range: annual_range)
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
# 月間隔を取得するためだけの末尾要素を削除
|
47
|
+
annual_range.pop
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
initialize_month_label(annual_range: annual_range)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
# 1年データを取得する
|
53
|
-
#
|
54
|
-
# @param [Context::Context] context 暦コンテキスト
|
55
|
-
# @param [Monthly::LunarPhase] lunar_phase 月の位相
|
56
|
-
#
|
57
|
-
# @return [Array<Month>] 1年データ
|
58
|
-
#
|
59
|
-
def self.initialized_annual_range(context:, lunar_phase:)
|
60
|
-
result = []
|
52
|
+
private
|
61
53
|
|
62
|
-
#
|
63
|
-
|
64
|
-
|
54
|
+
#
|
55
|
+
# 1年データを取得する
|
56
|
+
#
|
57
|
+
# @param [Context::Context] context 暦コンテキスト
|
58
|
+
# @param [Monthly::LunarPhase] lunar_phase 月の位相
|
59
|
+
#
|
60
|
+
# @return [Array<Month>] 1年データ
|
61
|
+
#
|
62
|
+
def initialized_annual_range(context:, lunar_phase:)
|
63
|
+
result = []
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
# 14ヶ月分を生成する(閏年で最大13ヶ月 + 末月の大小/二十四節気を求めるために必要な月)
|
66
|
+
(0..13).each do |_index|
|
67
|
+
adjusted = lunar_phase.next_month
|
68
|
+
|
69
|
+
result.push(
|
70
|
+
Monthly::InitializedMonth.new(
|
71
|
+
context: context,
|
72
|
+
month_label: Monthly::MonthLabel.new,
|
73
|
+
first_day: Monthly::FirstDay.new(remainder: adjusted),
|
74
|
+
phase_index: 0
|
75
|
+
)
|
72
76
|
)
|
73
|
-
|
74
|
-
end
|
77
|
+
end
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
private_class_method :initialized_annual_range
|
79
|
+
result
|
80
|
+
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
#
|
83
|
+
# 1年データの各月に月の大小を設定する
|
84
|
+
#
|
85
|
+
# @param [Array<Month>] annual_range 1年データ
|
86
|
+
#
|
87
|
+
def apply_big_and_small_of_the_month(annual_range:)
|
88
|
+
# NOTE: 最後の月は処理できない(=計算外の余分な月が最後に必要である)
|
89
|
+
annual_range.each_cons(2) do |(current_month, next_month)|
|
90
|
+
current_month.eval_many_days(next_month_day: next_month.remainder.day)
|
91
|
+
end
|
89
92
|
end
|
90
|
-
end
|
91
|
-
private_class_method :apply_big_and_small_of_the_month
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
#
|
95
|
+
# 月表示情報を更新する
|
96
|
+
#
|
97
|
+
# @param [Array<Month>] annual_range 1年データ
|
98
|
+
#
|
99
|
+
def initialize_month_label(annual_range:)
|
100
|
+
annual_range.each(&:rename_month_label_by_solar_term)
|
101
|
+
end
|
100
102
|
end
|
101
|
-
private_class_method :initialize_month_label
|
102
103
|
end
|
103
104
|
end
|
104
105
|
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../operation/operation'
|
4
|
+
require_relative '../monthly/month'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Range
|
12
|
+
#
|
13
|
+
# OperatedSolarTerm 運用時二十四節気
|
14
|
+
#
|
15
|
+
class OperatedSolarTerm
|
16
|
+
# @return [Array<Year>] 完全範囲(年データ)
|
17
|
+
attr_reader :years
|
18
|
+
# @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
19
|
+
#
|
20
|
+
# * 移動元の二十四節気:無効な大余小余あり(削除対象)
|
21
|
+
# * 移動先の二十四節気:移動元からの二十四節気(追加対象)
|
22
|
+
#
|
23
|
+
attr_reader :directions
|
24
|
+
# @return [Context::Context] 暦コンテキスト
|
25
|
+
attr_reader :context
|
26
|
+
|
27
|
+
#
|
28
|
+
# 初期化
|
29
|
+
#
|
30
|
+
# @param [Context::Context] context 暦コンテキスト
|
31
|
+
# @param [Array<Year>] years 完全範囲(年データ)
|
32
|
+
#
|
33
|
+
def initialize(context:, years: [])
|
34
|
+
@context = context
|
35
|
+
@years = years
|
36
|
+
@directions = {}
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# データ生成する
|
41
|
+
#
|
42
|
+
# @return [<Type>] <description>
|
43
|
+
#
|
44
|
+
def create
|
45
|
+
@directions = create_directions
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# 二十四節気を取得する
|
50
|
+
#
|
51
|
+
# @param [Western::Calendar] western_date 月初日の西暦日
|
52
|
+
#
|
53
|
+
# @return [True] 対象あり
|
54
|
+
# @return [False] 対象なし
|
55
|
+
# @return [SolarTerm] 二十四節気
|
56
|
+
#
|
57
|
+
def get(western_date: Western::Calendar.new)
|
58
|
+
context = current_context(western_date: western_date)
|
59
|
+
|
60
|
+
solar_term_class = context.resolver.solar_term
|
61
|
+
solar_term = directions.fetch(western_date.format, solar_term_class.new)
|
62
|
+
|
63
|
+
# 合致しない場合
|
64
|
+
return false, solar_term_class.new if solar_term.empty?
|
65
|
+
|
66
|
+
# 合致した上で、二十四節気が移動元(削除対象)の場合
|
67
|
+
# 合致した上で、二十四節気が移動先(追加対象)の場合
|
68
|
+
[true, solar_term]
|
69
|
+
end
|
70
|
+
|
71
|
+
# :reek:LongParameterList {max_params: 4}
|
72
|
+
|
73
|
+
class << self
|
74
|
+
# :reek:TooManyStatements { max_statements: 6 }
|
75
|
+
|
76
|
+
#
|
77
|
+
# 年内の全ての月の移動方向を作成する
|
78
|
+
#
|
79
|
+
# @param [Context::Context] context 暦コンテキスト
|
80
|
+
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
81
|
+
# @param [Array<Month>] months 年内の全ての月
|
82
|
+
#
|
83
|
+
def create_directions_with_months(context:, directions: {}, months: [])
|
84
|
+
months.each do |month|
|
85
|
+
history = Operation.specify_history(western_date: month.western_date)
|
86
|
+
|
87
|
+
next if history.invalid?
|
88
|
+
|
89
|
+
direction = history.diffs.solar_term
|
90
|
+
|
91
|
+
next if direction.invalid?
|
92
|
+
|
93
|
+
create_directions_each_month(
|
94
|
+
context: context, directions: directions, direction: direction, month: month
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# 月毎の移動方向を作成する
|
101
|
+
#
|
102
|
+
# @param [Context::Context] context 暦コンテキスト
|
103
|
+
# @param [Month] 月
|
104
|
+
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
105
|
+
# @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
|
106
|
+
#
|
107
|
+
def create_directions_each_month(context:, month:, directions: {},
|
108
|
+
direction: Operation::SolarTerm::Diretion.new)
|
109
|
+
|
110
|
+
month.solar_terms.each do |solar_term|
|
111
|
+
push_source(context: context, directions: directions,
|
112
|
+
direction: direction, solar_term: solar_term)
|
113
|
+
end
|
114
|
+
push_destination(context: context, directions: directions,
|
115
|
+
destination: direction.destination)
|
116
|
+
end
|
117
|
+
|
118
|
+
# :reek:LongParameterList {max_params: 4}
|
119
|
+
|
120
|
+
#
|
121
|
+
# 移動先に有効な二十四節気(差し替える二十四節気)を指定する
|
122
|
+
#
|
123
|
+
# @param [Context::Context] context 暦コンテキスト
|
124
|
+
# @param [SolarTerm] solar_term 二十四節気(計算値)
|
125
|
+
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
126
|
+
# @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
|
127
|
+
#
|
128
|
+
def push_source(context:, solar_term:, directions: {},
|
129
|
+
direction: Operation::SolarTerm::Direction.new)
|
130
|
+
source = direction.source
|
131
|
+
|
132
|
+
return if source.invalid?
|
133
|
+
|
134
|
+
return unless source.index == solar_term.index
|
135
|
+
|
136
|
+
# 移動先に移動元の二十四節気を指定する
|
137
|
+
directions[source.to.format] = created_source(
|
138
|
+
context: context, direction: direction, solar_term: solar_term
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# 移動先に有効な二十四節気(差し替える二十四節気)を生成する
|
144
|
+
#
|
145
|
+
# @param [Context::Context] context 暦コンテキスト
|
146
|
+
# @param [SolarTerm] solar_term 二十四節気(計算値)
|
147
|
+
# @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
|
148
|
+
#
|
149
|
+
# @return [SolarTerm] 二十四節気(運用値)
|
150
|
+
#
|
151
|
+
def created_source(context:, solar_term:,
|
152
|
+
direction: Operation::SolarTerm::Direction.new)
|
153
|
+
operated_solar_term = solar_term.clone
|
154
|
+
remainder_class_name = context.resolver.remainder
|
155
|
+
|
156
|
+
unless direction.invalid_days?
|
157
|
+
# 二十四節気の大余をずらす
|
158
|
+
operated_solar_term.remainder.add!(
|
159
|
+
remainder_class_name.new(day: direction.days, minute: 0, second: 0)
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
operated_solar_term
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# 移動元に無効な二十四節気(連番のみ指定)を指定する
|
168
|
+
#
|
169
|
+
# @param [Context::Context] context 暦コンテキスト
|
170
|
+
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
171
|
+
# @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
|
172
|
+
#
|
173
|
+
def push_destination(context:, directions: {},
|
174
|
+
destination: Operation::SolarTerm::Destination.new)
|
175
|
+
return if destination.invalid?
|
176
|
+
|
177
|
+
solar_term_class = context.resolver.solar_term
|
178
|
+
directions[destination.from.format] = solar_term_class.new(
|
179
|
+
index: destination.index
|
180
|
+
)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
|
186
|
+
#
|
187
|
+
# 日付に対応する暦コンテキストを取得する
|
188
|
+
#
|
189
|
+
# @param [Western::Calendar] western_date 西暦日
|
190
|
+
#
|
191
|
+
# @return [Context::Context] 暦コンテキスト
|
192
|
+
#
|
193
|
+
def current_context(western_date: Western::Calendar.new)
|
194
|
+
years.each do |year|
|
195
|
+
return year.context if western_date >= year.new_year_date
|
196
|
+
end
|
197
|
+
|
198
|
+
Context::Context.new
|
199
|
+
end
|
200
|
+
|
201
|
+
#
|
202
|
+
# 二十四節気の移動元/移動先を生成する
|
203
|
+
#
|
204
|
+
# @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
205
|
+
#
|
206
|
+
def create_directions
|
207
|
+
directions = {}
|
208
|
+
|
209
|
+
years.each do |year|
|
210
|
+
self.class.create_directions_with_months(
|
211
|
+
context: year.context, directions: directions, months: year.months
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
215
|
+
directions
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|