zakuro 0.6.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +58 -16
  4. data/VERSION +1 -1
  5. data/doc/dropped_date.md +93 -0
  6. data/doc/error.md +45 -0
  7. data/doc/operation/transfer.rb +8 -8
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +50 -4
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +6 -6
  11. data/lib/zakuro/calculation/base/operated_year.rb +3 -3
  12. data/lib/zakuro/calculation/base/year.rb +4 -4
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +5 -3
  14. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
  15. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  17. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  26. data/lib/zakuro/calculation/{gengou → era/gengou}/internal/reserve.rb +6 -7
  27. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  28. data/lib/zakuro/calculation/{version → era/version}/internal/crawler.rb +7 -7
  29. data/lib/zakuro/calculation/{version → era/version}/internal/range.rb +4 -4
  30. data/lib/zakuro/calculation/{version → era/version}/version.rb +3 -3
  31. data/lib/zakuro/calculation/monthly/initialized_month.rb +1 -1
  32. data/lib/zakuro/calculation/monthly/month.rb +44 -5
  33. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  34. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  35. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  36. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +29 -27
  37. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +11 -14
  38. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  39. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  40. data/lib/zakuro/calculation/range/medieval_annual_range.rb +2 -2
  41. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  42. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  43. data/lib/zakuro/calculation/range/operated_solar_terms.rb +9 -11
  44. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +6 -6
  45. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +2 -0
  46. data/lib/zakuro/calculation/summary/internal/day.rb +40 -0
  47. data/lib/zakuro/calculation/summary/internal/month.rb +92 -0
  48. data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -40
  49. data/lib/zakuro/calculation/summary/internal/option.rb +85 -0
  50. data/lib/zakuro/calculation/summary/japan/range.rb +158 -0
  51. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  52. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +96 -0
  53. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  54. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  55. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +174 -0
  56. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +98 -0
  57. data/lib/zakuro/calculation/type/optional.rb +46 -0
  58. data/lib/zakuro/condition.rb +75 -22
  59. data/lib/zakuro/context/context.rb +44 -0
  60. data/lib/zakuro/context/option.rb +117 -0
  61. data/lib/zakuro/context/version_class_resolver.rb +110 -0
  62. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +125 -0
  63. data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
  64. data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
  65. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
  66. data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
  67. data/lib/zakuro/era/japan/gengou/resource/parser.rb +245 -0
  68. data/lib/zakuro/era/japan/gengou/resource/type.rb +299 -0
  69. data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
  70. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-001-until-south.yaml +2 -2
  71. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-002-from-north.yaml +2 -2
  72. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-003-modern.yaml +2 -2
  73. data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
  74. data/lib/zakuro/era/japan/gengou.rb +25 -79
  75. data/lib/zakuro/era/japan/version.rb +18 -18
  76. data/lib/zakuro/era/western/calendar.rb +13 -9
  77. data/lib/zakuro/exception/case/pattern.rb +71 -0
  78. data/lib/zakuro/exception/case/preset.rb +51 -0
  79. data/lib/zakuro/exception/case/template.rb +48 -0
  80. data/lib/zakuro/exception/cause.rb +28 -0
  81. data/lib/zakuro/exception/exception.rb +37 -0
  82. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  83. data/lib/zakuro/gateway/locale/date.rb +127 -0
  84. data/lib/zakuro/gateway/locale/range.rb +67 -0
  85. data/lib/zakuro/gateway/range.rb +99 -0
  86. data/lib/zakuro/gateway/single.rb +70 -0
  87. data/lib/zakuro/merchant.rb +84 -12
  88. data/lib/zakuro/operation/month/parser.rb +11 -9
  89. data/lib/zakuro/operation/month/type.rb +31 -31
  90. data/lib/zakuro/operation/month/validator.rb +50 -50
  91. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  92. data/lib/zakuro/output/logger.rb +17 -3
  93. data/lib/zakuro/output/response.rb +24 -57
  94. data/lib/zakuro/result/data/day.rb +43 -0
  95. data/lib/zakuro/result/data/gengou.rb +35 -0
  96. data/lib/zakuro/result/data/month.rb +63 -0
  97. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  98. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  99. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  100. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  101. data/lib/zakuro/result/data/single_day.rb +56 -0
  102. data/lib/zakuro/result/data/solar_term.rb +35 -0
  103. data/lib/zakuro/result/data/year.rb +45 -0
  104. data/lib/zakuro/result/operation/bundle.rb +44 -0
  105. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  106. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  107. data/lib/zakuro/result/operation/month/history.rb +54 -0
  108. data/lib/zakuro/result/result.rb +21 -2
  109. data/lib/zakuro/tools/stringifier.rb +26 -3
  110. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  111. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  112. data/lib/zakuro/version/daien/range/annual_range.rb +1 -1
  113. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +2 -0
  114. data/lib/zakuro/version/daien/stella/lunar/value.rb +2 -0
  115. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  116. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  117. data/lib/zakuro/version/genka/range/annual_range.rb +1 -1
  118. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  119. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  120. data/lib/zakuro/version/gihou/range/annual_range.rb +1 -1
  121. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +2 -0
  122. data/lib/zakuro/version/gihou/stella/lunar/value.rb +2 -0
  123. data/lib/zakuro/version/senmyou/README.md +11 -7
  124. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  125. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  126. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  127. data/lib/zakuro/version/senmyou/range/annual_range.rb +1 -1
  128. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +2 -0
  129. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +2 -0
  130. metadata +85 -24
  131. data/lib/zakuro/calculation/gengou/internal/counter.rb +0 -129
  132. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +0 -183
  133. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +0 -382
  134. data/lib/zakuro/calculation/gengou/scroll.rb +0 -262
  135. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  136. data/lib/zakuro/era/japan/gengou/parser.rb +0 -237
  137. data/lib/zakuro/era/japan/gengou/type.rb +0 -285
  138. data/lib/zakuro/era/japan/gengou/validator.rb +0 -341
  139. data/lib/zakuro/result/data.rb +0 -187
  140. data/lib/zakuro/result/operation.rb +0 -114
  141. data/lib/zakuro/version/context.rb +0 -44
  142. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../base/year'
