zakuro 0.6.1 → 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 +6 -4
- data/VERSION +1 -1
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/gengou.rb +46 -0
- data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +6 -8
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +37 -51
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +17 -17
- 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 +2 -3
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/monthly/month.rb +39 -0
- data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
- data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +5 -4
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +9 -11
- 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 +0 -2
- data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +1 -1
- 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 +1 -2
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +89 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +125 -122
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +141 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +171 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +38 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +183 -182
- data/lib/zakuro/era/japan/gengou/resource/type.rb +233 -232
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +255 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +5 -20
- data/lib/zakuro/era/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 +8 -44
- data/lib/zakuro/operation/month/parser.rb +9 -9
- data/lib/zakuro/operation/month/type.rb +31 -31
- data/lib/zakuro/operation/month/validator.rb +49 -49
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- 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 +4 -2
- metadata +46 -14
- data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
- data/lib/zakuro/calculation/summary/range.rb +0 -120
- data/lib/zakuro/calculation/summary/single.rb +0 -110
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/result/operation.rb +0 -114
@@ -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
@@ -6,98 +6,113 @@ require_relative './line'
|
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
9
|
-
#
|
10
|
-
# Japan 和暦
|
11
|
-
#
|
9
|
+
# :nodoc:
|
12
10
|
module Japan
|
13
|
-
#
|
14
|
-
|
15
|
-
#
|
16
|
-
module Alignment
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# Alignment 整列
|
19
15
|
#
|
20
|
-
|
21
|
-
#
|
22
|
-
|
16
|
+
module Alignment
|
17
|
+
#
|
18
|
+
# Aligner 元号整列
|
19
|
+
#
|
20
|
+
class Aligner
|
21
|
+
# @return [Integer] 1行目元号
|
22
|
+
FIRST_LINE = 0
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# @return [Integer] 2行目元号
|
25
|
+
SECOND_LINE = 1
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# @return [Array<Integer>] 元号リスト
|
28
|
+
LINE_INDEXES = [FIRST_LINE, SECOND_LINE].freeze
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
# @return [Integer] 行数
|
31
|
+
LINE_SIZE = LINE_INDEXES.size
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
# @return [Array<Line>] 行元号
|
34
|
+
attr_reader :lines
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
#
|
37
|
+
# 初期化
|
38
|
+
#
|
39
|
+
# @param [Array<Set>] resources 元号解析結果
|
40
|
+
#
|
41
|
+
def initialize(resources: [])
|
42
|
+
@lines = []
|
43
|
+
(1..LINE_SIZE).each do |_index|
|
44
|
+
@lines.push(Line.new)
|
45
|
+
end
|
46
|
+
|
47
|
+
save(resources: resources)
|
45
48
|
end
|
46
49
|
|
47
|
-
|
48
|
-
|
50
|
+
#
|
51
|
+
# 行元号に追加する
|
52
|
+
#
|
53
|
+
# @param [Set] set 元号セット
|
54
|
+
#
|
55
|
+
def push(set:)
|
56
|
+
list = set.list
|
57
|
+
list.each do |gengou|
|
58
|
+
push_gengou(gengou: gengou)
|
59
|
+
end
|
60
|
+
end
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
#
|
63
|
+
# 指定した範囲内の元号を取得する
|
64
|
+
#
|
65
|
+
# @param [Integer] line 行
|
66
|
+
# @param [Western::Calendar] start_date 開始日
|
67
|
+
# @param [Western::Calendar] last_date 終了日
|
68
|
+
#
|
69
|
+
# @return [Array<LinearGengou>] 元号
|
70
|
+
#
|
71
|
+
def get(line:, start_date:, last_date:)
|
72
|
+
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
73
|
+
|
74
|
+
@lines[line].get(start_date: start_date, last_date: last_date)
|
59
75
|
end
|
60
|
-
end
|
61
76
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
77
|
+
#
|
78
|
+
# 指定した範囲内の元号を取得する(元号名)
|
79
|
+
#
|
80
|
+
# @param [Integer] line 行
|
81
|
+
# @param [String] name 元号名
|
82
|
+
#
|
83
|
+
# @return [Array<LinearGengou>] 元号
|
84
|
+
#
|
85
|
+
def get_by_name(line:, name:)
|
86
|
+
raise ArgumentError.new, 'invalid line number' unless LINE_INDEXES.include?(line)
|
73
87
|
|
74
|
-
|
75
|
-
|
88
|
+
@lines[line].get_by_name(name: name)
|
89
|
+
end
|
76
90
|
|
77
|
-
|
91
|
+
private
|
78
92
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
93
|
+
#
|
94
|
+
# 保存する
|
95
|
+
#
|
96
|
+
# @param [Array<Set>] resources 元号解析結果
|
97
|
+
#
|
98
|
+
def save(resources: [])
|
99
|
+
resources.each do |set|
|
100
|
+
push(set: set)
|
101
|
+
end
|
87
102
|
end
|
88
|
-
end
|
89
103
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
104
|
+
#
|
105
|
+
# 元号を追加する
|
106
|
+
#
|
107
|
+
# @param [Gengou] gengou 元号
|
108
|
+
#
|
109
|
+
def push_gengou(gengou:)
|
110
|
+
rest = [
|
111
|
+
LinearGengou.new(gengou: gengou)
|
112
|
+
]
|
113
|
+
@lines.each do |line|
|
114
|
+
rest = line.push(list: rest)
|
115
|
+
end
|
101
116
|
end
|
102
117
|
end
|
103
118
|
end
|