zakuro 0.4.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -3
- data/VERSION +1 -0
- data/doc/operation/csv/month.csv +21 -0
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/gengou.rb +82 -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/cycle/abstract_remainder.rb +0 -13
- 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/list.rb +244 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +42 -0
- data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -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 +49 -2
- data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
- data/lib/zakuro/calculation/range/full_range.rb +68 -107
- data/lib/zakuro/calculation/range/operated_range.rb +13 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
- 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/specifier/internal/month.rb +84 -0
- data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
- data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
- data/lib/zakuro/calculation/summary/range.rb +120 -0
- data/lib/zakuro/calculation/summary/single.rb +45 -64
- data/lib/zakuro/condition.rb +14 -0
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -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 +32 -0
- data/lib/zakuro/era/japan/gengou.rb +35 -74
- data/lib/zakuro/era/japan/version.rb +151 -0
- data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
- data/lib/zakuro/merchant.rb +50 -3
- data/lib/zakuro/operation/month/parser.rb +1 -1
- data/lib/zakuro/operation/month/type.rb +1 -1
- data/lib/zakuro/operation/month/validator.rb +2 -2
- data/lib/zakuro/operation/yaml/month.yaml +672 -0
- data/lib/zakuro/output/response.rb +5 -5
- data/lib/zakuro/result/result.rb +17 -0
- 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/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/daien/daien.rb +1 -26
- data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/genka/const/number.rb +43 -0
- data/lib/zakuro/version/genka/const/remainder.rb +33 -0
- data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
- data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
- data/lib/zakuro/version/genka/genka.rb +1 -9
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
- data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
- data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
- data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
- 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/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/lib/zakuro/version/version_class_resolver.rb +4 -0
- data/zakuro.gemspec +1 -3
- metadata +45 -16
- 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/transfer/western_date_allocation.rb +0 -82
- 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/version/abstract_version.rb +0 -29
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
@@ -1,218 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './multi_gengou'
|
4
|
-
|
5
|
-
require_relative '../../era/japan/gengou'
|
6
|
-
|
7
|
-
# :nodoc:
|
8
|
-
module Zakuro
|
9
|
-
# :nodoc:
|
10
|
-
module Calculation
|
11
|
-
# :nodoc:
|
12
|
-
module Base
|
13
|
-
#
|
14
|
-
# MultiGengouRoller 改元処理
|
15
|
-
#
|
16
|
-
class MultiGengouRoller
|
17
|
-
# @return [MultiGengou] 複数元号
|
18
|
-
attr_reader :multi_gengou
|
19
|
-
# @return [Western::Calendar] 元旦(元号が2つある場合は再過去の日付になる)
|
20
|
-
attr_reader :oldest_date
|
21
|
-
# @return [Western::Calendar] 元号内での最未来日(元号が2つある場合は再未来の日付になる)
|
22
|
-
attr_reader :newest_date
|
23
|
-
# @return [Western::Calendar] 現在日
|
24
|
-
attr_reader :current_date
|
25
|
-
|
26
|
-
def initialize(start_date: Western::Calendar.new, end_date: Western::Calendar.new)
|
27
|
-
end_date = start_date if end_date.invalid?
|
28
|
-
|
29
|
-
@oldest_date = MultiGengouRoller.choise_oldest_gengou_date(
|
30
|
-
first_line: MultiGengouRoller.first_line(date: start_date),
|
31
|
-
second_line: MultiGengouRoller.second_line(date: start_date)
|
32
|
-
)
|
33
|
-
@current_date = @oldest_date.clone
|
34
|
-
@newest_date = MultiGengouRoller.choise_newest_gengou_date(
|
35
|
-
first_line: MultiGengouRoller.first_line(date: end_date),
|
36
|
-
second_line: MultiGengouRoller.second_line(date: end_date)
|
37
|
-
)
|
38
|
-
|
39
|
-
@multi_gengou = MultiGengou.new(
|
40
|
-
first_line: current_first_line,
|
41
|
-
second_line: current_second_line,
|
42
|
-
new_year_date: @oldest_date
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# 現在日付を未来に進める
|
48
|
-
#
|
49
|
-
# @param [<Type>] days <description>
|
50
|
-
#
|
51
|
-
# @return [<Type>] <description>
|
52
|
-
#
|
53
|
-
def next(days: 0)
|
54
|
-
@current_date += days
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# 現在日から元号(1行目)を取得する
|
59
|
-
#
|
60
|
-
# @return [Japan::Gengou] 元号(1行目)
|
61
|
-
#
|
62
|
-
def current_first_line
|
63
|
-
MultiGengouRoller.first_line(date: @current_date)
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# 現在日から元号(2行目)を取得する
|
68
|
-
#
|
69
|
-
# @return [Japan::Gengou] 元号(2行目)
|
70
|
-
#
|
71
|
-
def current_second_line
|
72
|
-
MultiGengouRoller.second_line(date: @current_date)
|
73
|
-
end
|
74
|
-
|
75
|
-
#
|
76
|
-
# 改元する
|
77
|
-
#
|
78
|
-
# @return [MultiGengou] 複数元号
|
79
|
-
#
|
80
|
-
def transfer
|
81
|
-
MultiGengouRoller.transfer(multi_gengou: @multi_gengou, date: @current_date)
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# 次年にする
|
86
|
-
#
|
87
|
-
# @return [MultiGengou] 複数元号
|
88
|
-
#
|
89
|
-
def next_year
|
90
|
-
@multi_gengou.next_year
|
91
|
-
end
|
92
|
-
|
93
|
-
#
|
94
|
-
# 元号(1行目)を取得する
|
95
|
-
#
|
96
|
-
# @return [Japan::Gengou] 元号(1行目)
|
97
|
-
#
|
98
|
-
def self.first_line(date: Western::Calender.new)
|
99
|
-
Japan::GengouResource.first_line(date: date)
|
100
|
-
end
|
101
|
-
|
102
|
-
#
|
103
|
-
# 元号(2行目)を取得する
|
104
|
-
#
|
105
|
-
# @return [Japan::Gengou] 元号(2行目)
|
106
|
-
#
|
107
|
-
def self.second_line(date: Western::Calender.new)
|
108
|
-
Japan::GengouResource.second_line(date: date)
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# 改元する
|
113
|
-
#
|
114
|
-
# @param [MultiGengou] multi_gengou 複数元号
|
115
|
-
# @param [Western::Calendar] date 対象日
|
116
|
-
#
|
117
|
-
# @return [MultiGengou] 改元済み複数元号
|
118
|
-
#
|
119
|
-
def self.transfer(multi_gengou:, date:)
|
120
|
-
multi_gengou.transfer(
|
121
|
-
first_line: first_line(date: date),
|
122
|
-
second_line: second_line(date: date)
|
123
|
-
)
|
124
|
-
|
125
|
-
multi_gengou
|
126
|
-
end
|
127
|
-
|
128
|
-
#
|
129
|
-
# 現在日からみて直近の未来に対する元号の切替前日を求める
|
130
|
-
# @note 2つの元号が重複した場合はより過去の日となる
|
131
|
-
#
|
132
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
133
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
134
|
-
#
|
135
|
-
# @return [Western::Calendar] 元号の切替前日
|
136
|
-
#
|
137
|
-
def choise_nearest_end_date
|
138
|
-
condition = lambda do |first_date, second_date|
|
139
|
-
first_date < second_date ? first_date : second_date
|
140
|
-
end
|
141
|
-
|
142
|
-
second_line = current_second_line
|
143
|
-
|
144
|
-
MultiGengouRoller.choise_date(condition: condition, second_line: second_line,
|
145
|
-
first_date: current_first_line.end_date.clone,
|
146
|
-
second_date: second_line.end_date.clone)
|
147
|
-
end
|
148
|
-
|
149
|
-
#
|
150
|
-
# 最過去の元旦を求める
|
151
|
-
# @note 2つの元号が重複した場合はより過去の日となる
|
152
|
-
#
|
153
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
154
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
155
|
-
#
|
156
|
-
# @return [Western::Calendar] 最過去の元旦
|
157
|
-
#
|
158
|
-
def self.choise_oldest_gengou_date(first_line:, second_line:)
|
159
|
-
condition = lambda do |first_date, second_date|
|
160
|
-
first_date < second_date ? first_date : second_date
|
161
|
-
end
|
162
|
-
choise_date(condition: condition, second_line: second_line,
|
163
|
-
first_date: first_line.new_year_date.clone,
|
164
|
-
second_date: second_line.new_year_date.clone)
|
165
|
-
end
|
166
|
-
|
167
|
-
#
|
168
|
-
# 元号内での最未来日を求める
|
169
|
-
# @note 2つの元号が重複した場合はより未来の日となる
|
170
|
-
#
|
171
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
172
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
173
|
-
#
|
174
|
-
# @return [Western::Calendar] 最未来日
|
175
|
-
#
|
176
|
-
def self.choise_newest_gengou_date(first_line:, second_line:)
|
177
|
-
condition = lambda do |first_date, second_date|
|
178
|
-
first_date > second_date ? first_date : second_date
|
179
|
-
end
|
180
|
-
choise_date(condition: condition, second_line: second_line,
|
181
|
-
first_date: first_line.end_date.clone,
|
182
|
-
second_date: second_line.end_date.clone)
|
183
|
-
end
|
184
|
-
|
185
|
-
# :reek:LongParameterList {max_params: 4}
|
186
|
-
|
187
|
-
#
|
188
|
-
# 条件を元に日付を求める
|
189
|
-
#
|
190
|
-
# @param [Proc] condition 比較条件
|
191
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
192
|
-
# @param [Western::Calendar] first_date 比較対象(1行目)
|
193
|
-
# @param [Western::Calendar] second_date 比較対象(2行目)
|
194
|
-
#
|
195
|
-
# @return [Western::Calendar] 比較結果
|
196
|
-
#
|
197
|
-
def self.choise_date(condition:, second_line:, first_date:, second_date:)
|
198
|
-
# first_lineは常に存在する
|
199
|
-
return first_date if second_line.invalid?
|
200
|
-
|
201
|
-
condition.call(first_date, second_date)
|
202
|
-
end
|
203
|
-
|
204
|
-
#
|
205
|
-
# ディープコピー
|
206
|
-
#
|
207
|
-
# @param [MultiGengou] obj 自身
|
208
|
-
#
|
209
|
-
def initialize_copy(obj)
|
210
|
-
@oldest_date = obj.oldest_date.clone
|
211
|
-
@current_date = obj.current_date.clone
|
212
|
-
@newest_date = obj.newest_date.clone
|
213
|
-
@multi_gengou = obj.multi_gengou.clone
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# :nodoc:
|
4
|
-
module Zakuro
|
5
|
-
# :nodoc:
|
6
|
-
module Calculation
|
7
|
-
# :nodoc:
|
8
|
-
module Range
|
9
|
-
# :nodoc:
|
10
|
-
module Transfer
|
11
|
-
#
|
12
|
-
# WesternDateAllocation 西暦日の割り当て
|
13
|
-
#
|
14
|
-
module WesternDateAllocation
|
15
|
-
#
|
16
|
-
# 月初日の西暦日を更新する
|
17
|
-
#
|
18
|
-
# @param [Context] context 暦コンテキスト
|
19
|
-
# @param [Array<Year>] years 完全範囲(月初日なし)
|
20
|
-
#
|
21
|
-
# @return [Array<Year>] 完全範囲(月初日あり)
|
22
|
-
#
|
23
|
-
def self.get(context:, years:)
|
24
|
-
update_first_day(context: context, years: years)
|
25
|
-
|
26
|
-
years
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# 月初日の西暦日を更新する
|
31
|
-
#
|
32
|
-
# @param [Context] context 暦コンテキスト
|
33
|
-
# @param [Array<Year>] years 完全範囲(月初日なし)
|
34
|
-
#
|
35
|
-
def self.update_first_day(context:, years:)
|
36
|
-
years.each_with_index do |year, index|
|
37
|
-
new_year_date = year.new_year_date.clone
|
38
|
-
|
39
|
-
months = year.months
|
40
|
-
update_first_day_within_all_months(
|
41
|
-
context: context,
|
42
|
-
new_year_date: new_year_date, months: months
|
43
|
-
)
|
44
|
-
|
45
|
-
years[index] = Base::Year.new(
|
46
|
-
multi_gengou: year.multi_gengou, new_year_date: new_year_date,
|
47
|
-
months: months, total_days: year.total_days
|
48
|
-
)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# 全ての月で月初日の西暦日を更新する
|
54
|
-
#
|
55
|
-
# @param [Context] context 暦コンテキスト
|
56
|
-
# @param [Western::Calendar] new_year_date 元旦
|
57
|
-
# @param [Array<Month>] months 月データ
|
58
|
-
#
|
59
|
-
def self.update_first_day_within_all_months(context:,
|
60
|
-
new_year_date:, months:)
|
61
|
-
date = new_year_date.clone
|
62
|
-
months.each_with_index do |month, index|
|
63
|
-
updated_month = Monthly::Month.new(
|
64
|
-
context: context,
|
65
|
-
month_label: month.month_label,
|
66
|
-
first_day: Monthly::FirstDay.new(
|
67
|
-
remainder: month.first_day.remainder,
|
68
|
-
western_date: date
|
69
|
-
),
|
70
|
-
solar_terms: month.solar_terms
|
71
|
-
)
|
72
|
-
months[index] = updated_month
|
73
|
-
|
74
|
-
date = date.clone + updated_month.days
|
75
|
-
end
|
76
|
-
end
|
77
|
-
private_class_method :update_first_day_within_all_months
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,167 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../western'
|
4
|
-
require_relative './type'
|
5
|
-
require_relative './validator'
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
# :nodoc:
|
9
|
-
module Zakuro
|
10
|
-
#
|
11
|
-
# Japan 和暦
|
12
|
-
#
|
13
|
-
module Japan
|
14
|
-
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
15
|
-
|
16
|
-
#
|
17
|
-
# Parser yaml解析
|
18
|
-
#
|
19
|
-
module Parser
|
20
|
-
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
21
|
-
|
22
|
-
#
|
23
|
-
# GengouParser 元号情報の検証/展開を行う
|
24
|
-
#
|
25
|
-
class GengouParser
|
26
|
-
# @return [Integer] 要素位置
|
27
|
-
attr_reader :index
|
28
|
-
# @return [String] 元号名
|
29
|
-
attr_reader :name
|
30
|
-
# @return [String] 開始日
|
31
|
-
attr_reader :start_date
|
32
|
-
# @return [String] 元旦
|
33
|
-
attr_reader :new_year_date
|
34
|
-
# @return [String] 開始年
|
35
|
-
attr_reader :start_year
|
36
|
-
|
37
|
-
#
|
38
|
-
# 初期化
|
39
|
-
#
|
40
|
-
# @param [Hash<String, Strin>] hash 元号情報
|
41
|
-
# @param [Integer] index (元号セット内での)元号の要素位置
|
42
|
-
#
|
43
|
-
def initialize(hash:, index:)
|
44
|
-
@index = index
|
45
|
-
@name = hash['name']
|
46
|
-
@start_date = hash['start_date']
|
47
|
-
@new_year_date = hash['new_year_date']
|
48
|
-
@start_year = hash['start_year']
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# 元号情報を生成する
|
53
|
-
#
|
54
|
-
# @return [Gengou] 元号情報
|
55
|
-
#
|
56
|
-
def create
|
57
|
-
start_date = Western::Calendar.parse(str: @start_date)
|
58
|
-
new_year_date = Western::Calendar.parse(str: @new_year_date)
|
59
|
-
start_year = @start_year || 1
|
60
|
-
|
61
|
-
Gengou.new(name: @name, start_date: start_date, new_year_date: new_year_date,
|
62
|
-
year: start_year)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# SetParser 元号セット情報の検証/展開
|
68
|
-
#
|
69
|
-
class SetParser
|
70
|
-
# @return [String] 元号セットID
|
71
|
-
attr_reader :id
|
72
|
-
# @return [String] 元号セット名
|
73
|
-
attr_reader :name
|
74
|
-
# @return [String] 終了日
|
75
|
-
attr_reader :end_date
|
76
|
-
# @return [Array<Hash<String, String>>] 元号情報
|
77
|
-
attr_reader :list
|
78
|
-
|
79
|
-
#
|
80
|
-
# 初期化
|
81
|
-
#
|
82
|
-
# @param [Hash<String, Object>] hash 元号セット情報
|
83
|
-
#
|
84
|
-
def initialize(hash:)
|
85
|
-
@id = hash['id']
|
86
|
-
@name = hash['name']
|
87
|
-
@end_date = hash['end_date']
|
88
|
-
@list = hash['list']
|
89
|
-
end
|
90
|
-
|
91
|
-
#
|
92
|
-
# 元号セット情報を生成する
|
93
|
-
#
|
94
|
-
# @return [Set] 元号セット情報
|
95
|
-
#
|
96
|
-
def create
|
97
|
-
end_date = Western::Calendar.parse(str: @end_date)
|
98
|
-
list = create_list
|
99
|
-
Set.new(
|
100
|
-
id: @id, name: @name, end_date: end_date, list: list
|
101
|
-
)
|
102
|
-
end
|
103
|
-
|
104
|
-
# :reek:TooManyStatements { max_statements: 7 }
|
105
|
-
|
106
|
-
#
|
107
|
-
# 元号情報を生成する
|
108
|
-
#
|
109
|
-
# @return [Array<Gengou>] 元号情報
|
110
|
-
#
|
111
|
-
def create_list
|
112
|
-
result = []
|
113
|
-
@list.each_with_index do |li, index|
|
114
|
-
gengou = GengouParser.new(hash: li, index: index).create
|
115
|
-
next_index = index + 1
|
116
|
-
gengou = calc_end_date_on_gengou_data(next_index: next_index,
|
117
|
-
gengou: gengou)
|
118
|
-
result.push(gengou)
|
119
|
-
end
|
120
|
-
|
121
|
-
result
|
122
|
-
end
|
123
|
-
|
124
|
-
# :reek:TooManyStatements { max_statements: 6 }
|
125
|
-
|
126
|
-
#
|
127
|
-
# 次の元号の開始日から、元号の終了日に変換する
|
128
|
-
#
|
129
|
-
# @param [Integer] next_index 次の元号の要素位置
|
130
|
-
# @param [String] gengou 次回開始日
|
131
|
-
#
|
132
|
-
# @return [Gengou] 元号情報
|
133
|
-
#
|
134
|
-
def calc_end_date_on_gengou_data(next_index:, gengou:)
|
135
|
-
if next_index >= @list.size
|
136
|
-
end_date = Western::Calendar.parse(str: @end_date)
|
137
|
-
gengou.write_end_date(end_date: end_date)
|
138
|
-
return gengou
|
139
|
-
end
|
140
|
-
next_start_date = @list[next_index]['start_date']
|
141
|
-
gengou.convert_next_start_date_to_end_date(
|
142
|
-
next_start_date_string: next_start_date
|
143
|
-
)
|
144
|
-
gengou
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
#
|
149
|
-
# 解析/展開する
|
150
|
-
#
|
151
|
-
# @param [String] filepath 元号セットファイルパス
|
152
|
-
#
|
153
|
-
# @return [Set] 元号セット情報
|
154
|
-
#
|
155
|
-
def self.run(filepath: '')
|
156
|
-
yaml = YAML.load_file(filepath)
|
157
|
-
|
158
|
-
failed = Validator.run(yaml_hash: yaml)
|
159
|
-
|
160
|
-
raise ArgumentError, failed.join("\n") unless failed.empty?
|
161
|
-
|
162
|
-
parser = SetParser.new(hash: yaml)
|
163
|
-
parser.create
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../western'
|
4
|
-
|
5
|
-
# :nodoc:
|
6
|
-
module Zakuro
|
7
|
-
#
|
8
|
-
# Japan 和暦
|
9
|
-
#
|
10
|
-
module Japan
|
11
|
-
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
12
|
-
|
13
|
-
#
|
14
|
-
# Gengou 元号情報
|
15
|
-
#
|
16
|
-
class Gengou
|
17
|
-
# @return [String] 元号名
|
18
|
-
attr_reader :name
|
19
|
-
# @return [Western::Calendar] 開始日
|
20
|
-
attr_reader :start_date
|
21
|
-
# @return [Western::Calendar] 元旦
|
22
|
-
attr_reader :new_year_date
|
23
|
-
# @return [Western::Calendar] 終了日
|
24
|
-
attr_reader :end_date
|
25
|
-
# @return [Integer] 元号年
|
26
|
-
attr_reader :year
|
27
|
-
|
28
|
-
#
|
29
|
-
# 初期化
|
30
|
-
#
|
31
|
-
# @param [String] name 元号名
|
32
|
-
# @param [Western::Calendar] start_date 開始日
|
33
|
-
# @param [Western::Calendar] new_year_date 元旦
|
34
|
-
# @param [Western::Calendar] end_date 終了日
|
35
|
-
# @param [Integer] year 元号年
|
36
|
-
#
|
37
|
-
def initialize(name: '', start_date: Western::Calendar.new,
|
38
|
-
new_year_date: Western::Calendar.new,
|
39
|
-
end_date: Western::Calendar.new, year: -1)
|
40
|
-
@name = name
|
41
|
-
@start_date = start_date
|
42
|
-
@new_year_date = new_year_date
|
43
|
-
@end_date = end_date
|
44
|
-
@year = year
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# 終了日を更新する
|
49
|
-
#
|
50
|
-
# @param [Western::Calendar] end_date 終了日
|
51
|
-
#
|
52
|
-
def write_end_date(end_date:)
|
53
|
-
unless Gengou.valid_date(date: end_date)
|
54
|
-
raise ArgumentError, "invalid date format. [#{end_date}]"
|
55
|
-
end
|
56
|
-
|
57
|
-
@end_date = end_date
|
58
|
-
nil
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# 日付が有効かどうかを確認する
|
63
|
-
#
|
64
|
-
# @param [Western::Calendar] date 日付
|
65
|
-
#
|
66
|
-
# @return [True] 有効
|
67
|
-
# @return [False] 無効
|
68
|
-
#
|
69
|
-
def self.valid_date(date:)
|
70
|
-
return false unless date
|
71
|
-
|
72
|
-
date.is_a?(Western::Calendar)
|
73
|
-
end
|
74
|
-
|
75
|
-
#
|
76
|
-
# 次の元号の開始日から、元号の終了日に変換する
|
77
|
-
#
|
78
|
-
# @param [String] next_start_date_string 次回開始日
|
79
|
-
#
|
80
|
-
def convert_next_start_date_to_end_date(next_start_date_string: '')
|
81
|
-
raise ArgumentError, 'empty string cannot convert' if next_start_date_string.empty?
|
82
|
-
|
83
|
-
start_date = Western::Calendar.parse(str: next_start_date_string)
|
84
|
-
@end_date = start_date - 1
|
85
|
-
nil
|
86
|
-
end
|
87
|
-
|
88
|
-
#
|
89
|
-
# 指定した日が元号に含まれるか
|
90
|
-
#
|
91
|
-
# @param [Western::Calendar] date 日
|
92
|
-
#
|
93
|
-
# @return [True] 含まれる
|
94
|
-
# @return [False] 含まれない
|
95
|
-
#
|
96
|
-
def include?(date:)
|
97
|
-
date >= @start_date && date <= @end_date
|
98
|
-
end
|
99
|
-
|
100
|
-
#
|
101
|
-
# 不正な元号データかを確認する
|
102
|
-
#
|
103
|
-
# @return [True] 正しくない
|
104
|
-
# @return [True] 正しい
|
105
|
-
#
|
106
|
-
def invalid?
|
107
|
-
@year == -1
|
108
|
-
end
|
109
|
-
|
110
|
-
#
|
111
|
-
# 1元号年を追加する
|
112
|
-
#
|
113
|
-
def next_year
|
114
|
-
@year += 1 unless invalid?
|
115
|
-
nil
|
116
|
-
end
|
117
|
-
|
118
|
-
def to_s
|
119
|
-
"name: #{@name}, start_date: #{@start_date.format}, " \
|
120
|
-
"end_date: #{@end_date.format}, year: #{@year}"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
#
|
125
|
-
# Set 元号セット
|
126
|
-
#
|
127
|
-
class Set
|
128
|
-
# @return [Integer] 元号セットID
|
129
|
-
attr_reader :id
|
130
|
-
# @return [String] 元号セット名
|
131
|
-
attr_reader :name
|
132
|
-
# @return [Western::Calendar] 元号セットでの終了日
|
133
|
-
attr_reader :end_date
|
134
|
-
# @return [Array<Gengou>] 元号リスト
|
135
|
-
attr_reader :list
|
136
|
-
|
137
|
-
#
|
138
|
-
# 初期化
|
139
|
-
#
|
140
|
-
# @param [Integer] id 元号セットID
|
141
|
-
# @param [String] name 元号セット名
|
142
|
-
# @param [Western::Calendar] end_date 元号セットでの終了日
|
143
|
-
# @param [Array<Gengou>] list 元号リスト
|
144
|
-
#
|
145
|
-
def initialize(id: -1, name: '', end_date: Western::Calendar.new, list: [])
|
146
|
-
@id = id
|
147
|
-
@name = name
|
148
|
-
@end_date = end_date
|
149
|
-
@list = list
|
150
|
-
end
|
151
|
-
|
152
|
-
#
|
153
|
-
# 指定した日付を含む元号を返す
|
154
|
-
#
|
155
|
-
# @param [Western::Calendar] date 日
|
156
|
-
#
|
157
|
-
# @return [Gengou] 元号
|
158
|
-
#
|
159
|
-
def include_item(date:)
|
160
|
-
@list.each do |item|
|
161
|
-
return item if item.include?(date: date)
|
162
|
-
end
|
163
|
-
|
164
|
-
Gengou.new
|
165
|
-
end
|
166
|
-
|
167
|
-
#
|
168
|
-
# 元号セットが不正かどうかを確認する
|
169
|
-
#
|
170
|
-
# @return [True] 正しくない
|
171
|
-
# @return [False] 正しい
|
172
|
-
#
|
173
|
-
def invalid?
|
174
|
-
@id == -1
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|