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
@@ -0,0 +1,187 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../western/calendar'
|
4
|
+
|
5
|
+
require_relative '../resource/type'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Japan
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
# :nodoc:
|
14
|
+
module Alignment
|
15
|
+
#
|
16
|
+
# LinearGengou 直列元号
|
17
|
+
#
|
18
|
+
class LinearGengou
|
19
|
+
INVALID_YEAR = -1
|
20
|
+
|
21
|
+
# @return [Western::Calendar] 開始日
|
22
|
+
attr_reader :start_date
|
23
|
+
# @return [Western::Calendar] 終了日
|
24
|
+
attr_reader :last_date
|
25
|
+
# @return [Gengou] 元号
|
26
|
+
attr_reader :gengou
|
27
|
+
|
28
|
+
#
|
29
|
+
# 初期化
|
30
|
+
#
|
31
|
+
# @param [Western::Calendar] start_date 開始日
|
32
|
+
# @param [Western::Calendar] last_date 終了日
|
33
|
+
# @param [Resource::Gengou] gengou 元号
|
34
|
+
#
|
35
|
+
def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
36
|
+
gengou: Resource::Gengou.new)
|
37
|
+
@gengou = gengou
|
38
|
+
@start_date = start_date.invalid? ? native_start_date : start_date
|
39
|
+
@last_date = last_date.invalid? ? native_last_date : last_date
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# 元号名を取得する
|
44
|
+
#
|
45
|
+
# @return [String] 元号名
|
46
|
+
#
|
47
|
+
def name
|
48
|
+
@gengou.name
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# 不正か
|
53
|
+
#
|
54
|
+
# @return [True] 不正
|
55
|
+
# @return [False] 不正なし
|
56
|
+
#
|
57
|
+
def invalid?
|
58
|
+
@gengou.invalid?
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# 範囲内か
|
63
|
+
#
|
64
|
+
# @param [Western::Calendar] date 西暦日
|
65
|
+
#
|
66
|
+
# @return [True] 範囲内
|
67
|
+
# @return [False] 範囲外
|
68
|
+
#
|
69
|
+
def include?(date: Western::Calendar.new)
|
70
|
+
return false if invalid?
|
71
|
+
|
72
|
+
return false if @start_date.invalid?
|
73
|
+
|
74
|
+
return false if @last_date.invalid?
|
75
|
+
|
76
|
+
return false if date < @start_date
|
77
|
+
|
78
|
+
return false if date > @last_date
|
79
|
+
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# 完全に範囲内か
|
85
|
+
#
|
86
|
+
# @param [Western::Calendar] start_date 開始日
|
87
|
+
# @param [Western::Calendar] last_date 終了日
|
88
|
+
#
|
89
|
+
# @return [True] 範囲内
|
90
|
+
# @return [False] 範囲外あり
|
91
|
+
#
|
92
|
+
def in?(start_date:, last_date:)
|
93
|
+
@start_date <= start_date && last_date <= @last_date
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# 完全に範囲外か
|
98
|
+
#
|
99
|
+
# @param [Western::Calendar] start_date 開始日
|
100
|
+
# @param [Western::Calendar] last_date 終了日
|
101
|
+
#
|
102
|
+
# @return [True] 範囲外
|
103
|
+
# @return [False] 範囲内あり
|
104
|
+
#
|
105
|
+
def out?(start_date:, last_date:)
|
106
|
+
# 範囲より前
|
107
|
+
return true if start_date < @start_date && last_date < @start_date
|
108
|
+
|
109
|
+
# 範囲より後
|
110
|
+
return true if @last_date < start_date && @last_date < last_date
|
111
|
+
|
112
|
+
false
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
# 完全に範囲を超えているか
|
117
|
+
#
|
118
|
+
# @param [Western::Calendar] start_date 開始日
|
119
|
+
# @param [Western::Calendar] last_date 終了日
|
120
|
+
#
|
121
|
+
# @return [True] 完全超過
|
122
|
+
# @return [True] 完全超過せず
|
123
|
+
#
|
124
|
+
def covered?(start_date:, last_date:)
|
125
|
+
start_date < @start_date && @last_date < last_date
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# 元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?
|
130
|
+
#
|
131
|
+
# @return [True] 存在する
|
132
|
+
# @return [False] 存在しない
|
133
|
+
#
|
134
|
+
def changed?
|
135
|
+
return true if change_start_date?
|
136
|
+
|
137
|
+
return true if change_last_date?
|
138
|
+
|
139
|
+
false
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# 開始日が設定された開始日と異なるか(行が変更されているか)
|
144
|
+
#
|
145
|
+
# @return [True] 異なる
|
146
|
+
# @return [False] 同一
|
147
|
+
#
|
148
|
+
def change_start_date?
|
149
|
+
return false if invalid?
|
150
|
+
|
151
|
+
@start_date != native_start_date
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# 終了日が設定された終了日と異なるか(行が変更されているか)
|
156
|
+
#
|
157
|
+
# @return [True] 異なる
|
158
|
+
# @return [False] 同一
|
159
|
+
#
|
160
|
+
def change_last_date?
|
161
|
+
return false if invalid?
|
162
|
+
|
163
|
+
@last_date != native_last_date
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# 設定された元号の開始日を取得する
|
168
|
+
#
|
169
|
+
# @return [Western::Calendar]設定された元号の開始日
|
170
|
+
#
|
171
|
+
def native_start_date
|
172
|
+
@gengou.both_start_date.western
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# 設定された元号の終了日を取得する
|
177
|
+
#
|
178
|
+
# @return [Western::Calendar] 設定された元号の終了日
|
179
|
+
#
|
180
|
+
def native_last_date
|
181
|
+
@gengou.last_date
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './alignment/aligner'
|
4
|
+
|
5
|
+
require_relative './resource'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Japan
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
#
|
14
|
+
# Alignment 整列
|
15
|
+
#
|
16
|
+
module Alignment
|
17
|
+
# @return [Integer] 1行目元号
|
18
|
+
FIRST_LINE = Aligner::FIRST_LINE
|
19
|
+
|
20
|
+
# @return [Integer] 2行目元号
|
21
|
+
SECOND_LINE = Aligner::SECOND_LINE
|
22
|
+
|
23
|
+
# @return [Aligner] 整列結果
|
24
|
+
SUMMARY = Aligner.new(resources: Resource::LIST)
|
25
|
+
|
26
|
+
#
|
27
|
+
# 指定した範囲内の元号を取得する
|
28
|
+
#
|
29
|
+
# @param [Integer] line 行
|
30
|
+
# @param [Western::Calendar] start_date 開始日
|
31
|
+
# @param [Western::Calendar] last_date 終了日
|
32
|
+
#
|
33
|
+
# @return [Array<LinearGengou>] 元号
|
34
|
+
#
|
35
|
+
def self.get(line: FIRST_LINE,
|
36
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
37
|
+
|
38
|
+
SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# 指定した範囲内の元号を取得する(元号名)
|
43
|
+
#
|
44
|
+
# @param [Integer] line 行
|
45
|
+
# @param [String] name 元号名
|
46
|
+
#
|
47
|
+
# @return [Array<LinearGengou>] 元号
|
48
|
+
#
|
49
|
+
def self.get_by_name(line: FIRST_LINE, name:)
|
50
|
+
SUMMARY.get_by_name(line: line, name: name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../western/calendar'
|
4
|
+
require_relative './type'
|
5
|
+
require_relative './validator'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
module Zakuro
|
10
|
+
# :nodoc:
|
11
|
+
module Japan
|
12
|
+
# :nodoc:
|
13
|
+
module Gengou
|
14
|
+
#
|
15
|
+
# Resource yaml解析結果
|
16
|
+
#
|
17
|
+
module Resource
|
18
|
+
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
19
|
+
|
20
|
+
#
|
21
|
+
# Parser yaml解析
|
22
|
+
#
|
23
|
+
module Parser
|
24
|
+
#
|
25
|
+
# GengouParser 元号情報の検証/展開を行う
|
26
|
+
#
|
27
|
+
class GengouParser
|
28
|
+
# @return [Integer] 要素位置
|
29
|
+
attr_reader :index
|
30
|
+
# @return [String] 元号名
|
31
|
+
attr_reader :name
|
32
|
+
# @return [Hash<String, String>] 開始年
|
33
|
+
attr_reader :both_start_year
|
34
|
+
# @return [Hash<String, String>] 開始日
|
35
|
+
attr_reader :both_start_date
|
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
|
+
@both_start_year = hash['start_year']
|
47
|
+
@both_start_date = hash['start_date']
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# 元号情報を生成する
|
52
|
+
#
|
53
|
+
# @return [Gengou] 元号情報
|
54
|
+
#
|
55
|
+
def create
|
56
|
+
both_start_year = Both::YearParser.new(hash: @both_start_year).create
|
57
|
+
both_start_date = Both::DateParser.new(hash: @both_start_date).create
|
58
|
+
|
59
|
+
Gengou.new(name: @name, both_start_year: both_start_year,
|
60
|
+
both_start_date: both_start_date)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# SetParser 元号セット情報の検証/展開
|
66
|
+
#
|
67
|
+
class SetParser
|
68
|
+
# @return [String] 元号セットID
|
69
|
+
attr_reader :id
|
70
|
+
# @return [String] 元号セット名
|
71
|
+
attr_reader :name
|
72
|
+
# @return [Hash<String, String>] 終了年
|
73
|
+
attr_reader :both_last_year
|
74
|
+
# @return [Hash<String, String>] 終了日
|
75
|
+
attr_reader :both_last_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
|
+
@both_last_year = hash['last_year']
|
88
|
+
@both_last_date = hash['last_date']
|
89
|
+
@list = hash['list']
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# 元号セット情報を生成する
|
94
|
+
#
|
95
|
+
# @return [Set] 元号セット情報
|
96
|
+
#
|
97
|
+
def create
|
98
|
+
both_last_date = Both::DateParser.new(hash: @both_last_date).create
|
99
|
+
list = create_list
|
100
|
+
Set.new(
|
101
|
+
id: @id, name: @name, both_last_date: both_last_date, list: list
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
106
|
+
|
107
|
+
#
|
108
|
+
# 元号情報を生成する
|
109
|
+
#
|
110
|
+
# @return [Array<Gengou>] 元号情報
|
111
|
+
#
|
112
|
+
def create_list
|
113
|
+
result = []
|
114
|
+
@list.each_with_index do |li, index|
|
115
|
+
gengou = GengouParser.new(hash: li, index: index).create
|
116
|
+
next_index = index + 1
|
117
|
+
gengou = calc_last_date_on_gengou_data(next_index: next_index,
|
118
|
+
gengou: gengou)
|
119
|
+
result.push(gengou)
|
120
|
+
end
|
121
|
+
|
122
|
+
result
|
123
|
+
end
|
124
|
+
|
125
|
+
# :reek:TooManyStatements { max_statements: 6 }
|
126
|
+
|
127
|
+
#
|
128
|
+
# 次の元号の開始日から、元号の終了日に変換する
|
129
|
+
#
|
130
|
+
# @param [Integer] next_index 次の元号の要素位置
|
131
|
+
# @param [String] gengou 次回開始日
|
132
|
+
#
|
133
|
+
# @return [Gengou] 元号情報
|
134
|
+
#
|
135
|
+
def calc_last_date_on_gengou_data(next_index:, gengou:)
|
136
|
+
if next_index >= @list.size
|
137
|
+
gengou.write_last_year(last_year: @both_last_year['western'])
|
138
|
+
last_date = Western::Calendar.parse(text: @both_last_date['western'])
|
139
|
+
gengou.write_last_date(last_date: last_date)
|
140
|
+
return gengou
|
141
|
+
end
|
142
|
+
next_item = @list[next_index]
|
143
|
+
gengou.convert_next_start_year_to_last_year(
|
144
|
+
next_start_year: next_item['start_year']['western']
|
145
|
+
)
|
146
|
+
gengou.convert_next_start_date_to_last_date(
|
147
|
+
next_start_date: next_item['start_date']['western']
|
148
|
+
)
|
149
|
+
gengou
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
#
|
154
|
+
# 和暦/西暦
|
155
|
+
#
|
156
|
+
module Both
|
157
|
+
#
|
158
|
+
# YearParser 年
|
159
|
+
#
|
160
|
+
class YearParser
|
161
|
+
# @return [Integer] 和暦元号年
|
162
|
+
attr_reader :japan
|
163
|
+
# @return [Integer] 西暦年
|
164
|
+
attr_reader :western
|
165
|
+
|
166
|
+
#
|
167
|
+
# 初期化
|
168
|
+
#
|
169
|
+
# @param [Hash<String, Object>] hash 年情報
|
170
|
+
#
|
171
|
+
def initialize(hash:)
|
172
|
+
@japan = hash['japan']
|
173
|
+
@western = hash['western']
|
174
|
+
end
|
175
|
+
|
176
|
+
#
|
177
|
+
# 年情報を生成する
|
178
|
+
#
|
179
|
+
# @return [Both::Year] 年情報
|
180
|
+
#
|
181
|
+
def create
|
182
|
+
japan = @japan.to_i
|
183
|
+
western = @western.to_i
|
184
|
+
|
185
|
+
Japan::Gengou::Resource::Both::Year.new(japan: japan, western: western)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# DateParser 日
|
191
|
+
#
|
192
|
+
class DateParser
|
193
|
+
# @return [Japan::Calendar] 和暦日
|
194
|
+
attr_reader :japan
|
195
|
+
# @return [Western::Calendar] 西暦日
|
196
|
+
attr_reader :western
|
197
|
+
|
198
|
+
#
|
199
|
+
# 初期化
|
200
|
+
#
|
201
|
+
# @param [Hash<String, Object>] hash 日情報
|
202
|
+
#
|
203
|
+
def initialize(hash:)
|
204
|
+
@japan = hash['japan']
|
205
|
+
@western = hash['western']
|
206
|
+
end
|
207
|
+
|
208
|
+
#
|
209
|
+
# 日情報を生成する
|
210
|
+
#
|
211
|
+
# @return [Both::Date] 日情報
|
212
|
+
#
|
213
|
+
def create
|
214
|
+
japan = Japan::Calendar.parse(text: @japan)
|
215
|
+
western = Western::Calendar.parse(text: @western)
|
216
|
+
|
217
|
+
Japan::Gengou::Resource::Both::Date.new(japan: japan, western: western)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
#
|
223
|
+
# 解析/展開する
|
224
|
+
#
|
225
|
+
# @param [String] filepath 元号セットファイルパス
|
226
|
+
#
|
227
|
+
# @return [Set] 元号セット情報
|
228
|
+
#
|
229
|
+
# @raise [ArgumentError] 引数エラー
|
230
|
+
#
|
231
|
+
def self.run(filepath: '')
|
232
|
+
yaml = YAML.load_file(filepath)
|
233
|
+
|
234
|
+
failed = Validator.run(yaml_hash: yaml)
|
235
|
+
|
236
|
+
raise ArgumentError, failed.join("\n") unless failed.empty?
|
237
|
+
|
238
|
+
parser = SetParser.new(hash: yaml)
|
239
|
+
parser.create
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|