4
-
5
- require_relative '../../era/western/calendar'
6
- require_relative '../../output/response'
7
- require_relative '../../output/logger'
8
-
9
- # :nodoc:
10
- module Zakuro
11
- # :nodoc:
12
- module Calculation
13
- # :nodoc:
14
- module Specifier
15
- #
16
- # SingleDay 一日検索
17
- #
18
- module SingleDay
19
- # @return [Output::Logger] ロガー
20
- LOGGER = Output::Logger.new(location: 'specifier')
21
-
22
- #
23
- # 取得する
24
- #
25
- # @param [Array<Year>] yeas 範囲
26
- # @param [Western::Calendar] date 西暦日
27
- #
28
- # @return [Result::Data::SingleDay] 和暦日
29
- #
30
- def self.get(years: [], date: Western::Calendar.new)
31
- year, month = specify(years: years, date: date)
32
- first_date = month.western_date
33
-
34
- Output::Response::SingleDay.save_single_day(
35
- param: Output::Response::SingleDay::Param.new(
36
- year: year, month: month,
37
- date: date, days: date - first_date
38
- )
39
- )
40
- end
41
-
42
- #
43
- # 年を特定する
44
- #
45
- # @param [Array<Year>] years 範囲
46
- # @param [Western::Calendar] date 西暦日
47
- #
48
- # @return [Base::Year] 対象年
49
- # @return [Base::Month] 対象月
50
- #
51
- def self.specify(years:, date:)
52
- years.each do |year|
53
- month = specify_month(year: year, date: date)
54
- return year, month unless month.invalid?
55
- end
56
-
57
- raise ArgumentError, "invalid year range. date: #{date.format}"
58
- end
59
- private_class_method :specify
60
-
61
- # :reek:TooManyStatements { max_statements: 7 }
62
-
63
- #
64
- # 月を特定する
65
- #
66
- # @param [Year] year 年
67
- # @param [Western::Calendar] date 西暦日
68
- #
69
- # @return [Month] 対象月
70
- #
71
- def self.specify_month(year:, date:)
72
- months = year.months
73
-
74
- months.each do |month|
75
- western_date = month.western_date
76
- next if western_date.invalid?
77
-
78
- return month if month.include?(date: date)
79
- end
80
-
81
- Monthly::Month.new
82
- end
83
- private_class_method :specify_month
84
- end
85
- end
86
- end
87
- end
@@ -1,237 +0,0 @@
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
- #
11
- # Japan 和暦
12
- #
13
- module Japan
14
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
15
-
16
- #
17
- # Parser yaml解析
18
- #
19
- module Parser
20
- #
21
- # GengouParser 元号情報の検証/展開を行う
22
- #
23
- class GengouParser
24
- # @return [Integer] 要素位置
25
- attr_reader :index
26
- # @return [String] 元号名
27
- attr_reader :name
28
- # @return [Hash<String, String>] 開始年
29
- attr_reader :both_start_year
30
- # @return [Hash<String, String>] 開始日
31
- attr_reader :both_start_date
32
-
33
- #
34
- # 初期化
35
- #
36
- # @param [Hash<String, Strin>] hash 元号情報
37
- # @param [Integer] index (元号セット内での)元号の要素位置
38
- #
39
- def initialize(hash:, index:)
40
- @index = index
41
- @name = hash['name']
42
- @both_start_year = hash['start_year']
43
- @both_start_date = hash['start_date']
44
- end
45
-
46
- #
47
- # 元号情報を生成する
48
- #
49
- # @return [Gengou] 元号情報
50
- #
51
- def create
52
- both_start_year = Both::YearParser.new(hash: @both_start_year).create
53
- both_start_date = Both::DateParser.new(hash: @both_start_date).create
54
-
55
- Gengou.new(name: @name, both_start_year: both_start_year,
56
- both_start_date: both_start_date)
57
- end
58
- end
59
-
60
- #
61
- # SetParser 元号セット情報の検証/展開
62
- #
63
- class SetParser
64
- # @return [String] 元号セットID
65
- attr_reader :id
66
- # @return [String] 元号セット名
67
- attr_reader :name
68
- # @return [Hash<String, String>] 終了年
69
- attr_reader :both_end_year
70
- # @return [Hash<String, String>] 終了日
71
- attr_reader :both_end_date
72
- # @return [Array<Hash<String, String>>] 元号情報
73
- attr_reader :list
74
-
75
- #
76
- # 初期化
77
- #
78
- # @param [Hash<String, Object>] hash 元号セット情報
79
- #
80
- def initialize(hash:)
81
- @id = hash['id']
82
- @name = hash['name']
83
- @both_end_year = hash['end_year']
84
- @both_end_date = hash['end_date']
85
- @list = hash['list']
86
- end
87
-
88
- #
89
- # 元号セット情報を生成する
90
- #
91
- # @return [Set] 元号セット情報
92
- #
93
- def create
94
- both_end_date = Both::DateParser.new(hash: @both_end_date).create
95
- list = create_list
96
- Set.new(
97
- id: @id, name: @name, both_end_date: both_end_date, list: list
98
- )
99
- end
100
-
101
- # :reek:TooManyStatements { max_statements: 7 }
102
-
103
- #
104
- # 元号情報を生成する
105
- #
106
- # @return [Array<Gengou>] 元号情報
107
- #
108
- def create_list
109
- result = []
110
- @list.each_with_index do |li, index|
111
- gengou = GengouParser.new(hash: li, index: index).create
112
- next_index = index + 1
113
- gengou = calc_end_date_on_gengou_data(next_index: next_index,
114
- gengou: gengou)
115
- result.push(gengou)
116
- end
117
-
118
- result
119
- end
120
-
121
- # :reek:TooManyStatements { max_statements: 6 }
122
-
123
- #
124
- # 次の元号の開始日から、元号の終了日に変換する
125
- #
126
- # @param [Integer] next_index 次の元号の要素位置
127
- # @param [String] gengou 次回開始日
128
- #
129
- # @return [Gengou] 元号情報
130
- #
131
- def calc_end_date_on_gengou_data(next_index:, gengou:)
132
- if next_index >= @list.size
133
- gengou.write_end_year(end_year: @both_end_year['western'])
134
- end_date = Western::Calendar.parse(str: @both_end_date['western'])
135
- gengou.write_end_date(end_date: end_date)
136
- return gengou
137
- end
138
- next_item = @list[next_index]
139
- gengou.convert_next_start_year_to_end_year(
140
- next_start_year: next_item['start_year']['western']
141
- )
142
- gengou.convert_next_start_date_to_end_date(
143
- next_start_date: next_item['start_date']['western']
144
- )
145
- gengou
146
- end
147
- end
148
-
149
- #
150
- # 和暦/西暦
151
- #
152
- module Both
153
- #
154
- # YearParser 年
155
- #
156
- class YearParser
157
- # @return [Integer] 和暦元号年
158
- attr_reader :japan
159
- # @return [Integer] 西暦年
160
- attr_reader :western
161
-
162
- #
163
- # 初期化
164
- #
165
- # @param [Hash<String, Object>] hash 年情報
166
- #
167
- def initialize(hash:)
168
- @japan = hash['japan']
169
- @western = hash['western']
170
- end
171
-
172
- #
173
- # 年情報を生成する
174
- #
175
- # @return [Both::Year] 年情報
176
- #
177
- def create
178
- japan = @japan.to_i
179
- western = @western.to_i
180
-
181
- Japan::Both::Year.new(japan: japan, western: western)
182
- end
183
- end
184
-
185
- #
186
- # DateParser 日
187
- #
188
- class DateParser
189
- # @return [Japan::Calendar] 和暦日
190
- attr_reader :japan
191
- # @return [Western::Calendar] 西暦日
192
- attr_reader :western
193
-
194
- #
195
- # 初期化
196
- #
197
- # @param [Hash<String, Object>] hash 日情報
198
- #
199
- def initialize(hash:)
200
- @japan = hash['japan']
201
- @western = hash['western']
202
- end
203
-
204
- #
205
- # 日情報を生成する
206
- #
207
- # @return [Both::Date] 日情報
208
- #
209
- def create
210
- japan = Japan::Calendar.parse(text: @japan)
211
- western = Western::Calendar.parse(str: @western)
212
-
213
- Japan::Both::Date.new(japan: japan, western: western)
214
- end
215
- end
216
- end
217
-
218
- #
219
- # 解析/展開する
220
- #
221
- # @param [String] filepath 元号セットファイルパス
222
- #
223
- # @return [Set] 元号セット情報
224
- #
225
- def self.run(filepath: '')
226
- yaml = YAML.load_file(filepath)
227
-
228
- failed = Validator.run(yaml_hash: yaml)
229
-
230
- raise ArgumentError, failed.join("\n") unless failed.empty?
231
-
232
- parser = SetParser.new(hash: yaml)
233
- parser.create
234
- end
235
- end
236
- end
237
- end
@@ -1,285 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../western/calendar'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- #
8
- # Japan 和暦
9
- #
10
- module Japan
11
- #
12
- # Gengou 元号情報
13
- #
14
- class Gengou
15
- # @return [String] 元号名
16
- attr_reader :name
17
- # @return [Both::Year] 開始年(和暦/西暦)
18
- attr_reader :both_start_year
19
- # @return [Both::Date] 開始日(和暦/西暦)
20
- attr_reader :both_start_date
21
- # @return [Integer] 終了年
22
- attr_reader :end_year
23
- # @return [Western::Calendar] 終了日
24
- attr_reader :end_date
25
-
26
- #
27
- # 初期化
28
- #
29
- # @param [String] name 元号名
30
- # @param [Both::Year] both_start_year 開始年(和暦/西暦)
31
- # @param [Both::Date] both_start_date 開始日(和暦/西暦)
32
- # @param [Integer] end_date 終了年
33
- # @param [Western::Calendar] end_date 終了日
34
- #
35
- def initialize(name: '', both_start_year: Both::Year.new,
36
- both_start_date: Both::Date.new,
37
- end_date: Western::Calendar.new,
38
- end_year: Both::Year::INVALID)
39
- @name = name
40
- @both_start_year = both_start_year
41
- @both_start_date = both_start_date
42
- @end_year = end_year
43
- @end_date = end_date
44
- end
45
-
46
- #
47
- # 終了年を更新する
48
- #
49
- # @param [Integer] end_year 終了年
50
- #
51
- def write_end_year(end_year:)
52
- unless Gengou.valid_year(year: end_year)
53
- raise ArgumentError, "invalid year format. [#{end_year}]"
54
- end
55
-
56
- @end_year = end_year
57
- end
58
-
59
- #
60
- # 終了日を更新する
61
- #
62
- # @param [Western::Calendar] end_date 終了日
63
- #
64
- def write_end_date(end_date:)
65
- unless Gengou.valid_date(date: end_date)
66
- raise ArgumentError, "invalid date format. [#{end_date}]"
67
- end
68
-
69
- @end_date = end_date
70
- nil
71
- end
72
-
73
- #
74
- # 年が不正なしかどうかを確認する
75
- #
76
- # @param [Integer] year 年
77
- #
78
- # @return [True] 不正なし
79
- # @return [False] 不正
80
- #
81
- def self.valid_year(year:)
82
- return false unless year
83
-
84
- year.is_a?(Integer)
85
- end
86
-
87
- #
88
- # 日付が不正なしかどうかを確認する
89
- #
90
- # @param [Western::Calendar] date 日付
91
- #
92
- # @return [True] 不正なし
93
- # @return [False] 不正
94
- #
95
- def self.valid_date(date:)
96
- return false unless date
97
-
98
- date.is_a?(Western::Calendar)
99
- end
100
-
101
- #
102
- # 次の元号の開始年から、元号の終了年に変換する
103
- #
104
- # @param [Integer] next_start_year 次回開始年
105
- #
106
- def convert_next_start_year_to_end_year(next_start_year:)
107
- if @both_start_year.western >= next_start_year
108
- @end_year = next_start_year
109
- return
110
- end
111
-
112
- @end_year = next_start_year - 1
113
-
114
- nil
115
- end
116
-
117
- #
118
- # 次の元号の開始日から、元号の終了日に変換する
119
- #
120
- # @param [String] next_start_date 次回開始日
121
- #
122
- def convert_next_start_date_to_end_date(next_start_date: '')
123
- raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
124
-
125
- start_date = Western::Calendar.parse(str: next_start_date)
126
- @end_date = start_date - 1
127
-
128
- nil
129
- end
130
-
131
- #
132
- # 指定した日が元号に含まれるか
133
- #
134
- # @param [Western::Calendar] date 日
135
- #
136
- # @return [True] 含まれる
137
- # @return [False] 含まれない
138
- #
139
- def include?(date:)
140
- date >= @both_start_date.western && date <= @end_date
141
- end
142
-
143
- #
144
- # 不正か
145
- #
146
- # @return [True] 不正
147
- # @return [False] 不正なし
148
- #
149
- def invalid?
150
- @both_start_year.japan == -1 || @both_start_year.invalid? ||
151
- @both_start_date.invalid? || @end_date.invalid?
152
- end
153
-
154
- #
155
- # 1元号年を追加する
156
- #
157
- # def next_year
158
- # @year += 1 unless invalid?
159
- # nil
160
- # end
161
-
162
- def to_s
163
- "name: #{@name}, both_start_year: #{@both_start_year.format}, " \
164
- "both_start_date: #{@both_start_date.format}, end_date: #{@end_date.format}"
165
- end
166
- end
167
-
168
- #
169
- # Set 元号セット
170
- #
171
- class Set
172
- # @return [Integer] 不正値
173
- INVALID = -1
174
- # @return [Integer] 元号セットID
175
- attr_reader :id
176
- # @return [String] 元号セット名
177
- attr_reader :name
178
- # @return [Both::Date] 元号セットでの終了年
179
- attr_reader :both_end_year
180
- # @return [Both::Date] 元号セットでの終了日
181
- attr_reader :both_end_date
182
- # @return [Array<Gengou>] 元号リスト
183
- attr_reader :list
184
-
185
- #
186
- # 初期化
187
- #
188
- # @param [Integer] id 元号セットID
189
- # @param [String] name 元号セット名
190
- # @param [Western::Calendar] end_date 元号セットでの終了日
191
- # @param [Array<Gengou>] list 元号リスト
192
- #
193
- def initialize(id: INVALID, name: '', both_end_year: Both::Year.new,
194
- both_end_date: Both::Date.new, list: [])
195
- @id = id
196
- @name = name
197
- @both_end_year = both_end_year
198
- @both_end_date = both_end_date
199
- @list = list
200
- end
201
-
202
- #
203
- # 指定した日付を含む元号を返す
204
- #
205
- # @param [Western::Calendar] date 日
206
- #
207
- # @return [Gengou] 元号
208
- #
209
- def include_item(date:)
210
- @list.each do |item|
211
- return item if item.include?(date: date)
212
- end
213
-
214
- Gengou.new
215
- end
216
-
217
- #
218
- # 元号セットが不正かどうかを確認する
219
- #
220
- # @return [True] 正しくない
221
- # @return [False] 正しい
222
- #
223
- def invalid?
224
- @id == INVALID
225
- end
226
- end
227
-
228
- #
229
- # 和暦/西暦
230
- #
231
- module Both
232
- #
233
- # Year 年
234
- #
235
- class Year
236
- # @return [Integer] 不正値
237
- INVALID = -1
238
- # @return [Integer] 和暦元号年
239
- attr_reader :japan
240
- # @return [Integer] 西暦年
241
- attr_reader :western
242
-
243
- def initialize(japan: INVALID, western: INVALID)
244
- @japan = japan
245
- @western = western
246
- end
247
-
248
- #
249
- # 不正か
250
- #
251
- # @return [True] 不正
252
- # @return [False] 不正なし
253
- #
254
- def invalid?
255
- @japan == INVALID || @western == INVALID
256
- end
257
- end
258
-
259
- #
260
- # Date 日
261
- #
262
- class Date
263
- # @return [Japan::Calendar] 和暦日
264
- attr_reader :japan
265
- # @return [Western::Calendar] 西暦日
266
- attr_reader :western
267
-
268
- def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
269
- @japan = japan
270
- @western = western
271
- end
272
-
273
- #
274
- # 不正か
275
- #
276
- # @return [True] 不正
277
- # @return [False] 不正なし
278
- #
279
- def invalid?
280
- @japan.invalid? || @western.invalid?
281
- end
282
- end
283
- end
284
- end
285
- end