zakuro 0.6.0 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +3 -0
- data/README.md +58 -16
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/gengou.rb +50 -4
- data/lib/zakuro/calculation/base/linear_gengou.rb +6 -6
- data/lib/zakuro/calculation/base/operated_year.rb +3 -3
- data/lib/zakuro/calculation/base/year.rb +4 -4
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +5 -3
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
- data/lib/zakuro/calculation/{gengou → era/gengou}/internal/reserve.rb +6 -7
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/{version → era/version}/internal/crawler.rb +7 -7
- data/lib/zakuro/calculation/{version → era/version}/internal/range.rb +4 -4
- data/lib/zakuro/calculation/{version → era/version}/version.rb +3 -3
- data/lib/zakuro/calculation/monthly/initialized_month.rb +1 -1
- data/lib/zakuro/calculation/monthly/month.rb +44 -5
- data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
- data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
- data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
- data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +29 -27
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +11 -14
- data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
- data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +2 -2
- data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
- data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +9 -11
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +6 -6
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +2 -0
- data/lib/zakuro/calculation/summary/internal/day.rb +40 -0
- data/lib/zakuro/calculation/summary/internal/month.rb +92 -0
- data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -40
- data/lib/zakuro/calculation/summary/internal/option.rb +85 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +158 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +96 -0
- data/lib/zakuro/calculation/summary/western/range.rb +124 -0
- data/lib/zakuro/calculation/summary/western/single.rb +113 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +174 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +98 -0
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +75 -22
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +117 -0
- data/lib/zakuro/context/version_class_resolver.rb +110 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +125 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +245 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +299 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-001-until-south.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-002-from-north.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-003-modern.yaml +2 -2
- data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
- data/lib/zakuro/era/japan/gengou.rb +25 -79
- data/lib/zakuro/era/japan/version.rb +18 -18
- data/lib/zakuro/era/western/calendar.rb +13 -9
- data/lib/zakuro/exception/case/pattern.rb +71 -0
- data/lib/zakuro/exception/case/preset.rb +51 -0
- data/lib/zakuro/exception/case/template.rb +48 -0
- data/lib/zakuro/exception/cause.rb +28 -0
- data/lib/zakuro/exception/exception.rb +37 -0
- data/lib/zakuro/exception/zakuro_error.rb +46 -0
- data/lib/zakuro/gateway/locale/date.rb +127 -0
- data/lib/zakuro/gateway/locale/range.rb +67 -0
- data/lib/zakuro/gateway/range.rb +99 -0
- data/lib/zakuro/gateway/single.rb +70 -0
- data/lib/zakuro/merchant.rb +84 -12
- data/lib/zakuro/operation/month/parser.rb +11 -9
- data/lib/zakuro/operation/month/type.rb +31 -31
- data/lib/zakuro/operation/month/validator.rb +50 -50
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +24 -57
- data/lib/zakuro/result/data/day.rb +43 -0
- data/lib/zakuro/result/data/gengou.rb +35 -0
- data/lib/zakuro/result/data/month.rb +63 -0
- data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
- data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
- data/lib/zakuro/result/data/single_day.rb +56 -0
- data/lib/zakuro/result/data/solar_term.rb +35 -0
- data/lib/zakuro/result/data/year.rb +45 -0
- data/lib/zakuro/result/operation/bundle.rb +44 -0
- data/lib/zakuro/result/operation/month/annotation.rb +40 -0
- data/lib/zakuro/result/operation/month/bundle.rb +36 -0
- data/lib/zakuro/result/operation/month/history.rb +54 -0
- data/lib/zakuro/result/result.rb +21 -2
- data/lib/zakuro/tools/stringifier.rb +26 -3
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +1 -1
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +2 -0
- data/lib/zakuro/version/daien/stella/lunar/value.rb +2 -0
- data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +1 -1
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +1 -1
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +2 -0
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +2 -0
- data/lib/zakuro/version/senmyou/README.md +11 -7
- data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +1 -1
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +2 -0
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +2 -0
- metadata +85 -24
- data/lib/zakuro/calculation/gengou/internal/counter.rb +0 -129
- data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +0 -183
- data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +0 -382
- data/lib/zakuro/calculation/gengou/scroll.rb +0 -262
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -237
- data/lib/zakuro/era/japan/gengou/type.rb +0 -285
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -341
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/result/operation.rb +0 -114
- data/lib/zakuro/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -1,17 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../../
|
3
|
+
require_relative '../../context/context'
|
4
4
|
|
5
5
|
require_relative '../../era/western/calendar'
|
6
6
|
require_relative '../../output/logger'
|
7
7
|
|
8
|
-
require_relative '../
|
8
|
+
require_relative '../era/version/version'
|
9
9
|
|
10
10
|
require_relative '../base/gengou'
|
11
11
|
require_relative '../base/year'
|
12
12
|
|
13
|
-
require_relative '../version/version'
|
14
|
-
|
15
13
|
require_relative './transfer/year_boundary'
|
16
14
|
|
17
15
|
require_relative './transfer/gengou_scroller'
|
@@ -36,13 +34,13 @@ module Zakuro
|
|
36
34
|
# * 引き当てたい日付が元旦ではない場合、その月日に従い元号を再度求める
|
37
35
|
# * この再計算が必要になるのは、元号が切り替わる年のみである
|
38
36
|
#
|
39
|
-
class
|
40
|
-
# @return [Context] 暦コンテキスト
|
37
|
+
class AbstractFullRange
|
38
|
+
# @return [Context::Context] 暦コンテキスト
|
41
39
|
attr_reader :context
|
42
40
|
# @return [Western::Calendar] 開始日
|
43
41
|
attr_reader :start_date
|
44
42
|
# @return [Western::Calendar] 終了日
|
45
|
-
attr_reader :
|
43
|
+
attr_reader :last_date
|
46
44
|
# @return [MultiGengouRoller] 改元処理
|
47
45
|
attr_reader :scroll
|
48
46
|
|
@@ -52,18 +50,19 @@ module Zakuro
|
|
52
50
|
#
|
53
51
|
# 初期化
|
54
52
|
#
|
55
|
-
# @param [Context] context 暦コンテキスト
|
53
|
+
# @param [Context::Context] context 暦コンテキスト
|
54
|
+
# @param [Gengou::AbstractScroll] scroll 元号スクロール
|
56
55
|
# @param [Western::Calendar] start_date 開始日
|
57
|
-
# @param [Western::Calendar]
|
56
|
+
# @param [Western::Calendar] last_date 終了日
|
58
57
|
#
|
59
|
-
def initialize(context:,
|
58
|
+
def initialize(context:, scroll:,
|
59
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
60
60
|
@start_date = start_date
|
61
|
-
@
|
61
|
+
@last_date = last_date
|
62
62
|
return if invalid?
|
63
63
|
|
64
|
-
# TODO: 現時点では使用していない。特定の暦を指定できるようになった状態で使用する
|
65
64
|
@context = context
|
66
|
-
@scroll =
|
65
|
+
@scroll = scroll
|
67
66
|
end
|
68
67
|
|
69
68
|
#
|
@@ -104,19 +103,22 @@ module Zakuro
|
|
104
103
|
result = []
|
105
104
|
|
106
105
|
start_year = @scroll.western_start_year
|
107
|
-
|
106
|
+
last_year = @scroll.western_last_year
|
108
107
|
|
109
|
-
|
108
|
+
# TODO: context にデフォルト暦名が設定されている場合は使用しない
|
109
|
+
versions = Version.get(start_year: start_year, last_year: last_year)
|
110
110
|
|
111
111
|
versions.each_with_index do |version, index|
|
112
|
-
|
112
|
+
specified_context = Context::Context.new(
|
113
|
+
version: version.name, options: context.option.hash
|
114
|
+
)
|
113
115
|
start_year = version.start_year
|
114
|
-
|
116
|
+
last_year = version.last_year
|
115
117
|
# 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
|
116
|
-
|
118
|
+
last_year += 1 if (index + 1) == versions.size
|
117
119
|
|
118
120
|
years = boundary_resolved_ranges(
|
119
|
-
context:
|
121
|
+
context: specified_context, start_year: start_year, last_year: last_year
|
120
122
|
)
|
121
123
|
result.concat(years)
|
122
124
|
end
|
@@ -127,15 +129,15 @@ module Zakuro
|
|
127
129
|
#
|
128
130
|
# 年境界解決済みの範囲
|
129
131
|
#
|
130
|
-
# @param [Context] context 暦コンテキスト
|
132
|
+
# @param [Context::Context] context 暦コンテキスト
|
131
133
|
# @param [Integer] start_year 開始西暦年
|
132
|
-
# @param [Integer]
|
134
|
+
# @param [Integer] last_year 終了西暦年
|
133
135
|
#
|
134
136
|
# @return [Array<Base::Year>] 年境界解決済みの範囲
|
135
137
|
#
|
136
|
-
def boundary_resolved_ranges(context:, start_year:,
|
138
|
+
def boundary_resolved_ranges(context:, start_year:, last_year:)
|
137
139
|
ranges = annual_ranges(
|
138
|
-
context: context, start_year: start_year,
|
140
|
+
context: context, start_year: start_year, last_year: last_year
|
139
141
|
)
|
140
142
|
|
141
143
|
Transfer::YearBoundary.get(
|
@@ -146,17 +148,17 @@ module Zakuro
|
|
146
148
|
#
|
147
149
|
# 完全範囲内の年データを取得する
|
148
150
|
#
|
149
|
-
# @param [Context] context 暦コンテキスト
|
151
|
+
# @param [Context::Context] context 暦コンテキスト
|
150
152
|
# @param [Integer] start_year 開始西暦年
|
151
|
-
# @param [Integer]
|
153
|
+
# @param [Integer] last_year 終了西暦年
|
152
154
|
#
|
153
155
|
# @return [Array<Base::Year>] 年データ(冬至基準)
|
154
156
|
#
|
155
|
-
def annual_ranges(context:, start_year:,
|
157
|
+
def annual_ranges(context:, start_year:, last_year:)
|
156
158
|
annual_range = context.resolver.annual_range
|
157
159
|
|
158
160
|
years = []
|
159
|
-
(start_year..(
|
161
|
+
(start_year..(last_year + 1)).each do |year|
|
160
162
|
years.push(
|
161
163
|
annual_range.get(
|
162
164
|
context: context, western_year: year
|
@@ -13,30 +13,28 @@ module Zakuro
|
|
13
13
|
# :nodoc:
|
14
14
|
module Range
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# AbstractOperationRange 運用結果範囲
|
17
17
|
#
|
18
18
|
# 何らかの理由により、計算された暦とは異なる運用結果である場合、その結果に合わせて計算結果を上書きする
|
19
|
-
class
|
19
|
+
class AbstractOperationRange
|
20
20
|
# @return [Array<Year>] 年データ(完全範囲)
|
21
21
|
attr_reader :years
|
22
22
|
# @return [OperatedSolarTerms] 運用時二十四節気
|
23
23
|
attr_reader :operated_solar_terms
|
24
|
-
# @return [Context] 暦コンテキスト
|
24
|
+
# @return [Context::Context] 暦コンテキスト
|
25
25
|
attr_reader :context
|
26
26
|
|
27
27
|
#
|
28
28
|
# 初期化
|
29
29
|
#
|
30
|
-
# @param [Context] context 暦コンテキスト
|
31
|
-
# @param [
|
32
|
-
# @param [Western::Calendar] end_date 終了日
|
30
|
+
# @param [Context::Context] context 暦コンテキスト
|
31
|
+
# @param [Gengou::AbstractScroll] scroll 元号スクロール
|
33
32
|
# @param [Array<Year>] years 年データ(完全範囲)
|
34
33
|
#
|
35
|
-
def initialize(context:,
|
36
|
-
years: [])
|
34
|
+
def initialize(context:, scroll:, years: [])
|
37
35
|
@context = context
|
38
36
|
@years = years
|
39
|
-
@scroll =
|
37
|
+
@scroll = scroll
|
40
38
|
@operated_solar_terms = OperatedSolarTerms.new(context: context, years: @years)
|
41
39
|
@operated_solar_terms.create
|
42
40
|
end
|
@@ -49,9 +47,9 @@ module Zakuro
|
|
49
47
|
def get
|
50
48
|
operated_years = rewrite
|
51
49
|
|
52
|
-
|
50
|
+
AbstractOperationRange.move(operated_years: operated_years)
|
53
51
|
|
54
|
-
|
52
|
+
AbstractOperationRange.commit(operated_years: operated_years)
|
55
53
|
|
56
54
|
Transfer::GengouScroller.set(scroll: @scroll, years: operated_years)
|
57
55
|
|
@@ -67,7 +65,7 @@ module Zakuro
|
|
67
65
|
operated_years = []
|
68
66
|
|
69
67
|
years.each do |year|
|
70
|
-
operated_year =
|
68
|
+
operated_year = AbstractOperationRange.rewrite_year(
|
71
69
|
year: year,
|
72
70
|
operated_solar_terms: @operated_solar_terms
|
73
71
|
)
|
@@ -83,7 +81,6 @@ module Zakuro
|
|
83
81
|
# @param [Array<OperatedYear>] operated_years 運用結果範囲
|
84
82
|
#
|
85
83
|
def self.move(operated_years:)
|
86
|
-
# FIXME: この方式は完全ではない。範囲の1年前/1年後が必要
|
87
84
|
move_into_next_year(operated_years: operated_years)
|
88
85
|
move_into_last_year(operated_years: operated_years)
|
89
86
|
end
|
@@ -158,7 +155,7 @@ module Zakuro
|
|
158
155
|
def self.resolve_month(context:, month:, operated_solar_terms:)
|
159
156
|
history = Operation.specify_history(western_date: month.western_date)
|
160
157
|
|
161
|
-
|
158
|
+
AbstractOperationRange.rewrite_month(
|
162
159
|
context: context, month: month, history: history,
|
163
160
|
operated_solar_terms: operated_solar_terms
|
164
161
|
)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../era/gengou/dated_scroll'
|
4
|
+
require_relative './abstract_full_range'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Range
|
12
|
+
#
|
13
|
+
# DatedFullRange 完全範囲
|
14
|
+
#
|
15
|
+
class DatedFullRange < AbstractFullRange
|
16
|
+
#
|
17
|
+
# 初期化
|
18
|
+
#
|
19
|
+
# @param [Context::Context] context 暦コンテキスト
|
20
|
+
# @param [Western::Calendar] start_date 開始日
|
21
|
+
# @param [Western::Calendar] last_date 終了日
|
22
|
+
#
|
23
|
+
def initialize(context:,
|
24
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
25
|
+
scroll = Gengou::DatedScroll.new(start_date: start_date, last_date: last_date)
|
26
|
+
|
27
|
+
super(context: context, scroll: scroll, start_date: start_date, last_date: last_date)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../era/gengou/dated_scroll'
|
4
|
+
|
5
|
+
require_relative './abstract_operation_range'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Calculation
|
11
|
+
# :nodoc:
|
12
|
+
module Range
|
13
|
+
#
|
14
|
+
# DatedOperationRange 運用結果範囲
|
15
|
+
#
|
16
|
+
class DatedOperationRange < AbstractOperationRange
|
17
|
+
#
|
18
|
+
# 初期化
|
19
|
+
#
|
20
|
+
# @param [Context::Context] context 暦コンテキスト
|
21
|
+
# @param [Western::Calendar] start_date 開始日
|
22
|
+
# @param [Western::Calendar] last_date 終了日
|
23
|
+
# @param [Array<Year>] years 年データ(完全範囲)
|
24
|
+
#
|
25
|
+
def initialize(context:, start_date: Western::Calendar.new,
|
26
|
+
last_date: Western::Calendar.new, years: [])
|
27
|
+
scroll = Gengou::DatedScroll.new(start_date: start_date, last_date: last_date)
|
28
|
+
super(context: context, scroll: scroll, years: years)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -29,7 +29,7 @@ module Zakuro
|
|
29
29
|
# * 対象年に対して、前年11月-当年11月までを出力する
|
30
30
|
# * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
|
31
31
|
#
|
32
|
-
# @param [Context] context 暦コンテキスト
|
32
|
+
# @param [Context::Context] context 暦コンテキスト
|
33
33
|
# @param [Monthly::AbstractLunarPhase] lunar_phase 月の位相
|
34
34
|
# @param [Solar::AbstractAverage] solar_average 定気(太陽軌道平均)
|
35
35
|
#
|
@@ -51,7 +51,7 @@ module Zakuro
|
|
51
51
|
#
|
52
52
|
# 1年データを取得する
|
53
53
|
#
|
54
|
-
# @param [Context] context 暦コンテキスト
|
54
|
+
# @param [Context::Context] context 暦コンテキスト
|
55
55
|
# @param [Monthly::LunarPhase] lunar_phase 月の位相
|
56
56
|
#
|
57
57
|
# @return [Array<Month>] 1年データ
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../era/gengou/named_scroll'
|
4
|
+
require_relative './abstract_full_range'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Range
|
12
|
+
#
|
13
|
+
# NamedFullRange 完全範囲
|
14
|
+
#
|
15
|
+
class NamedFullRange < AbstractFullRange
|
16
|
+
# @return [String] 不正元号名
|
17
|
+
INVALID_NAME = Japan::Calendar::EMPTY
|
18
|
+
|
19
|
+
#
|
20
|
+
# 初期化
|
21
|
+
#
|
22
|
+
# @param [Context::Context] context 暦コンテキスト
|
23
|
+
# @param [String] start_name 開始元号名
|
24
|
+
# @param [String] last_name 終了元号名
|
25
|
+
#
|
26
|
+
def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME)
|
27
|
+
scroll = Gengou::NamedScroll.new(start_name: start_name, last_name: last_name)
|
28
|
+
range = scroll.range
|
29
|
+
|
30
|
+
super(
|
31
|
+
context: context, scroll: scroll,
|
32
|
+
start_date: range.western_start_date, last_date: range.western_last_date
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../era/gengou/named_scroll'
|
4
|
+
|
5
|
+
require_relative './abstract_operation_range'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Calculation
|
11
|
+
# :nodoc:
|
12
|
+
module Range
|
13
|
+
#
|
14
|
+
# NamedOperationRange 運用結果範囲
|
15
|
+
#
|
16
|
+
class NamedOperationRange < AbstractOperationRange
|
17
|
+
# @return [String] 不正元号名
|
18
|
+
INVALID_NAME = Japan::Calendar::EMPTY
|
19
|
+
|
20
|
+
#
|
21
|
+
# 初期化
|
22
|
+
#
|
23
|
+
# @param [Context::Context] context 暦コンテキスト
|
24
|
+
# @param [String] start_name 開始元号名
|
25
|
+
# @param [String] last_name 終了元号名
|
26
|
+
# @param [Array<Year>] years 年データ(完全範囲)
|
27
|
+
#
|
28
|
+
def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME, years: [])
|
29
|
+
scroll = Gengou::NamedScroll.new(start_name: start_name, last_name: last_name)
|
30
|
+
|
31
|
+
super(context: context, scroll: scroll, years: years)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -3,8 +3,6 @@
|
|
3
3
|
require_relative '../../operation/operation'
|
4
4
|
require_relative '../monthly/month'
|
5
5
|
|
6
|
-
# TODO: solar_termの中はsrc/destだが、yamlはcalc/actual。統一したい。
|
7
|
-
|
8
6
|
# :nodoc:
|
9
7
|
module Zakuro
|
10
8
|
# :nodoc:
|
@@ -23,13 +21,13 @@ module Zakuro
|
|
23
21
|
# * 移動先の二十四節気:移動元からの二十四節気(追加対象)
|
24
22
|
#
|
25
23
|
attr_reader :directions
|
26
|
-
# @return [Context] 暦コンテキスト
|
24
|
+
# @return [Context::Context] 暦コンテキスト
|
27
25
|
attr_reader :context
|
28
26
|
|
29
27
|
#
|
30
28
|
# 初期化
|
31
29
|
#
|
32
|
-
# @param [Context] context 暦コンテキスト
|
30
|
+
# @param [Context::Context] context 暦コンテキスト
|
33
31
|
# @param [Array<Year>] years 完全範囲(年データ)
|
34
32
|
#
|
35
33
|
def initialize(context:, years: [])
|
@@ -75,7 +73,7 @@ module Zakuro
|
|
75
73
|
#
|
76
74
|
# 年内の全ての月の移動方向を作成する
|
77
75
|
#
|
78
|
-
# @param [Context] context 暦コンテキスト
|
76
|
+
# @param [Context::Context] context 暦コンテキスト
|
79
77
|
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
80
78
|
# @param [Array<Month>] months 年内の全ての月
|
81
79
|
#
|
@@ -100,7 +98,7 @@ module Zakuro
|
|
100
98
|
#
|
101
99
|
# 月毎の移動方向を作成する
|
102
100
|
#
|
103
|
-
# @param [Context] context 暦コンテキスト
|
101
|
+
# @param [Context::Context] context 暦コンテキスト
|
104
102
|
# @param [Month] 月
|
105
103
|
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
106
104
|
# @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
|
@@ -121,7 +119,7 @@ module Zakuro
|
|
121
119
|
#
|
122
120
|
# 移動先に有効な二十四節気(差し替える二十四節気)を指定する
|
123
121
|
#
|
124
|
-
# @param [Context] context 暦コンテキスト
|
122
|
+
# @param [Context::Context] context 暦コンテキスト
|
125
123
|
# @param [SolarTerm] solar_term 二十四節気(計算値)
|
126
124
|
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
127
125
|
# @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
|
@@ -143,7 +141,7 @@ module Zakuro
|
|
143
141
|
#
|
144
142
|
# 移動先に有効な二十四節気(差し替える二十四節気)を生成する
|
145
143
|
#
|
146
|
-
# @param [Context] context 暦コンテキスト
|
144
|
+
# @param [Context::Context] context 暦コンテキスト
|
147
145
|
# @param [SolarTerm] solar_term 二十四節気(計算値)
|
148
146
|
# @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
|
149
147
|
#
|
@@ -167,7 +165,7 @@ module Zakuro
|
|
167
165
|
#
|
168
166
|
# 移動元に無効な二十四節気(連番のみ指定)を指定する
|
169
167
|
#
|
170
|
-
# @param [Context] context 暦コンテキスト
|
168
|
+
# @param [Context::Context] context 暦コンテキスト
|
171
169
|
# @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
172
170
|
# @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
|
173
171
|
#
|
@@ -188,14 +186,14 @@ module Zakuro
|
|
188
186
|
#
|
189
187
|
# @param [Western::Calendar] western_date 西暦日
|
190
188
|
#
|
191
|
-
# @return [Context] 暦コンテキスト
|
189
|
+
# @return [Context::Context] 暦コンテキスト
|
192
190
|
#
|
193
191
|
def current_context(western_date: Western::Calendar.new)
|
194
192
|
@years.each do |year|
|
195
193
|
return year.context if western_date >= year.new_year_date
|
196
194
|
end
|
197
195
|
|
198
|
-
Context.new
|
196
|
+
Context::Context.new
|
199
197
|
end
|
200
198
|
|
201
199
|
#
|
@@ -19,7 +19,7 @@ module Zakuro
|
|
19
19
|
#
|
20
20
|
# 年間範囲内の年データの開始月を変更する
|
21
21
|
#
|
22
|
-
# @param [Context] context 暦コンテキスト
|
22
|
+
# @param [Context::Context] context 暦コンテキスト
|
23
23
|
# @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
|
24
24
|
#
|
25
25
|
# @return [Array<Base::Year>] 年データ(元旦基準)
|
@@ -32,7 +32,7 @@ module Zakuro
|
|
32
32
|
#
|
33
33
|
# 年間範囲内の年データの開始月を変更する
|
34
34
|
#
|
35
|
-
# @param [Context] context 暦コンテキスト
|
35
|
+
# @param [Context::Context] context 暦コンテキスト
|
36
36
|
# @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
|
37
37
|
#
|
38
38
|
# @return [Array<Base::Year>] 年データ(元旦基準)
|
@@ -54,7 +54,7 @@ module Zakuro
|
|
54
54
|
#
|
55
55
|
# 年間範囲を昨年/今年で分類する
|
56
56
|
#
|
57
|
-
# @param [Context] context 暦コンテキスト
|
57
|
+
# @param [Context::Context] context 暦コンテキスト
|
58
58
|
# @param [Array<Base::Year>] annual_range 1年データ
|
59
59
|
#
|
60
60
|
def self.categorize(context:, annual_ranges:)
|
@@ -67,7 +67,7 @@ module Zakuro
|
|
67
67
|
#
|
68
68
|
# 各月を昨年/今年で分類する
|
69
69
|
#
|
70
|
-
# @param [Context] context 暦コンテキスト
|
70
|
+
# @param [Context::Context] context 暦コンテキスト
|
71
71
|
# @param [Array<Month>] annual_range 1年データ
|
72
72
|
#
|
73
73
|
def self.categorize_year(context:, annual_range:)
|
@@ -88,7 +88,7 @@ module Zakuro
|
|
88
88
|
#
|
89
89
|
# 年データの開始月を変更する
|
90
90
|
#
|
91
|
-
# @param [Context] context 暦コンテキスト
|
91
|
+
# @param [Context::Context] context 暦コンテキスト
|
92
92
|
# @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
|
93
93
|
# @param [Integer] index 対象年の要素番号
|
94
94
|
#
|
@@ -108,7 +108,7 @@ module Zakuro
|
|
108
108
|
#
|
109
109
|
# 当年データを生成する
|
110
110
|
#
|
111
|
-
# @param [Context] context 暦コンテキスト
|
111
|
+
# @param [Context::Context] context 暦コンテキスト
|
112
112
|
# @param [Array<Month>] annual_range 1年データ
|
113
113
|
#
|
114
114
|
# @return [Base::Year] 当年月ありの対象年
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../calculation/base/day'
|
4
|
+
require_relative '../../../era/western/calendar'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Summary
|
12
|
+
#
|
13
|
+
# Day 特定日
|
14
|
+
#
|
15
|
+
module Day
|
16
|
+
#
|
17
|
+
# 日を取得する
|
18
|
+
#
|
19
|
+
# @param [Month] month 月
|
20
|
+
# @param [Western::Calendar] date 現在西暦日
|
21
|
+
#
|
22
|
+
# @return [Calculation::Base::Day] 特定日
|
23
|
+
#
|
24
|
+
def self.get(month:, date: Western::Calendar.new)
|
25
|
+
first_date = month.western_date
|
26
|
+
days = date - first_date
|
27
|
+
remainder = month.remainder
|
28
|
+
remainder = remainder.add(
|
29
|
+
# 常に参照元のRemainderクラスで生成する
|
30
|
+
remainder.class.new(day: days, minute: 0, second: 0)
|
31
|
+
)
|
32
|
+
|
33
|
+
Calculation::Base::Day.new(
|
34
|
+
number: days + 1, western_date: date, remainder: remainder
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../output/response'
|
4
|
+
|
5
|
+
require_relative './day'
|
6
|
+
require_relative './option'
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
module Zakuro
|
10
|
+
# :nodoc:
|
11
|
+
module Calculation
|
12
|
+
# :nodoc:
|
13
|
+
module Summary
|
14
|
+
#
|
15
|
+
# Month 特定月
|
16
|
+
#
|
17
|
+
class Month
|
18
|
+
# @return [Context::Context] 暦コンテキスト
|
19
|
+
attr_reader :context
|
20
|
+
# @return [Western::Calendar] 西暦開始日
|
21
|
+
attr_reader :start_date
|
22
|
+
# @return [Western::Calendar] 西暦終了日
|
23
|
+
attr_reader :last_date
|
24
|
+
# @return [Base::Year] 年
|
25
|
+
attr_reader :year
|
26
|
+
# @return [Monthly::Month] 月
|
27
|
+
attr_reader :month
|
28
|
+
|
29
|
+
#
|
30
|
+
# 初期化
|
31
|
+
#
|
32
|
+
# @param [Context::Context] context 暦コンテキスト
|
33
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
34
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
35
|
+
# @param [Base::Year] year 年
|
36
|
+
# @param [Monthly::Month] month 月
|
37
|
+
#
|
38
|
+
def initialize(context:, start_date:, last_date:, year:, month:)
|
39
|
+
@context = context
|
40
|
+
@start_date = start_date
|
41
|
+
@last_date = last_date
|
42
|
+
@year = year
|
43
|
+
@month = month
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# 取得する
|
48
|
+
#
|
49
|
+
# @return [Array<Result::Data::SingleDay>] 1日データ
|
50
|
+
#
|
51
|
+
def get
|
52
|
+
result = []
|
53
|
+
first_date = @month.western_date.clone
|
54
|
+
|
55
|
+
(0..@month.days).each do |index|
|
56
|
+
current_date = first_date.clone + index
|
57
|
+
|
58
|
+
next unless include?(date: current_date)
|
59
|
+
|
60
|
+
day = Day.get(month: @month, date: current_date)
|
61
|
+
|
62
|
+
options = Option.create(month: @month, day: day)
|
63
|
+
|
64
|
+
single_day = Output::Response::SingleDay.create(
|
65
|
+
year: @year, month: @month, day: day, options: options
|
66
|
+
)
|
67
|
+
|
68
|
+
result.push(single_day)
|
69
|
+
end
|
70
|
+
|
71
|
+
result
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# 含まれるか
|
76
|
+
#
|
77
|
+
# @param [Western::Calendar] date 西暦日
|
78
|
+
#
|
79
|
+
# @return [True] 含む
|
80
|
+
# @return [False] 含まない
|
81
|
+
#
|
82
|
+
def include?(date:)
|
83
|
+
return false if date < @start_date
|
84
|
+
|
85
|
+
return false if date > @last_date
|
86
|
+
|
87
|
+
true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|