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,10 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
4
|
-
|
5
|
-
require_relative '../range/operated_range'
|
6
|
-
|
7
|
-
require_relative '../range/full_range'
|
3
|
+
require_relative '../../../operation/operation'
|
8
4
|
|
9
5
|
# :nodoc:
|
10
6
|
module Zakuro
|
@@ -13,38 +9,9 @@ module Zakuro
|
|
13
9
|
# :nodoc:
|
14
10
|
module Summary
|
15
11
|
#
|
16
|
-
#
|
12
|
+
# Operation 運用情報
|
17
13
|
#
|
18
|
-
module
|
19
|
-
#
|
20
|
-
# 生成する
|
21
|
-
#
|
22
|
-
# @param [Context] context 暦コンテキスト
|
23
|
-
# @param [Western::Calendar] date 西暦日
|
24
|
-
#
|
25
|
-
# @return [Result::Single] 一日検索結果(和暦日)
|
26
|
-
#
|
27
|
-
def self.get(context:, date: Western::Calendar.new)
|
28
|
-
full_range = Calculation::Range::FullRange.new(context: context, start_date: date)
|
29
|
-
years = full_range.get
|
30
|
-
|
31
|
-
calc_date = Calculation::Specifier::SingleDay.get(
|
32
|
-
years: years, date: date
|
33
|
-
)
|
34
|
-
|
35
|
-
operated_range = Calculation::Range::OperatedRange.new(
|
36
|
-
context: context, start_date: date, years: years
|
37
|
-
)
|
38
|
-
operated_years = operated_range.get
|
39
|
-
|
40
|
-
Result::Single.new(
|
41
|
-
data: Calculation::Specifier::SingleDay.get(
|
42
|
-
years: operated_years, date: date
|
43
|
-
),
|
44
|
-
operation: create_operation(calc_date: calc_date)
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
14
|
+
module Operation
|
48
15
|
#
|
49
16
|
# 運用情報を生成する
|
50
17
|
#
|
@@ -52,9 +19,9 @@ module Zakuro
|
|
52
19
|
#
|
53
20
|
# @return [Result::Operation::Bundle] 運用情報
|
54
21
|
#
|
55
|
-
def self.
|
22
|
+
def self.create(calc_date: Result::Data::SingleDay.new)
|
56
23
|
first_day = calc_date.month.first_day.western_date
|
57
|
-
operation_history = Operation.specify_history(western_date: first_day)
|
24
|
+
operation_history = Zakuro::Operation.specify_history(western_date: first_day)
|
58
25
|
|
59
26
|
operation_month = create_operation_month(operation_history: operation_history)
|
60
27
|
|
@@ -62,7 +29,6 @@ module Zakuro
|
|
62
29
|
operated: !operation_history.invalid?, month: operation_month, original: calc_date
|
63
30
|
)
|
64
31
|
end
|
65
|
-
private_class_method :create_operation
|
66
32
|
|
67
33
|
#
|
68
34
|
# 月履歴集約情報を生成する
|
@@ -74,7 +40,7 @@ module Zakuro
|
|
74
40
|
def self.create_operation_month(operation_history: Operation::MonthHistory.new)
|
75
41
|
return Result::Operation::Month::Bundle.new if operation_history.invalid?
|
76
42
|
|
77
|
-
parent_operation_history = Operation.specify_history_by_id(
|
43
|
+
parent_operation_history = Zakuro::Operation.specify_history_by_id(
|
78
44
|
id: operation_history.parent_id
|
79
45
|
)
|
80
46
|
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../context/option'
|
4
|
+
require_relative '../../../result/data/option/dropped_date/option'
|
5
|
+
require_relative '../../../result/data/solar_term'
|
6
|
+
|
7
|
+
require_relative '../../option/dropped_date/location'
|
8
|
+
|
9
|
+
# :nodoc:
|
10
|
+
module Zakuro
|
11
|
+
# :nodoc:
|
12
|
+
module Calculation
|
13
|
+
# :nodoc:
|
14
|
+
module Summary
|
15
|
+
#
|
16
|
+
# Option オプション
|
17
|
+
#
|
18
|
+
module Option
|
19
|
+
#
|
20
|
+
# 初期化
|
21
|
+
#
|
22
|
+
# @param [Calculation::Monthly::Month] month 月情報(各暦のデータ型)
|
23
|
+
# @param [Calculation::Base::Day] day 日情報
|
24
|
+
#
|
25
|
+
# @return [Hash<String, Result::Data::Option::AbstractOption>] オプション結果
|
26
|
+
#
|
27
|
+
def self.create(month:, day:)
|
28
|
+
# TODO: test
|
29
|
+
options = {}
|
30
|
+
context = month.context
|
31
|
+
|
32
|
+
if context.option.dropped_date?
|
33
|
+
remainder = day.remainder
|
34
|
+
solar_terms = month.solar_terms
|
35
|
+
option = dropped_date(context: context, remainder: remainder, solar_terms: solar_terms)
|
36
|
+
options[Context::Option::DROPPED_DATE_KEY] = option
|
37
|
+
end
|
38
|
+
|
39
|
+
options
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# 没日を求める
|
44
|
+
#
|
45
|
+
# @param [Context::Context] context 暦コンテキスト
|
46
|
+
# @param [Cycle::AbstractRemainder] remainder 当日和暦日
|
47
|
+
# @param [Array<Cycle::AbstractSolarTerm>] solar_terms 二十四節気
|
48
|
+
#
|
49
|
+
# @return [Result::Data::Option::DroppedDate::Option] 没日
|
50
|
+
#
|
51
|
+
def self.dropped_date(context:, remainder:, solar_terms:)
|
52
|
+
# TODO: refactor
|
53
|
+
option = Result::Data::Option::DroppedDate::Option.new(
|
54
|
+
matched: false,
|
55
|
+
calculation: Result::Data::Option::DroppedDate::Calculation.new
|
56
|
+
)
|
57
|
+
|
58
|
+
return option if remainder.invalid?
|
59
|
+
|
60
|
+
location = Calculation::Option::DroppedDate::Location.new(
|
61
|
+
context: context, solar_terms: solar_terms
|
62
|
+
)
|
63
|
+
|
64
|
+
return option unless location.exist?
|
65
|
+
|
66
|
+
dropped_date = location.get
|
67
|
+
|
68
|
+
return option unless remainder.day == dropped_date.day
|
69
|
+
|
70
|
+
solar_term = location.solar_term
|
71
|
+
Result::Data::Option::DroppedDate::Option.new(
|
72
|
+
matched: true,
|
73
|
+
calculation: Result::Data::Option::DroppedDate::Calculation.new(
|
74
|
+
remainder: dropped_date.format,
|
75
|
+
solar_term: Result::Data::SolarTerm.new(
|
76
|
+
index: solar_term.index,
|
77
|
+
remainder: solar_term.remainder.format
|
78
|
+
)
|
79
|
+
)
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../range/named_operation_range'
|
4
|
+
|
5
|
+
require_relative '../../range/named_full_range'
|
6
|
+
|
7
|
+
require_relative '../western/specifier/multiple_day'
|
8
|
+
|
9
|
+
require_relative '../internal/operation'
|
10
|
+
|
11
|
+
require_relative './specifier/single_day'
|
12
|
+
|
13
|
+
# :nodoc:
|
14
|
+
module Zakuro
|
15
|
+
# :nodoc:
|
16
|
+
module Calculation
|
17
|
+
# :nodoc:
|
18
|
+
module Summary
|
19
|
+
# :nodoc:
|
20
|
+
module Japan
|
21
|
+
#
|
22
|
+
# Range 期間
|
23
|
+
#
|
24
|
+
module Range
|
25
|
+
#
|
26
|
+
# 生成する
|
27
|
+
#
|
28
|
+
# @param [Context::Context] context 暦コンテキスト
|
29
|
+
# @param [Japan::Calendar] start_date 和暦開始日
|
30
|
+
# @param [Japan::Calendar] last_date 和暦終了日
|
31
|
+
#
|
32
|
+
# @return [Result::Range] 期間検索結果(和暦日)
|
33
|
+
#
|
34
|
+
def self.get(context:, start_date: Japan::Calendar.new,
|
35
|
+
last_date: Japan::Calendar.new)
|
36
|
+
years = get_full_range_years(
|
37
|
+
context: context, start_date: start_date, last_date: last_date
|
38
|
+
)
|
39
|
+
operated_years = get_operation_range_years(
|
40
|
+
context: context, years: years, start_date: start_date, last_date: last_date
|
41
|
+
)
|
42
|
+
|
43
|
+
japan_start_date = Specifier::SingleDay.get(
|
44
|
+
years: operated_years, date: start_date
|
45
|
+
)
|
46
|
+
japan_last_date = Specifier::SingleDay.get(
|
47
|
+
years: operated_years, date: last_date
|
48
|
+
)
|
49
|
+
|
50
|
+
list = create_list(
|
51
|
+
context: context,
|
52
|
+
operated_years: operated_years, years: years,
|
53
|
+
start_date: japan_start_date, last_date: japan_last_date
|
54
|
+
)
|
55
|
+
|
56
|
+
Result::Range.new(list: list)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# 1日検索結果リストを生成する
|
61
|
+
#
|
62
|
+
# @param [Context::Context] context 暦コンテキスト
|
63
|
+
# @param [Array<Base::OperatedYear>] operated_years 運用結果範囲
|
64
|
+
# @param [Array<Base::Year>] years 完全範囲
|
65
|
+
# @param [Result::Data::SingleDay] start_date 和暦開始日
|
66
|
+
# @param [Result::Data::SingleDay] last_date 和暦終了日
|
67
|
+
#
|
68
|
+
# @return [Array<Result::Single>] 結果リスト
|
69
|
+
#
|
70
|
+
def self.create_list(context:, operated_years: [], years: [],
|
71
|
+
start_date:, last_date:)
|
72
|
+
western_start_date = start_date.day.western_date
|
73
|
+
western_last_date = last_date.day.western_date
|
74
|
+
|
75
|
+
operated_dates = Western::Specifier::MultipleDay.get(
|
76
|
+
context: context, years: operated_years, start_date: western_start_date, last_date: western_last_date
|
77
|
+
)
|
78
|
+
|
79
|
+
dates = Western::Specifier::MultipleDay.get(
|
80
|
+
context: context, years: years, start_date: western_start_date, last_date: western_last_date
|
81
|
+
)
|
82
|
+
|
83
|
+
create_result_list(dates: dates, operated_dates: operated_dates)
|
84
|
+
end
|
85
|
+
private_class_method :create_list
|
86
|
+
|
87
|
+
#
|
88
|
+
# 完全範囲を取得する
|
89
|
+
#
|
90
|
+
# @param [Context::Context] context 暦コンテキスト
|
91
|
+
# @param [Japan::Calendar] start_date 和暦開始日
|
92
|
+
# @param [Japan::Calendar] last_date 和暦終了日
|
93
|
+
#
|
94
|
+
# @return [Array<Base::Year>] 完全範囲
|
95
|
+
#
|
96
|
+
def self.get_full_range_years(context:, start_date: Japan::Calendar.new,
|
97
|
+
last_date: Japan::Calendar.new)
|
98
|
+
full_range = Calculation::Range::NamedFullRange.new(
|
99
|
+
context: context, start_name: start_date.gengou, last_name: last_date.gengou
|
100
|
+
)
|
101
|
+
full_range.get
|
102
|
+
end
|
103
|
+
private_class_method :get_full_range_years
|
104
|
+
|
105
|
+
#
|
106
|
+
# 運用結果範囲を取得する
|
107
|
+
#
|
108
|
+
# @param [Context::Context] context 暦コンテキスト
|
109
|
+
# @param [Array<Base::Year>] years 完全範囲
|
110
|
+
# @param [Japan::Calendar] start_date 和暦開始日
|
111
|
+
# @param [Japan::Calendar] last_date 和暦終了日
|
112
|
+
#
|
113
|
+
# @return [Array<Base::OperatedYear>] 運用結果範囲
|
114
|
+
#
|
115
|
+
def self.get_operation_range_years(context:, years:, start_date: Japan::Calendar.new,
|
116
|
+
last_date: Japan::Calendar.new)
|
117
|
+
operation_range = Calculation::Range::NamedOperationRange.new(
|
118
|
+
context: context, years: years,
|
119
|
+
start_name: start_date.gengou, last_name: last_date.gengou
|
120
|
+
)
|
121
|
+
operation_range.get
|
122
|
+
end
|
123
|
+
private_class_method :get_operation_range_years
|
124
|
+
|
125
|
+
#
|
126
|
+
# 結果リストを生成する
|
127
|
+
#
|
128
|
+
# @param [Array<Result::Data::SingleDay>] dates 検索結果(計算値)
|
129
|
+
# @param [Array<Result::Data::SingleDay>] operated_dates 検索結果(運用値)
|
130
|
+
#
|
131
|
+
# @return [Array<Result::Single>] 結果リスト
|
132
|
+
#
|
133
|
+
def self.create_result_list(dates:, operated_dates:)
|
134
|
+
result = []
|
135
|
+
|
136
|
+
return result if dates.size != operated_dates.size
|
137
|
+
|
138
|
+
(0..(dates.size - 1)).each do |index|
|
139
|
+
data = operated_dates[index]
|
140
|
+
|
141
|
+
date = dates[index]
|
142
|
+
operation = Operation.create(calc_date: date)
|
143
|
+
|
144
|
+
result.push(
|
145
|
+
Result::Single.new(
|
146
|
+
data: data,
|
147
|
+
operation: operation
|
148
|
+
)
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
result
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../range/named_operation_range'
|
4
|
+
|
5
|
+
require_relative '../../range/named_full_range'
|
6
|
+
|
7
|
+
require_relative '../western/specifier/single_day'
|
8
|
+
|
9
|
+
require_relative '../internal/operation'
|
10
|
+
|
11
|
+
require_relative './specifier/single_day'
|
12
|
+
|
13
|
+
# :nodoc:
|
14
|
+
module Zakuro
|
15
|
+
# :nodoc:
|
16
|
+
module Calculation
|
17
|
+
# :nodoc:
|
18
|
+
module Summary
|
19
|
+
# :nodoc:
|
20
|
+
module Japan
|
21
|
+
#
|
22
|
+
# Single 一日
|
23
|
+
#
|
24
|
+
module Single
|
25
|
+
#
|
26
|
+
# 生成する
|
27
|
+
#
|
28
|
+
# @param [Context::Context] context 暦コンテキスト
|
29
|
+
# @param [Japan::Calendar] date 和暦日
|
30
|
+
#
|
31
|
+
# @return [Result::Single] 一日検索結果(和暦日)
|
32
|
+
#
|
33
|
+
def self.get(context:, date: Japan::Calendar.new)
|
34
|
+
years = get_full_range_years(context: context, date: date)
|
35
|
+
|
36
|
+
data = get_data(context: context, years: years, date: date)
|
37
|
+
|
38
|
+
western_date = data.day.western_date
|
39
|
+
operation = get_operation(years: years, date: western_date)
|
40
|
+
|
41
|
+
Result::Single.new(
|
42
|
+
data: data,
|
43
|
+
operation: operation
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# 完全範囲を取得する
|
49
|
+
#
|
50
|
+
# @param [Context::Context] context 暦コンテキスト
|
51
|
+
# @param [Japan::Calendar] date 和暦日
|
52
|
+
#
|
53
|
+
# @return [Array<Base::Year>] 完全範囲
|
54
|
+
#
|
55
|
+
def self.get_full_range_years(context:, date: Japan::Calendar.new)
|
56
|
+
full_range = Calculation::Range::NamedFullRange.new(
|
57
|
+
context: context, start_name: date.gengou
|
58
|
+
)
|
59
|
+
full_range.get
|
60
|
+
end
|
61
|
+
private_class_method :get_full_range_years
|
62
|
+
|
63
|
+
#
|
64
|
+
# 1日を取得する
|
65
|
+
#
|
66
|
+
# @param [Context::Context] context 暦コンテキスト
|
67
|
+
# @param [Array<Base::Year>] years 完全範囲
|
68
|
+
# @param [Japan::Calendar] date 和暦日
|
69
|
+
#
|
70
|
+
# @return [Data::SingleDay] 1日
|
71
|
+
#
|
72
|
+
def self.get_data(context:, years:, date: Japan::Calendar.new)
|
73
|
+
operated_years = get_operation_range_years(context: context, years: years, date: date)
|
74
|
+
|
75
|
+
Specifier::SingleDay.get(
|
76
|
+
years: operated_years, date: date
|
77
|
+
)
|
78
|
+
end
|
79
|
+
private_class_method :get_data
|
80
|
+
|
81
|
+
#
|
82
|
+
# 運用結果範囲を取得する
|
83
|
+
#
|
84
|
+
# @param [Context::Context] context 暦コンテキスト
|
85
|
+
# @param [Array<Calculation::Base::Year>] years 完全範囲
|
86
|
+
# @param [Japan::Calendar] date 和暦日
|
87
|
+
#
|
88
|
+
# @return [Array<Base::OperatedYear>] 運用結果範囲
|
89
|
+
#
|
90
|
+
def self.get_operation_range_years(context:, years:, date: Japan::Calendar.new)
|
91
|
+
operation_range = Calculation::Range::NamedOperationRange.new(
|
92
|
+
context: context, start_name: date.gengou, years: years
|
93
|
+
)
|
94
|
+
operation_range.get
|
95
|
+
end
|
96
|
+
private_class_method :get_operation_range_years
|
97
|
+
|
98
|
+
#
|
99
|
+
# 完全範囲を取得する
|
100
|
+
#
|
101
|
+
# @param [Array<Calculation::Base::Year>] years 完全範囲
|
102
|
+
# @param [Western::Calendar] date 和暦日
|
103
|
+
#
|
104
|
+
# @return [Array<Base::Year>] 完全範囲
|
105
|
+
#
|
106
|
+
def self.get_operation(years:, date: Western::Calendar.new)
|
107
|
+
calc_date = Western::Specifier::SingleDay.get(
|
108
|
+
years: years, date: date
|
109
|
+
)
|
110
|
+
|
111
|
+
Operation.create(calc_date: calc_date)
|
112
|
+
end
|
113
|
+
private_class_method :get_operation
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/japan/calendar'
|
4
|
+
require_relative '../../../../era/western/calendar'
|
5
|
+
require_relative '../../../../output/response'
|
6
|
+
require_relative '../../../../output/logger'
|
7
|
+
|
8
|
+
require_relative '../../../base/year'
|
9
|
+
|
10
|
+
require_relative '../../internal/day'
|
11
|
+
require_relative '../../internal/option'
|
12
|
+
|
13
|
+
# :nodoc:
|
14
|
+
module Zakuro
|
15
|
+
# :nodoc:
|
16
|
+
module Calculation
|
17
|
+
# :nodoc:
|
18
|
+
module Summary
|
19
|
+
# :nodoc:
|
20
|
+
module Japan
|
21
|
+
# :nodoc:
|
22
|
+
module Specifier
|
23
|
+
#
|
24
|
+
# SingleDay 一日検索
|
25
|
+
#
|
26
|
+
module SingleDay
|
27
|
+
# @return [Output::Logger] ロガー
|
28
|
+
LOGGER = Output::Logger.new(location: 'specifier')
|
29
|
+
|
30
|
+
#
|
31
|
+
# 取得する
|
32
|
+
#
|
33
|
+
# @param [Array<Year>] yeas 範囲
|
34
|
+
# @param [Japan::Calendar] date 和暦日
|
35
|
+
#
|
36
|
+
# @return [Result::Data::SingleDay] 和暦日
|
37
|
+
#
|
38
|
+
def self.get(years: [], date: Japan::Calendar.new)
|
39
|
+
year, month = specify(years: years, date: date)
|
40
|
+
first_date = month.western_date.clone
|
41
|
+
days = date.day - 1
|
42
|
+
western_date = first_date + days
|
43
|
+
day = Day.get(month: month, date: western_date)
|
44
|
+
|
45
|
+
options = Option.create(month: month, day: day)
|
46
|
+
|
47
|
+
Output::Response::SingleDay.create(
|
48
|
+
year: year, month: month, day: day, options: options
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# 年を特定する
|
54
|
+
#
|
55
|
+
# @param [Array<Year>] years 範囲
|
56
|
+
# @param [Japan::Calendar] date 和暦日
|
57
|
+
#
|
58
|
+
# @return [Base::Year] 対象年
|
59
|
+
# @return [Monthly::Month] 対象月
|
60
|
+
#
|
61
|
+
# @raise [ArgumentError] 引数エラー
|
62
|
+
#
|
63
|
+
def self.specify(years:, date:)
|
64
|
+
years.each do |year|
|
65
|
+
month = specify_month(year: year, date: date)
|
66
|
+
return year, month unless month.invalid?
|
67
|
+
end
|
68
|
+
|
69
|
+
raise ArgumentError, "invalid year range. date: #{date.format}"
|
70
|
+
end
|
71
|
+
private_class_method :specify
|
72
|
+
|
73
|
+
#
|
74
|
+
# 月を特定する
|
75
|
+
#
|
76
|
+
# @param [Base::Year] year 年
|
77
|
+
# @param [Japan::Calendar] date 和暦日
|
78
|
+
#
|
79
|
+
# @return [Monthly::Month] 対象月
|
80
|
+
#
|
81
|
+
def self.specify_month(year:, date:)
|
82
|
+
months = year.months
|
83
|
+
|
84
|
+
months.each do |month|
|
85
|
+
return month if month.include_by_japan_date?(date: date)
|
86
|
+
end
|
87
|
+
|
88
|
+
Monthly::Month.new
|
89
|
+
end
|
90
|
+
private_class_method :specify_month
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../range/dated_operation_range'
|
4
|
+
|
5
|
+
require_relative '../../range/dated_full_range'
|
6
|
+
|
7
|
+
require_relative './specifier/multiple_day'
|
8
|
+
|
9
|
+
require_relative '../internal/operation'
|
10
|
+
|
11
|
+
# :nodoc:
|
12
|
+
module Zakuro
|
13
|
+
# :nodoc:
|
14
|
+
module Calculation
|
15
|
+
# :nodoc:
|
16
|
+
module Summary
|
17
|
+
# :nodoc:
|
18
|
+
module Western
|
19
|
+
#
|
20
|
+
# Range 期間
|
21
|
+
#
|
22
|
+
module Range
|
23
|
+
#
|
24
|
+
# 生成する
|
25
|
+
#
|
26
|
+
# @param [Context::Context] context 暦コンテキスト
|
27
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
28
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
29
|
+
#
|
30
|
+
# @return [Result::Range] 期間検索結果(和暦日)
|
31
|
+
#
|
32
|
+
def self.get(context:, start_date: Western::Calendar.new,
|
33
|
+
last_date: Western::Calendar.new)
|
34
|
+
years = get_full_range_years(
|
35
|
+
context: context, start_date: start_date, last_date: last_date
|
36
|
+
)
|
37
|
+
operated_years = get_operation_range_years(
|
38
|
+
context: context, years: years, start_date: start_date, last_date: last_date
|
39
|
+
)
|
40
|
+
|
41
|
+
dates = Specifier::MultipleDay.get(
|
42
|
+
context: context, years: years, start_date: start_date, last_date: last_date
|
43
|
+
)
|
44
|
+
|
45
|
+
operated_dates = Specifier::MultipleDay.get(
|
46
|
+
context: context, years: operated_years, start_date: start_date, last_date: last_date
|
47
|
+
)
|
48
|
+
|
49
|
+
list = create_result_list(dates: dates, operated_dates: operated_dates)
|
50
|
+
|
51
|
+
Result::Range.new(list: list)
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# 完全範囲を取得する
|
56
|
+
#
|
57
|
+
# @param [Context::Context] context 暦コンテキスト
|
58
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
59
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
60
|
+
#
|
61
|
+
# @return [Array<Base::Year>] 完全範囲
|
62
|
+
#
|
63
|
+
def self.get_full_range_years(context:, start_date: Western::Calendar.new,
|
64
|
+
last_date: Western::Calendar.new)
|
65
|
+
full_range = Calculation::Range::DatedFullRange.new(
|
66
|
+
context: context, start_date: start_date, last_date: last_date
|
67
|
+
)
|
68
|
+
full_range.get
|
69
|
+
end
|
70
|
+
private_class_method :get_full_range_years
|
71
|
+
|
72
|
+
#
|
73
|
+
# 運用結果範囲を取得する
|
74
|
+
#
|
75
|
+
# @param [Context::Context] context 暦コンテキスト
|
76
|
+
# @param [Array<Base::Year>] years 完全範囲
|
77
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
78
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
79
|
+
#
|
80
|
+
# @return [Array<Base::OperatedYear>] 運用結果範囲
|
81
|
+
#
|
82
|
+
def self.get_operation_range_years(context:, years:, start_date: Western::Calendar.new,
|
83
|
+
last_date: Western::Calendar.new)
|
84
|
+
operation_range = Calculation::Range::DatedOperationRange.new(
|
85
|
+
context: context, start_date: start_date, last_date: last_date, years: years
|
86
|
+
)
|
87
|
+
operation_range.get
|
88
|
+
end
|
89
|
+
private_class_method :get_operation_range_years
|
90
|
+
|
91
|
+
#
|
92
|
+
# 結果リストを生成する
|
93
|
+
#
|
94
|
+
# @param [Array<Result::Data::SingleDay>] dates 検索結果(計算値)
|
95
|
+
# @param [Array<Result::Data::SingleDay>] operated_dates 検索結果(運用値)
|
96
|
+
#
|
97
|
+
# @return [Array<Result::Single>] 結果リスト
|
98
|
+
#
|
99
|
+
def self.create_result_list(dates:, operated_dates:)
|
100
|
+
result = []
|
101
|
+
|
102
|
+
return result if dates.size != operated_dates.size
|
103
|
+
|
104
|
+
(0..(dates.size - 1)).each do |index|
|
105
|
+
data = operated_dates[index]
|
106
|
+
|
107
|
+
date = dates[index]
|
108
|
+
operation = Operation.create(calc_date: date)
|
109
|
+
|
110
|
+
result.push(
|
111
|
+
Result::Single.new(
|
112
|
+
data: data,
|
113
|
+
operation: operation
|
114
|
+
)
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
result
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|