zakuro 0.6.1 → 0.8.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 +46 -17
- 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 +49 -3
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +26 -24
- data/lib/zakuro/calculation/base/year.rb +7 -7
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
- data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
- data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +44 -37
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
- 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 +156 -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 +73 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
- data/lib/zakuro/calculation/era/version/version.rb +12 -10
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
- data/lib/zakuro/calculation/monthly/const.rb +18 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
- data/lib/zakuro/calculation/monthly/month.rb +55 -16
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- 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} +45 -29
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
- 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 +64 -63
- 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_term.rb +220 -0
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
- data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +127 -0
- data/lib/zakuro/calculation/summary/western/single.rb +115 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +143 -94
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +119 -0
- data/lib/zakuro/context/version_class_resolver.rb +112 -0
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
- data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +28 -41
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +104 -88
- 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 +39 -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 +81 -0
- data/lib/zakuro/merchant.rb +67 -33
- data/lib/zakuro/operation/month/parser.rb +252 -249
- data/lib/zakuro/operation/month/type.rb +44 -35
- data/lib/zakuro/operation/month/validator.rb +182 -178
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +107 -141
- 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/month/annotation.rb +40 -0
- data/lib/zakuro/result/operation/month/history.rb +54 -0
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +22 -97
- data/lib/zakuro/result/result.rb +6 -4
- data/lib/zakuro/tools/stringifier.rb +67 -42
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
- data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
- data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
- 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/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
- metadata +68 -16
- data/lib/zakuro/calculation/range/operated_range.rb +0 -193
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
- 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/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -6,36 +6,51 @@ require_relative './resource'
|
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
9
|
-
#
|
10
|
-
# Japan 和暦
|
11
|
-
#
|
9
|
+
# :nodoc:
|
12
10
|
module Japan
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
#
|
14
|
+
# Alignment 整列
|
15
|
+
#
|
16
|
+
module Alignment
|
17
|
+
# @return [Integer] 1行目元号
|
18
|
+
FIRST_LINE = Aligner::FIRST_LINE
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# @return [Integer] 2行目元号
|
21
|
+
SECOND_LINE = Aligner::SECOND_LINE
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# @return [Aligner] 整列結果
|
24
|
+
SUMMARY = Aligner.new(resources: Resource::LIST)
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
class << self
|
27
|
+
#
|
28
|
+
# 指定した範囲内の元号を取得する
|
29
|
+
#
|
30
|
+
# @param [Integer] line 行
|
31
|
+
# @param [Western::Calendar] start_date 開始日
|
32
|
+
# @param [Western::Calendar] last_date 終了日
|
33
|
+
#
|
34
|
+
# @return [Array<LinearGengou>] 元号
|
35
|
+
#
|
36
|
+
def get(line: FIRST_LINE,
|
37
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
38
|
+
|
39
|
+
SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
|
40
|
+
end
|
37
41
|
|
38
|
-
|
42
|
+
#
|
43
|
+
# 指定した範囲内の元号を取得する(元号名)
|
44
|
+
#
|
45
|
+
# @param [Integer] line 行
|
46
|
+
# @param [String] name 元号名
|
47
|
+
#
|
48
|
+
# @return [Array<LinearGengou>] 元号
|
49
|
+
#
|
50
|
+
def get_by_name(line: FIRST_LINE, name:)
|
51
|
+
SUMMARY.get_by_name(line: line, name: name)
|
52
|
+
end
|
53
|
+
end
|
39
54
|
end
|
40
55
|
end
|
41
56
|
end
|
@@ -7,236 +7,254 @@ require 'yaml'
|
|
7
7
|
|
8
8
|
# :nodoc:
|
9
9
|
module Zakuro
|
10
|
-
#
|
11
|
-
# Japan 和暦
|
12
|
-
#
|
10
|
+
# :nodoc:
|
13
11
|
module Japan
|
14
|
-
#
|
15
|
-
|
16
|
-
#
|
17
|
-
module Resource
|
18
|
-
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
19
|
-
|
12
|
+
# :nodoc:
|
13
|
+
module Gengou
|
20
14
|
#
|
21
|
-
#
|
15
|
+
# Resource yaml解析結果
|
22
16
|
#
|
23
|
-
module
|
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
|
17
|
+
module Resource
|
18
|
+
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
63
19
|
|
64
20
|
#
|
65
|
-
#
|
21
|
+
# Parser yaml解析
|
66
22
|
#
|
67
|
-
|
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
|
-
# 元号セット情報を生成する
|
23
|
+
module Parser
|
94
24
|
#
|
95
|
-
#
|
25
|
+
# GengouParser 元号情報の検証/展開を行う
|
96
26
|
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
106
36
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
gengou: gengou)
|
119
|
-
result.push(gengou)
|
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']
|
120
48
|
end
|
121
49
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
50
|
+
#
|
51
|
+
# 元号情報を生成する
|
52
|
+
#
|
53
|
+
# @return [Gengou] 元号情報
|
54
|
+
#
|
55
|
+
def create
|
56
|
+
start_year = Both::YearParser.new(hash: both_start_year).create
|
57
|
+
start_date = Both::DateParser.new(hash: both_start_date).create
|
126
58
|
|
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(str: @both_last_date['western'])
|
139
|
-
gengou.write_last_date(last_date: last_date)
|
140
|
-
return gengou
|
59
|
+
Gengou.new(name: name, both_start_year: start_year,
|
60
|
+
both_start_date: start_date)
|
141
61
|
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
62
|
end
|
151
|
-
end
|
152
63
|
|
153
|
-
#
|
154
|
-
# 和暦/西暦
|
155
|
-
#
|
156
|
-
module Both
|
157
64
|
#
|
158
|
-
#
|
65
|
+
# SetParser 元号セット情報の検証/展開
|
159
66
|
#
|
160
|
-
class
|
161
|
-
# @return [
|
162
|
-
attr_reader :
|
163
|
-
# @return [
|
164
|
-
attr_reader :
|
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
|
165
78
|
|
166
79
|
#
|
167
80
|
# 初期化
|
168
81
|
#
|
169
|
-
# @param [Hash<String, Object>] hash
|
82
|
+
# @param [Hash<String, Object>] hash 元号セット情報
|
170
83
|
#
|
171
84
|
def initialize(hash:)
|
172
|
-
@
|
173
|
-
@
|
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']
|
174
90
|
end
|
175
91
|
|
176
92
|
#
|
177
|
-
#
|
93
|
+
# 元号セット情報を生成する
|
178
94
|
#
|
179
|
-
# @return [
|
95
|
+
# @return [Set] 元号セット情報
|
180
96
|
#
|
181
97
|
def create
|
182
|
-
|
183
|
-
|
98
|
+
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: last_date, list: list
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
184
106
|
|
185
|
-
|
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
|
186
123
|
end
|
187
|
-
end
|
188
124
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
# @
|
194
|
-
|
195
|
-
# @return [
|
196
|
-
|
125
|
+
#
|
126
|
+
# 次の元号の開始日から、元号の終了日に変換する
|
127
|
+
#
|
128
|
+
# @param [Integer] next_index 次の元号の要素位置
|
129
|
+
# @param [GengouParser] gengou 元号
|
130
|
+
#
|
131
|
+
# @return [Gengou] 元号情報
|
132
|
+
#
|
133
|
+
def calc_last_date_on_gengou_data(next_index:, gengou:)
|
134
|
+
if next_index >= list.size
|
135
|
+
last_gengou_data(gengou: gengou)
|
136
|
+
return gengou
|
137
|
+
end
|
138
|
+
next_item = list[next_index]
|
139
|
+
gengou.convert_next_start_year_to_last_year(
|
140
|
+
next_start_year: next_item['start_year']['western']
|
141
|
+
)
|
142
|
+
gengou.convert_next_start_date_to_last_date(
|
143
|
+
next_start_date: next_item['start_date']['western']
|
144
|
+
)
|
145
|
+
gengou
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
197
149
|
|
198
150
|
#
|
199
|
-
#
|
151
|
+
# 最後の元号の終了日を設定する
|
200
152
|
#
|
201
|
-
# @param [
|
153
|
+
# @param [GengouParser] gengou 元号
|
202
154
|
#
|
203
|
-
def
|
204
|
-
|
205
|
-
|
155
|
+
def last_gengou_data(gengou:)
|
156
|
+
gengou.write_last_year(last_year: both_last_year['western'])
|
157
|
+
last_date = Western::Calendar.parse(text: both_last_date['western'])
|
158
|
+
gengou.write_last_date(last_date: last_date)
|
206
159
|
end
|
160
|
+
end
|
207
161
|
|
162
|
+
#
|
163
|
+
# 和暦/西暦
|
164
|
+
#
|
165
|
+
module Both
|
208
166
|
#
|
209
|
-
#
|
167
|
+
# YearParser 年
|
210
168
|
#
|
211
|
-
|
169
|
+
class YearParser
|
170
|
+
# @return [Integer] 和暦元号年
|
171
|
+
attr_reader :japan
|
172
|
+
# @return [Integer] 西暦年
|
173
|
+
attr_reader :western
|
174
|
+
|
175
|
+
#
|
176
|
+
# 初期化
|
177
|
+
#
|
178
|
+
# @param [Hash<String, Object>] hash 年情報
|
179
|
+
#
|
180
|
+
def initialize(hash:)
|
181
|
+
@japan = hash['japan']
|
182
|
+
@western = hash['western']
|
183
|
+
end
|
184
|
+
|
185
|
+
#
|
186
|
+
# 年情報を生成する
|
187
|
+
#
|
188
|
+
# @return [Both::Year] 年情報
|
189
|
+
#
|
190
|
+
def create
|
191
|
+
japan_year = japan.to_i
|
192
|
+
western_year = western.to_i
|
193
|
+
|
194
|
+
Japan::Gengou::Resource::Both::Year.new(
|
195
|
+
japan: japan_year, western: western_year
|
196
|
+
)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
212
200
|
#
|
213
|
-
|
214
|
-
|
215
|
-
|
201
|
+
# DateParser 日
|
202
|
+
#
|
203
|
+
class DateParser
|
204
|
+
# @return [Japan::Calendar] 和暦日
|
205
|
+
attr_reader :japan
|
206
|
+
# @return [Western::Calendar] 西暦日
|
207
|
+
attr_reader :western
|
208
|
+
|
209
|
+
#
|
210
|
+
# 初期化
|
211
|
+
#
|
212
|
+
# @param [Hash<String, Object>] hash 日情報
|
213
|
+
#
|
214
|
+
def initialize(hash:)
|
215
|
+
@japan = hash['japan']
|
216
|
+
@western = hash['western']
|
217
|
+
end
|
218
|
+
|
219
|
+
#
|
220
|
+
# 日情報を生成する
|
221
|
+
#
|
222
|
+
# @return [Both::Date] 日情報
|
223
|
+
#
|
224
|
+
def create
|
225
|
+
japan_date = Japan::Calendar.parse(text: japan)
|
226
|
+
western_date = Western::Calendar.parse(text: western)
|
216
227
|
|
217
|
-
|
228
|
+
Japan::Gengou::Resource::Both::Date.new(
|
229
|
+
japan: japan_date, western: western_date
|
230
|
+
)
|
231
|
+
end
|
218
232
|
end
|
219
233
|
end
|
220
|
-
end
|
221
234
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
235
|
+
class << self
|
236
|
+
#
|
237
|
+
# 解析/展開する
|
238
|
+
#
|
239
|
+
# @param [String] filepath 元号セットファイルパス
|
240
|
+
#
|
241
|
+
# @return [Set] 元号セット情報
|
242
|
+
#
|
243
|
+
# @raise [ArgumentError] 引数エラー
|
244
|
+
#
|
245
|
+
def run(filepath: '')
|
246
|
+
yaml = YAML.load_file(filepath)
|
231
247
|
|
232
|
-
|
248
|
+
failed = Validator.run(yaml_hash: yaml)
|
233
249
|
|
234
|
-
|
250
|
+
raise ArgumentError, failed.join("\n") unless failed.empty?
|
235
251
|
|
236
|
-
|
237
|
-
|
252
|
+
parser = SetParser.new(hash: yaml)
|
253
|
+
parser.create
|
254
|
+
end
|
255
|
+
end
|
238
256
|
end
|
239
257
|
end
|
258
|
+
end
|
240
259
|
end
|
241
260
|
end
|
242
|
-
end
|