zakuro 0.5.0 → 0.7.0
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 +22 -7
- data/VERSION +1 -0
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/gengou.rb +128 -0
- data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
- data/lib/zakuro/calculation/base/operated_year.rb +5 -15
- data/lib/zakuro/calculation/base/year.rb +26 -14
- 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/era/gengou/internal/reserve.rb +41 -0
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
- data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
- data/lib/zakuro/calculation/era/version/version.rb +24 -0
- data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
- data/lib/zakuro/calculation/monthly/month.rb +88 -2
- data/lib/zakuro/calculation/monthly/operated_month.rb +3 -3
- data/lib/zakuro/calculation/range/abstract_full_range.rb +172 -0
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +17 -15
- 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/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 +36 -19
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
- data/lib/zakuro/calculation/summary/internal/month.rb +84 -0
- data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -37
- data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -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 +169 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
- data/lib/zakuro/condition.rb +15 -2
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +121 -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 +243 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +293 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
- data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
- data/lib/zakuro/era/japan/gengou.rb +26 -80
- data/lib/zakuro/era/japan/version.rb +151 -0
- data/lib/zakuro/era/{western.rb → western/calendar.rb} +9 -9
- data/lib/zakuro/exception/case/pattern.rb +35 -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 +28 -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 +15 -4
- data/lib/zakuro/operation/month/parser.rb +10 -10
- data/lib/zakuro/operation/month/type.rb +32 -32
- data/lib/zakuro/operation/month/validator.rb +51 -51
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +5 -5
- 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/single_day.rb +48 -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/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/operation/operation.rb +44 -0
- data/lib/zakuro/result/result.rb +21 -2
- data/lib/zakuro/tools/typeconv.rb +38 -0
- data/lib/zakuro/tools/typeof.rb +4 -1
- data/lib/zakuro/version/context.rb +24 -3
- data/lib/zakuro/version/daien/daien.rb +1 -26
- data/lib/zakuro/version/genka/genka.rb +1 -26
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
- data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
- data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
- data/lib/zakuro/version/kansei/kansei.rb +1 -9
- data/lib/zakuro/version/senmyou/README.md +11 -7
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/zakuro.gemspec +1 -3
- metadata +74 -22
- data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
- data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
- data/lib/zakuro/calculation/range/full_range.rb +0 -210
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -109
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
- data/lib/zakuro/era/japan/gengou/type.rb +0 -178
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
- data/lib/zakuro/era/japan/reki.rb +0 -91
- data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
- data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
- data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/result/operation.rb +0 -114
- data/lib/zakuro/version/abstract_version.rb +0 -29
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,91 @@
|
|
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
|
+
# :nodoc:
|
11
|
+
module Zakuro
|
12
|
+
# :nodoc:
|
13
|
+
module Calculation
|
14
|
+
# :nodoc:
|
15
|
+
module Summary
|
16
|
+
# :nodoc:
|
17
|
+
module Japan
|
18
|
+
# :nodoc:
|
19
|
+
module Specifier
|
20
|
+
#
|
21
|
+
# SingleDay 一日検索
|
22
|
+
#
|
23
|
+
module SingleDay
|
24
|
+
# @return [Output::Logger] ロガー
|
25
|
+
LOGGER = Output::Logger.new(location: 'specifier')
|
26
|
+
|
27
|
+
#
|
28
|
+
# 取得する
|
29
|
+
#
|
30
|
+
# @param [Array<Year>] yeas 範囲
|
31
|
+
# @param [Japan::Calendar] date 和暦日
|
32
|
+
#
|
33
|
+
# @return [Result::Data::SingleDay] 和暦日
|
34
|
+
#
|
35
|
+
def self.get(years: [], date: Japan::Calendar.new)
|
36
|
+
year, month = specify(years: years, date: date)
|
37
|
+
first_date = month.western_date.clone
|
38
|
+
days = date.day - 1
|
39
|
+
western_date = first_date + days
|
40
|
+
|
41
|
+
Output::Response::SingleDay.save_single_day(
|
42
|
+
param: Output::Response::SingleDay::Param.new(
|
43
|
+
year: year, month: month,
|
44
|
+
date: western_date, days: days
|
45
|
+
)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# 年を特定する
|
51
|
+
#
|
52
|
+
# @param [Array<Year>] years 範囲
|
53
|
+
# @param [Japan::Calendar] date 和暦日
|
54
|
+
#
|
55
|
+
# @return [Base::Year] 対象年
|
56
|
+
# @return [Monthly::Month] 対象月
|
57
|
+
#
|
58
|
+
def self.specify(years:, date:)
|
59
|
+
years.each do |year|
|
60
|
+
month = specify_month(year: year, date: date)
|
61
|
+
return year, month unless month.invalid?
|
62
|
+
end
|
63
|
+
|
64
|
+
raise ArgumentError, "invalid year range. date: #{date.format}"
|
65
|
+
end
|
66
|
+
private_class_method :specify
|
67
|
+
|
68
|
+
#
|
69
|
+
# 月を特定する
|
70
|
+
#
|
71
|
+
# @param [Base::Year] year 年
|
72
|
+
# @param [Japan::Calendar] date 和暦日
|
73
|
+
#
|
74
|
+
# @return [Monthly::Month] 対象月
|
75
|
+
#
|
76
|
+
def self.specify_month(year:, date:)
|
77
|
+
months = year.months
|
78
|
+
|
79
|
+
months.each do |month|
|
80
|
+
return month if month.include_by_japan_date?(date: date)
|
81
|
+
end
|
82
|
+
|
83
|
+
Monthly::Month.new
|
84
|
+
end
|
85
|
+
private_class_method :specify_month
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
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 暦コンテキスト
|
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
|
+
years: years, start_date: start_date, last_date: last_date
|
43
|
+
)
|
44
|
+
|
45
|
+
operated_dates = Specifier::MultipleDay.get(
|
46
|
+
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 暦コンテキスト
|
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 暦コンテキスト
|
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
|
@@ -0,0 +1,113 @@
|
|
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/single_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
|
+
# Single 一日
|
21
|
+
#
|
22
|
+
module Single
|
23
|
+
#
|
24
|
+
# 生成する
|
25
|
+
#
|
26
|
+
# @param [Context] context 暦コンテキスト
|
27
|
+
# @param [Western::Calendar] date 西暦日
|
28
|
+
#
|
29
|
+
# @return [Result::Single] 一日検索結果(和暦日)
|
30
|
+
#
|
31
|
+
def self.get(context:, date: Western::Calendar.new)
|
32
|
+
years = get_full_range_years(context: context, date: date)
|
33
|
+
|
34
|
+
data = get_data(context: context, years: years, date: date)
|
35
|
+
|
36
|
+
operation = get_operation(years: years, date: date)
|
37
|
+
|
38
|
+
Result::Single.new(
|
39
|
+
data: data,
|
40
|
+
operation: operation
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# 完全範囲を取得する
|
46
|
+
#
|
47
|
+
# @param [Context] context 暦コンテキスト
|
48
|
+
# @param [Western::Calendar] date 西暦日
|
49
|
+
#
|
50
|
+
# @return [Array<Base::Year>] 完全範囲
|
51
|
+
#
|
52
|
+
def self.get_full_range_years(context:, date: Western::Calendar.new)
|
53
|
+
full_range = Calculation::Range::DatedFullRange.new(context: context, start_date: date)
|
54
|
+
full_range.get
|
55
|
+
end
|
56
|
+
private_class_method :get_full_range_years
|
57
|
+
|
58
|
+
#
|
59
|
+
# 運用結果範囲を取得する
|
60
|
+
#
|
61
|
+
# @param [Context] context 暦コンテキスト
|
62
|
+
# @param [Array<Base::Year>] years 完全範囲
|
63
|
+
# @param [Western::Calendar] date 西暦日
|
64
|
+
#
|
65
|
+
# @return [Array<Base::OperatedYear>] 運用結果範囲
|
66
|
+
#
|
67
|
+
def self.get_operation_range_years(context:, years:, date: Western::Calendar.new)
|
68
|
+
operation_range = Calculation::Range::DatedOperationRange.new(
|
69
|
+
context: context, start_date: date, years: years
|
70
|
+
)
|
71
|
+
operation_range.get
|
72
|
+
end
|
73
|
+
private_class_method :get_operation_range_years
|
74
|
+
|
75
|
+
#
|
76
|
+
# 1日を取得する
|
77
|
+
#
|
78
|
+
# @param [Context] context 暦コンテキスト
|
79
|
+
# @param [Array<Base::Year>] years 完全範囲
|
80
|
+
# @param [Western::Calendar] date 西暦日
|
81
|
+
#
|
82
|
+
# @return [Data::SingleDay] 1日
|
83
|
+
#
|
84
|
+
def self.get_data(context:, years:, date: Western::Calendar.new)
|
85
|
+
operated_years = get_operation_range_years(context: context, years: years, date: date)
|
86
|
+
|
87
|
+
Specifier::SingleDay.get(
|
88
|
+
years: operated_years, date: date
|
89
|
+
)
|
90
|
+
end
|
91
|
+
private_class_method :get_data
|
92
|
+
|
93
|
+
#
|
94
|
+
# 完全範囲を取得する
|
95
|
+
#
|
96
|
+
# @param [Context] context 暦コンテキスト
|
97
|
+
# @param [Western::Calendar] date 西暦日
|
98
|
+
#
|
99
|
+
# @return [Array<Base::Year>] 完全範囲
|
100
|
+
#
|
101
|
+
def self.get_operation(years:, date: Western::Calendar.new)
|
102
|
+
calc_date = Specifier::SingleDay.get(
|
103
|
+
years: years, date: date
|
104
|
+
)
|
105
|
+
|
106
|
+
Operation.create(calc_date: calc_date)
|
107
|
+
end
|
108
|
+
private_class_method :get_operation
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/western/calendar'
|
4
|
+
require_relative '../../../../output/response'
|
5
|
+
require_relative '../../../../output/logger'
|
6
|
+
|
7
|
+
require_relative '../../../base/year'
|
8
|
+
|
9
|
+
require_relative '../../internal/month'
|
10
|
+
|
11
|
+
# :nodoc:
|
12
|
+
module Zakuro
|
13
|
+
# :nodoc:
|
14
|
+
module Calculation
|
15
|
+
# :nodoc:
|
16
|
+
module Summary
|
17
|
+
# :nodoc:
|
18
|
+
module Western
|
19
|
+
# :nodoc:
|
20
|
+
module Specifier
|
21
|
+
#
|
22
|
+
# MultipleDay 複数日検索
|
23
|
+
#
|
24
|
+
module MultipleDay
|
25
|
+
# @return [Output::Logger] ロガー
|
26
|
+
LOGGER = Output::Logger.new(location: 'specifier')
|
27
|
+
|
28
|
+
#
|
29
|
+
# 取得する
|
30
|
+
#
|
31
|
+
# @param [Array<Base::Year>] years 範囲
|
32
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
33
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
34
|
+
#
|
35
|
+
# @return [Array<Result::Data::SingleDay>] 期間検索結果(和暦日)
|
36
|
+
#
|
37
|
+
def self.get(years: [], start_date: Western::Calendar.new,
|
38
|
+
last_date: Western::Calendar.new)
|
39
|
+
months = specify(years: years, start_date: start_date, last_date: last_date)
|
40
|
+
|
41
|
+
result = []
|
42
|
+
months.each do |month|
|
43
|
+
result |= month.get
|
44
|
+
end
|
45
|
+
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# 年を特定する
|
51
|
+
#
|
52
|
+
# @param [Array<Year>] years 範囲
|
53
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
54
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
55
|
+
#
|
56
|
+
# @return [Array<Month>] 特定月
|
57
|
+
#
|
58
|
+
def self.specify(years: [], start_date: Western::Calendar.new,
|
59
|
+
last_date: Western::Calendar.new)
|
60
|
+
result = []
|
61
|
+
years.each do |year|
|
62
|
+
result |= specify_month(
|
63
|
+
year: year, start_date: start_date, last_date: last_date
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
result
|
68
|
+
end
|
69
|
+
private_class_method :specify
|
70
|
+
|
71
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
72
|
+
|
73
|
+
#
|
74
|
+
# 月を特定する
|
75
|
+
#
|
76
|
+
# @param [Year] year 年
|
77
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
78
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
79
|
+
#
|
80
|
+
# @return [Month] 対象月
|
81
|
+
#
|
82
|
+
def self.specify_month(year:, start_date: Western::Calendar.new,
|
83
|
+
last_date: Western::Calendar.new)
|
84
|
+
months = year.months
|
85
|
+
|
86
|
+
specify_months = []
|
87
|
+
months.each do |month|
|
88
|
+
next unless include?(month: month, start_date: start_date, last_date: last_date)
|
89
|
+
|
90
|
+
monthly_start_date = month.western_date.clone
|
91
|
+
monthly_last_date = month.last_date.clone
|
92
|
+
|
93
|
+
monthly_start_date = start_date.clone if start_date > monthly_start_date
|
94
|
+
|
95
|
+
monthly_last_date = last_date.clone if last_date < monthly_last_date
|
96
|
+
|
97
|
+
specify_months.push(
|
98
|
+
Month.new(year: year, month: month,
|
99
|
+
start_date: monthly_start_date, last_date: monthly_last_date)
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
specify_months
|
104
|
+
end
|
105
|
+
private_class_method :specify_month
|
106
|
+
|
107
|
+
#
|
108
|
+
# 月が範囲に含まれるか
|
109
|
+
#
|
110
|
+
# @param [Monthly::Month] month 月
|
111
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
112
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
113
|
+
#
|
114
|
+
# @return [True] 含む
|
115
|
+
# @return [False] 含まない
|
116
|
+
#
|
117
|
+
def self.include?(month:, start_date:, last_date:)
|
118
|
+
monthly_start_date = month.western_date.clone
|
119
|
+
monthly_last_date = month.last_date.clone
|
120
|
+
|
121
|
+
return false if monthly_start_date.invalid?
|
122
|
+
|
123
|
+
return false if monthly_last_date.invalid?
|
124
|
+
|
125
|
+
return false if under(monthly_start_date: monthly_start_date,
|
126
|
+
start_date: start_date, last_date: last_date)
|
127
|
+
|
128
|
+
return false if over(monthly_last_date: monthly_last_date,
|
129
|
+
start_date: start_date, last_date: last_date)
|
130
|
+
|
131
|
+
true
|
132
|
+
end
|
133
|
+
private_class_method :include?
|
134
|
+
|
135
|
+
#
|
136
|
+
# 範囲が月より前にあるか
|
137
|
+
#
|
138
|
+
# @param [Western::Calendar] monthly_start_date 月初日
|
139
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
140
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
141
|
+
#
|
142
|
+
# @return [True] 前にある
|
143
|
+
# @return [False] 前にない
|
144
|
+
#
|
145
|
+
def self.under(monthly_start_date:, start_date:, last_date:)
|
146
|
+
start_date < monthly_start_date && last_date < monthly_start_date
|
147
|
+
end
|
148
|
+
private_class_method :under
|
149
|
+
|
150
|
+
#
|
151
|
+
# 範囲が月より後にあるか
|
152
|
+
#
|
153
|
+
# @param [Western::Calendar] monthly_start_date 月末日
|
154
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
155
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
156
|
+
#
|
157
|
+
# @return [True] 後にある
|
158
|
+
# @return [False] 後にない
|
159
|
+
#
|
160
|
+
def self.over(monthly_last_date:, start_date:, last_date:)
|
161
|
+
start_date > monthly_last_date && last_date > monthly_last_date
|
162
|
+
end
|
163
|
+
private_class_method :over
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/western/calendar'
|
4
|
+
require_relative '../../../../output/response'
|
5
|
+
require_relative '../../../../output/logger'
|
6
|
+
|
7
|
+
require_relative '../../../base/year'
|
8
|
+
|
9
|
+
# :nodoc:
|
10
|
+
module Zakuro
|
11
|
+
# :nodoc:
|
12
|
+
module Calculation
|
13
|
+
# :nodoc:
|
14
|
+
module Summary
|
15
|
+
# :nodoc:
|
16
|
+
module Western
|
17
|
+
# :nodoc:
|
18
|
+
module Specifier
|
19
|
+
#
|
20
|
+
# SingleDay 一日検索
|
21
|
+
#
|
22
|
+
module SingleDay
|
23
|
+
# @return [Output::Logger] ロガー
|
24
|
+
LOGGER = Output::Logger.new(location: 'specifier')
|
25
|
+
|
26
|
+
#
|
27
|
+
# 取得する
|
28
|
+
#
|
29
|
+
# @param [Array<Year>] yeas 範囲
|
30
|
+
# @param [Western::Calendar] date 西暦日
|
31
|
+
#
|
32
|
+
# @return [Result::Data::SingleDay] 和暦日
|
33
|
+
#
|
34
|
+
def self.get(years: [], date: Western::Calendar.new)
|
35
|
+
year, month = specify(years: years, date: date)
|
36
|
+
first_date = month.western_date
|
37
|
+
|
38
|
+
Output::Response::SingleDay.save_single_day(
|
39
|
+
param: Output::Response::SingleDay::Param.new(
|
40
|
+
year: year, month: month,
|
41
|
+
date: date, days: date - first_date
|
42
|
+
)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# 年を特定する
|
48
|
+
#
|
49
|
+
# @param [Array<Year>] years 範囲
|
50
|
+
# @param [Western::Calendar] date 西暦日
|
51
|
+
#
|
52
|
+
# @return [Base::Year] 対象年
|
53
|
+
# @return [Monthly::Month] 対象月
|
54
|
+
#
|
55
|
+
def self.specify(years:, date:)
|
56
|
+
years.each do |year|
|
57
|
+
month = specify_month(year: year, date: date)
|
58
|
+
return year, month unless month.invalid?
|
59
|
+
end
|
60
|
+
|
61
|
+
raise ArgumentError, "invalid year range. date: #{date.format}"
|
62
|
+
end
|
63
|
+
private_class_method :specify
|
64
|
+
|
65
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
66
|
+
|
67
|
+
#
|
68
|
+
# 月を特定する
|
69
|
+
#
|
70
|
+
# @param [Base::Year] year 年
|
71
|
+
# @param [Western::Calendar] date 西暦日
|
72
|
+
#
|
73
|
+
# @return [Monthly::Month] 対象月
|
74
|
+
#
|
75
|
+
def self.specify_month(year:, date:)
|
76
|
+
months = year.months
|
77
|
+
|
78
|
+
months.each do |month|
|
79
|
+
western_date = month.western_date
|
80
|
+
next if western_date.invalid?
|
81
|
+
|
82
|
+
return month if month.include?(date: date)
|
83
|
+
end
|
84
|
+
|
85
|
+
Monthly::Month.new
|
86
|
+
end
|
87
|
+
private_class_method :specify_month
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/zakuro/condition.rb
CHANGED
@@ -18,10 +18,9 @@ module Zakuro
|
|
18
18
|
#
|
19
19
|
# 初期化
|
20
20
|
#
|
21
|
-
# @param [Date] date
|
21
|
+
# @param [Date, String] date 西暦日/和暦日
|
22
22
|
#
|
23
23
|
def initialize(date:)
|
24
|
-
# TODO: 和暦日(String)から西暦日(Date)への変換
|
25
24
|
@date = date
|
26
25
|
end
|
27
26
|
|
@@ -87,6 +86,20 @@ module Zakuro
|
|
87
86
|
|
88
87
|
failed
|
89
88
|
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# 不正か
|
92
|
+
#
|
93
|
+
# @return [True] 不正
|
94
|
+
# @return [False] 不正なし
|
95
|
+
#
|
96
|
+
def invalid?
|
97
|
+
return true unless @start
|
98
|
+
|
99
|
+
return true unless @end
|
100
|
+
|
101
|
+
false
|
102
|
+
end
|
90
103
|
end
|
91
104
|
|
92
105
|
#
|