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
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require_relative '../../output/logger'
|
4
4
|
|
5
|
+
require_relative './const'
|
6
|
+
|
5
7
|
# :nodoc:
|
6
8
|
module Zakuro
|
7
9
|
# :nodoc:
|
@@ -16,8 +18,10 @@ module Zakuro
|
|
16
18
|
LOGGER = Output::Logger.new(location: 'lunar_phase')
|
17
19
|
|
18
20
|
# @return [Array<String>] 月内の弦
|
19
|
-
PHASE_INDEXES =
|
21
|
+
PHASE_INDEXES = Const::PHASE_INDEXES
|
20
22
|
|
23
|
+
# @return [Cycle::AbstractRemainder] 弦
|
24
|
+
attr_reader :quarter
|
21
25
|
# @return [Cycle::AbstractRemainder] 経
|
22
26
|
attr_reader :average_remainder
|
23
27
|
# @return [Solar::AbstractLocation] 入定気
|
@@ -30,14 +34,14 @@ module Zakuro
|
|
30
34
|
#
|
31
35
|
# 初期化
|
32
36
|
#
|
33
|
-
# @param [Cycle::AbstractRemainder]
|
37
|
+
# @param [Cycle::AbstractRemainder] quarter 弦
|
34
38
|
# @param [Solar::AbstractLocation] average_remainder 経
|
35
39
|
# @param [Solar::AbstractLocation] solar_location 入定気
|
36
40
|
# @param [Lunar::AbstractLocation] lunar_location 入暦
|
37
41
|
#
|
38
|
-
def initialize(
|
42
|
+
def initialize(quarter:, average_remainder:, solar_location:, lunar_location:)
|
39
43
|
# 弦
|
40
|
-
@quarter =
|
44
|
+
@quarter = quarter
|
41
45
|
# 経
|
42
46
|
@average_remainder = average_remainder
|
43
47
|
# 入定気
|
@@ -87,7 +91,7 @@ module Zakuro
|
|
87
91
|
#
|
88
92
|
def next_index
|
89
93
|
@index += 1
|
90
|
-
@index = 0 if
|
94
|
+
@index = 0 if index >= PHASE_INDEXES.size
|
91
95
|
@index
|
92
96
|
end
|
93
97
|
|
@@ -98,7 +102,7 @@ module Zakuro
|
|
98
102
|
# @return [False] 朔月ではない
|
99
103
|
#
|
100
104
|
def first_phase?
|
101
|
-
|
105
|
+
index.zero?
|
102
106
|
end
|
103
107
|
|
104
108
|
#
|
@@ -157,9 +161,9 @@ module Zakuro
|
|
157
161
|
end
|
158
162
|
|
159
163
|
def add_quarter_moon_size
|
160
|
-
|
161
|
-
|
162
|
-
|
164
|
+
average_remainder.add!(quarter)
|
165
|
+
solar_location.add_quarter
|
166
|
+
lunar_location.add_quarter
|
163
167
|
|
164
168
|
next_index
|
165
169
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Zakuro
|
5
|
+
# :nodoc:
|
6
|
+
module Calculation
|
7
|
+
# :nodoc:
|
8
|
+
module Monthly
|
9
|
+
#
|
10
|
+
# Const 定数
|
11
|
+
#
|
12
|
+
module Const
|
13
|
+
# @return [Array<String>] 月内の弦
|
14
|
+
PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -67,43 +67,6 @@ module Zakuro
|
|
67
67
|
)
|
68
68
|
end
|
69
69
|
|
70
|
-
#
|
71
|
-
# 中気の連番に合わせて月を返す
|
72
|
-
#
|
73
|
-
# @example
|
74
|
-
# 20: 9月
|
75
|
-
# 22: 10月
|
76
|
-
# 0: 11月
|
77
|
-
# 2: 12月
|
78
|
-
# 4: 1月
|
79
|
-
#
|
80
|
-
# @param [Integer] index 中気番号
|
81
|
-
#
|
82
|
-
# @return [Integer] 月
|
83
|
-
#
|
84
|
-
def self.month_number_by_even_term_index(index)
|
85
|
-
half_index = index / 2
|
86
|
-
|
87
|
-
# 11月、12月
|
88
|
-
return half_index + 11 if half_index < 2
|
89
|
-
|
90
|
-
# 1月~10月
|
91
|
-
half_index - 1
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# 節気の連番に合わせて月を返す
|
96
|
-
#
|
97
|
-
# @param [Integer] index 節気番号
|
98
|
-
#
|
99
|
-
# @return [Integer] 月
|
100
|
-
#
|
101
|
-
def self.month_number_by_odd_term_index(index)
|
102
|
-
even_index = index - 1
|
103
|
-
|
104
|
-
month_number_by_even_term_index(even_index)
|
105
|
-
end
|
106
|
-
|
107
70
|
#
|
108
71
|
# 一ヶ月戻す
|
109
72
|
#
|
@@ -119,6 +82,45 @@ module Zakuro
|
|
119
82
|
def solar_term_size
|
120
83
|
solar_terms.size
|
121
84
|
end
|
85
|
+
|
86
|
+
class << self
|
87
|
+
#
|
88
|
+
# 中気の連番に合わせて月を返す
|
89
|
+
#
|
90
|
+
# @example
|
91
|
+
# 20: 9月
|
92
|
+
# 22: 10月
|
93
|
+
# 0: 11月
|
94
|
+
# 2: 12月
|
95
|
+
# 4: 1月
|
96
|
+
#
|
97
|
+
# @param [Integer] index 中気番号
|
98
|
+
#
|
99
|
+
# @return [Integer] 月
|
100
|
+
#
|
101
|
+
def month_number_by_even_term_index(index)
|
102
|
+
half_index = index / 2
|
103
|
+
|
104
|
+
# 11月、12月
|
105
|
+
return half_index + 11 if half_index < 2
|
106
|
+
|
107
|
+
# 1月~10月
|
108
|
+
half_index - 1
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# 節気の連番に合わせて月を返す
|
113
|
+
#
|
114
|
+
# @param [Integer] index 節気番号
|
115
|
+
#
|
116
|
+
# @return [Integer] 月
|
117
|
+
#
|
118
|
+
def month_number_by_odd_term_index(index)
|
119
|
+
even_index = index - 1
|
120
|
+
|
121
|
+
month_number_by_even_term_index(even_index)
|
122
|
+
end
|
123
|
+
end
|
122
124
|
end
|
123
125
|
end
|
124
126
|
end
|
@@ -34,8 +34,8 @@ module Zakuro
|
|
34
34
|
# @param [Array<SolarTerm>] solar_terms 二十四節気
|
35
35
|
# @param [Base::Gengou] gengou 元号
|
36
36
|
#
|
37
|
-
def initialize(context: Context::Context.new, month_label: MonthLabel.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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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 [
|
21
|
-
attr_reader :
|
21
|
+
# @return [OperatedSolarTerm] 運用時二十四節気
|
22
|
+
attr_reader :operated_solar_term
|
22
23
|
|
23
24
|
# :reek:LongParameterList {max_params: 6}
|
24
25
|
# rubocop:disable Metrics/ParameterLists
|
@@ -27,19 +28,19 @@ module Zakuro
|
|
27
28
|
# 初期化
|
28
29
|
#
|
29
30
|
# @param [Context::Context] context 暦コンテキスト
|
30
|
-
# @param [
|
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:,
|
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
|
-
@
|
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:
|
65
|
+
number: self.class.rewrite_month_fields(
|
65
66
|
month_diff: diff, month_label: month_label, name: 'number'
|
66
67
|
),
|
67
|
-
is_many_days:
|
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:
|
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,
|
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 =
|
97
|
-
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 =
|
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
|
-
|
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
|
@@ -72,7 +72,7 @@ module Zakuro
|
|
72
72
|
# @return [False] 有効
|
73
73
|
#
|
74
74
|
def invalid?
|
75
|
-
|
75
|
+
start_date.invalid?
|
76
76
|
end
|
77
77
|
|
78
78
|
#
|
@@ -100,30 +100,13 @@ module Zakuro
|
|
100
100
|
# @return [Array<Base::Year>] 完全範囲
|
101
101
|
#
|
102
102
|
def version_ranges
|
103
|
-
|
104
|
-
|
105
|
-
start_year = @scroll.western_start_year
|
106
|
-
last_year = @scroll.western_last_year
|
103
|
+
start_year = scroll.western_start_year
|
104
|
+
last_year = scroll.western_last_year
|
107
105
|
|
108
106
|
# TODO: context にデフォルト暦名が設定されている場合は使用しない
|
109
107
|
versions = Version.get(start_year: start_year, last_year: last_year)
|
110
108
|
|
111
|
-
versions
|
112
|
-
specified_context = Context::Context.new(
|
113
|
-
version: version.name, options: context.option.hash
|
114
|
-
)
|
115
|
-
start_year = version.start_year
|
116
|
-
last_year = version.last_year
|
117
|
-
# 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
|
118
|
-
last_year += 1 if (index + 1) == versions.size
|
119
|
-
|
120
|
-
years = boundary_resolved_ranges(
|
121
|
-
context: specified_context, start_year: start_year, last_year: last_year
|
122
|
-
)
|
123
|
-
result.concat(years)
|
124
|
-
end
|
125
|
-
|
126
|
-
result
|
109
|
+
collect_version_ranges(versions: versions, start_year: start_year, last_year: last_year)
|
127
110
|
end
|
128
111
|
|
129
112
|
#
|
@@ -168,6 +151,36 @@ module Zakuro
|
|
168
151
|
|
169
152
|
years
|
170
153
|
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# 暦別範囲を収集する
|
157
|
+
#
|
158
|
+
# @param [Array<Version::Range>] versions 暦の範囲
|
159
|
+
# @param [Integer] start_year 開始西暦年
|
160
|
+
# @param [Integer] last_year 終了西暦年
|
161
|
+
#
|
162
|
+
# @return [Array<Base::Year>] 完全範囲
|
163
|
+
#
|
164
|
+
def collect_version_ranges(versions:, start_year:, last_year:)
|
165
|
+
result = []
|
166
|
+
|
167
|
+
versions.each_with_index do |version, index|
|
168
|
+
specified_context = Context::Context.new(
|
169
|
+
version: version.name, options: context.option.hash
|
170
|
+
)
|
171
|
+
start_year = version.start_year
|
172
|
+
last_year = version.last_year
|
173
|
+
# 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
|
174
|
+
last_year += 1 if (index + 1) == versions.size
|
175
|
+
|
176
|
+
years = boundary_resolved_ranges(
|
177
|
+
context: specified_context, start_year: start_year, last_year: last_year
|
178
|
+
)
|
179
|
+
result.concat(years)
|
180
|
+
end
|
181
|
+
|
182
|
+
result
|
183
|
+
end
|
171
184
|
end
|
172
185
|
end
|
173
186
|
end
|