zakuro 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +46 -17
  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 +49 -3
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  11. data/lib/zakuro/calculation/base/operated_year.rb +26 -24
  12. data/lib/zakuro/calculation/base/year.rb +7 -7
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
  14. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  15. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  16. data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +44 -37
  17. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  19. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  20. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +156 -0
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  27. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +73 -0
  28. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
  29. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  30. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  31. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  32. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  33. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  34. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  35. data/lib/zakuro/calculation/monthly/month.rb +55 -16
  36. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  37. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  38. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  39. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  40. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  41. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +45 -29
  42. data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
  43. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  44. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  45. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  46. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  47. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  48. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  49. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  50. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  51. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  52. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  53. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  54. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  55. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  56. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  57. data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
  58. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  59. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  60. data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
  61. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  62. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
  63. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  64. data/lib/zakuro/calculation/summary/western/range.rb +127 -0
  65. data/lib/zakuro/calculation/summary/western/single.rb +115 -0
  66. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
  67. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
  68. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  69. data/lib/zakuro/calculation/type/optional.rb +46 -0
  70. data/lib/zakuro/condition.rb +143 -94
  71. data/lib/zakuro/context/context.rb +44 -0
  72. data/lib/zakuro/context/option.rb +119 -0
  73. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  74. data/lib/zakuro/era/japan/calendar.rb +35 -33
  75. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
  76. data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
  77. data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
  78. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
  79. data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
  80. data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
  81. data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
  82. data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
  83. data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
  84. data/lib/zakuro/era/japan/gengou.rb +28 -41
  85. data/lib/zakuro/era/japan/version.rb +18 -16
  86. data/lib/zakuro/era/western/calendar.rb +104 -88
  87. data/lib/zakuro/exception/case/pattern.rb +71 -0
  88. data/lib/zakuro/exception/case/preset.rb +51 -0
  89. data/lib/zakuro/exception/case/template.rb +48 -0
  90. data/lib/zakuro/exception/cause.rb +28 -0
  91. data/lib/zakuro/exception/exception.rb +39 -0
  92. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  93. data/lib/zakuro/gateway/locale/date.rb +127 -0
  94. data/lib/zakuro/gateway/locale/range.rb +67 -0
  95. data/lib/zakuro/gateway/range.rb +99 -0
  96. data/lib/zakuro/gateway/single.rb +81 -0
  97. data/lib/zakuro/merchant.rb +67 -33
  98. data/lib/zakuro/operation/month/parser.rb +252 -249
  99. data/lib/zakuro/operation/month/type.rb +44 -35
  100. data/lib/zakuro/operation/month/validator.rb +182 -178
  101. data/lib/zakuro/operation/operation.rb +38 -36
  102. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  103. data/lib/zakuro/output/logger.rb +17 -3
  104. data/lib/zakuro/output/response.rb +107 -141
  105. data/lib/zakuro/result/data/day.rb +43 -0
  106. data/lib/zakuro/result/data/gengou.rb +35 -0
  107. data/lib/zakuro/result/data/month.rb +63 -0
  108. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  109. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  110. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  111. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  112. data/lib/zakuro/result/data/single_day.rb +56 -0
  113. data/lib/zakuro/result/data/solar_term.rb +35 -0
  114. data/lib/zakuro/result/data/year.rb +45 -0
  115. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  116. data/lib/zakuro/result/operation/month/history.rb +54 -0
  117. data/lib/zakuro/result/operation/month.rb +31 -0
  118. data/lib/zakuro/result/operation.rb +22 -97
  119. data/lib/zakuro/result/result.rb +6 -4
  120. data/lib/zakuro/tools/stringifier.rb +67 -42
  121. data/lib/zakuro/tools/typeconv.rb +17 -15
  122. data/lib/zakuro/tools/typeof.rb +15 -13
  123. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  124. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  125. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  126. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  127. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  128. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  129. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  130. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  131. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  132. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  133. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  134. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  135. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  136. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  137. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  138. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  139. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  140. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  141. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  142. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  143. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  144. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  145. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  146. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  147. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  148. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  149. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  150. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  151. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  152. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  153. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  154. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  155. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  156. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  157. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  158. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  159. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  160. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  161. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  162. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  163. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  164. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  165. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  166. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  167. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  168. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  169. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  170. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  171. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  172. metadata +68 -16
  173. data/lib/zakuro/calculation/range/operated_range.rb +0 -193
  174. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
  175. data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
  176. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  177. data/lib/zakuro/calculation/summary/range.rb +0 -120
  178. data/lib/zakuro/calculation/summary/single.rb +0 -110
  179. data/lib/zakuro/result/data.rb +0 -187
  180. data/lib/zakuro/version/context.rb +0 -44
  181. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -7,231 +7,44 @@ require 'yaml'
7
7
 
8
8
  # :nodoc:
9
9
  module Zakuro
10
- #
11
- # Japan 和暦
12
- #
10
+ # :nodoc:
13
11
  module Japan
14
- #
15
- # Resource yaml解析結果
16
- #
17
- module Resource
12
+ # :nodoc:
13
+ module Gengou
18
14
  #
19
- # Validator yaml解析
15
+ # Resource yaml解析結果
20
16
  #
21
- module Validator
17
+ module Resource
22
18
  #
23
- # Set 元号セット情報の検証/展開
19
+ # Validator yaml解析
24
20
  #
25
- class Set
26
- # @return [String] 元号セットID
27
- attr_reader :id
28
- # @return [String] 元号セット名
29
- attr_reader :name
30
- # @return [Hash<String, String>] 終了年
31
- attr_reader :both_last_year
32
- # @return [Hash<String, String>] 終了日
33
- attr_reader :both_last_date
34
- # @return [Array<Hash<String, String>>] 元号情報
35
- attr_reader :list
36
-
37
- #
38
- # 初期化
39
- #
40
- # @param [Hash<String, Object>] hash 元号セット情報
41
- #
42
- def initialize(hash:)
43
- @id = hash['id']
44
- @name = hash['name']
45
- @both_last_year = hash['last_year']
46
- @both_last_date = hash['last_date']
47
- @list = hash['list']
48
- end
49
-
50
- #
51
- # 検証する
52
- #
53
- # @return [Array<String>] 不正メッセージ
54
- #
55
- def validate
56
- failed = []
57
- failed.push("invalid id. #{@id}") unless id?
58
-
59
- failed.push("invalid name. #{@name}") unless name?
60
-
61
- failed |= validate_both_last_year
62
-
63
- failed |= validate_both_last_date
64
-
65
- failed |= validate_list
66
- failed
67
- end
68
-
69
- #
70
- # IDを検証する
71
- #
72
- # @return [True] 正しい
73
- # @return [False] 正しくない
74
- #
75
- def id?
76
- return false unless @id
77
-
78
- @id.is_a?(Integer)
79
- end
80
-
81
- #
82
- # 元号セット名を検証する
83
- #
84
- # @return [True] 正しい
85
- # @return [False] 正しくない
86
- #
87
- def name?
88
- return false unless @name
89
-
90
- @name.is_a?(String)
91
- end
92
-
93
- #
94
- # 終了年を検証する
95
- #
96
- # @return [Array<String>] 不正メッセージ
97
- #
98
- def validate_both_last_year
99
- Both::Year.new(hash: @both_last_year).validate
100
- end
101
-
102
- #
103
- # 終了日を検証する
104
- #
105
- # @return [Array<String>] 不正メッセージ
106
- #
107
- def validate_both_last_date
108
- Both::Date.new(hash: @both_last_date).validate
109
- end
110
-
111
- #
112
- # 元号情報を検証する
113
- #
114
- # @return [True] 正しい
115
- # @return [False] 正しくない
116
- #
117
- def list?
118
- return false unless @list
119
-
120
- @list.is_a?(Array)
121
- end
122
-
123
- #
124
- # 元号情報を検証する
125
- #
126
- # @return [Array<String>] 不正メッセージ
127
- #
128
- def validate_list
129
- return ["invalid list. #{@list.class}"] unless list?
130
-
131
- failed = []
132
- list.each_with_index do |li, index|
133
- failed |= Gengou.new(hash: li, index: index).validate
134
- end
135
- failed
136
- end
137
- end
138
-
139
- #
140
- # Gengou 元号情報
141
- #
142
- class Gengou
143
- # @return [Integer] 要素位置
144
- attr_reader :index
145
- # @return [String] 元号名
146
- attr_reader :name
147
- # @return [Hash<String, String>] 開始年
148
- attr_reader :both_start_year
149
- # @return [Hash<String, String>] 開始日
150
- attr_reader :both_start_date
151
-
152
- #
153
- # 初期化
154
- #
155
- # @param [Hash<String, Strin>] hash 元号情報
156
- # @param [Integer] index (元号セット内での)元号の要素位置
157
- #
158
- def initialize(hash:, index:)
159
- @index = index
160
- @name = hash['name']
161
- @both_start_year = hash['start_year']
162
- @both_start_date = hash['start_date']
163
- end
164
-
165
- #
166
- # 検証する
167
- #
168
- # @return [Array<String>] 不正メッセージ
169
- #
170
- def validate
171
- prefix = "list[#{index}]. "
172
- failed = []
173
-
174
- failed.push(prefix + "invalid name. #{@name}") unless name?
175
-
176
- failed |= validate_both_start_year
177
-
178
- failed |= validate_both_start_date
179
-
180
- failed
181
- end
182
-
183
- #
184
- # 元号名を検証する
185
- #
186
- # @return [True] 正しい
187
- # @return [False] 正しくない
188
- #
189
- def name?
190
- return false unless @name
191
-
192
- @name.is_a?(String)
193
- end
194
-
195
- #
196
- # 開始年を検証する
197
- #
198
- # @return [Array<String>] 不正メッセージ
199
- #
200
- def validate_both_start_year
201
- Both::Year.new(hash: @both_start_year).validate
202
- end
203
-
204
- #
205
- # 開始日を検証する
206
- #
207
- # @return [Array<String>] 不正メッセージ
208
- #
209
- def validate_both_start_date
210
- Both::Date.new(hash: @both_start_date).validate
211
- end
212
- end
213
-
214
- #
215
- # 和暦/西暦
216
- #
217
- module Both
218
- #
219
- # Year 年
220
- #
221
- class Year
222
- # @return [String] 和暦元号年
223
- attr_reader :japan
224
- # @return [String] 西暦年
225
- attr_reader :western
21
+ module Validator
22
+ #
23
+ # Set 元号セット情報の検証/展開
24
+ #
25
+ class Set
26
+ # @return [String] 元号セットID
27
+ attr_reader :id
28
+ # @return [String] 元号セット名
29
+ attr_reader :name
30
+ # @return [Hash<String, String>] 終了年
31
+ attr_reader :both_last_year
32
+ # @return [Hash<String, String>] 終了日
33
+ attr_reader :both_last_date
34
+ # @return [Array<Hash<String, String>>] 元号情報
35
+ attr_reader :list
226
36
 
227
37
  #
228
38
  # 初期化
229
39
  #
230
- # @param [Hash<String, Strin>] hash 年情報
40
+ # @param [Hash<String, Object>] hash 元号セット情報
231
41
  #
232
42
  def initialize(hash:)
233
- @japan = hash['japan']
234
- @western = hash['western']
43
+ @id = hash['id']
44
+ @name = hash['name']
45
+ @both_last_year = hash['last_year']
46
+ @both_last_date = hash['last_date']
47
+ @list = hash['list']
235
48
  end
236
49
 
237
50
  #
@@ -241,56 +54,112 @@ module Zakuro
241
54
  #
242
55
  def validate
243
56
  failed = []
57
+ failed.push("invalid id. #{id}") unless id?
58
+
59
+ failed.push("invalid name. #{name}") unless name?
244
60
 
245
- failed.push("invalid japan year. #{@japan}") unless japan?
61
+ failed |= validate_both_last_year
246
62
 
247
- failed.push("invalid western year. #{@western}") unless western?
63
+ failed |= validate_both_last_date
248
64
 
65
+ failed |= validate_list
249
66
  failed
250
67
  end
251
68
 
252
69
  #
253
- # 和暦元号年を検証する
70
+ # IDを検証する
254
71
  #
255
72
  # @return [True] 正しい
256
73
  # @return [False] 正しくない
257
74
  #
258
- def japan?
259
- return false unless @japan
75
+ def id?
76
+ return false unless id
260
77
 
261
- @japan.is_a?(Integer)
78
+ id.is_a?(Integer)
262
79
  end
263
80
 
264
81
  #
265
- # 和暦元号年を検証する
82
+ # 元号セット名を検証する
266
83
  #
267
84
  # @return [True] 正しい
268
85
  # @return [False] 正しくない
269
86
  #
270
- def western?
271
- return false unless @western
87
+ def name?
88
+ return false unless @name
272
89
 
273
- @western.is_a?(Integer)
90
+ name.is_a?(String)
91
+ end
92
+
93
+ #
94
+ # 終了年を検証する
95
+ #
96
+ # @return [Array<String>] 不正メッセージ
97
+ #
98
+ def validate_both_last_year
99
+ Both::Year.new(hash: both_last_year).validate
100
+ end
101
+
102
+ #
103
+ # 終了日を検証する
104
+ #
105
+ # @return [Array<String>] 不正メッセージ
106
+ #
107
+ def validate_both_last_date
108
+ Both::Date.new(hash: both_last_date).validate
109
+ end
110
+
111
+ #
112
+ # 元号情報を検証する
113
+ #
114
+ # @return [True] 正しい
115
+ # @return [False] 正しくない
116
+ #
117
+ def list?
118
+ return false unless list
119
+
120
+ list.is_a?(Array)
121
+ end
122
+
123
+ #
124
+ # 元号情報を検証する
125
+ #
126
+ # @return [Array<String>] 不正メッセージ
127
+ #
128
+ def validate_list
129
+ return ["invalid list. #{list.class}"] unless list?
130
+
131
+ failed = []
132
+ list.each_with_index do |li, index|
133
+ failed |= Gengou.new(hash: li, index: index).validate
134
+ end
135
+ failed
274
136
  end
275
137
  end
276
138
 
277
139
  #
278
- # Date
140
+ # Gengou 元号情報
279
141
  #
280
- class Date
281
- # @return [String] 和暦日
282
- attr_reader :japan
283
- # @return [String] 西暦日
284
- attr_reader :western
142
+ class Gengou
143
+ # @return [Integer] 要素位置
144
+ attr_reader :index
145
+ # @return [String] 元号名
146
+ attr_reader :name
147
+ # @return [Hash<String, String>] 開始年
148
+ attr_reader :both_start_year
149
+ # @return [Hash<String, String>] 開始日
150
+ attr_reader :both_start_date
285
151
 
286
152
  #
287
153
  # 初期化
288
154
  #
289
- # @param [Hash<String, Strin>] hash 日情報
155
+ # @param [Hash<String, Strin>] hash 元号情報
156
+ # @param [Integer] index (元号セット内での)元号の要素位置
290
157
  #
291
- def initialize(hash:)
292
- @japan = hash['japan']
293
- @western = hash['western']
158
+ def initialize(hash:, index:)
159
+ @index = index
160
+ @name = hash['name']
161
+ @both_start_year = hash['start_year']
162
+ @both_start_date = hash['start_date']
294
163
  end
295
164
 
296
165
  #
@@ -299,46 +168,180 @@ module Zakuro
299
168
  # @return [Array<String>] 不正メッセージ
300
169
  #
301
170
  def validate
171
+ prefix = "list[#{index}]. "
302
172
  failed = []
303
173
 
304
- failed.push("invalid japan date. #{@japan}") unless japan?
174
+ failed.push(prefix + "invalid name. #{name}") unless name?
305
175
 
306
- failed.push("invalid western date. #{@western}") unless western?
176
+ failed |= validate_both_start_year
177
+
178
+ failed |= validate_both_start_date
307
179
 
308
180
  failed
309
181
  end
310
182
 
311
183
  #
312
- # 和暦日を検証する
184
+ # 元号名を検証する
313
185
  #
314
186
  # @return [True] 正しい
315
187
  # @return [False] 正しくない
316
188
  #
317
- def japan?
318
- Japan::Calendar.valid_date_string(text: @japan)
189
+ def name?
190
+ return false unless name
191
+
192
+ name.is_a?(String)
319
193
  end
320
194
 
321
195
  #
322
- # 西暦日を検証する
196
+ # 開始年を検証する
323
197
  #
324
- # @return [True] 正しい
325
- # @return [False] 正しくない
198
+ # @return [Array<String>] 不正メッセージ
326
199
  #
327
- def western?
328
- Western::Calendar.valid_date_string(str: @western)
200
+ def validate_both_start_year
201
+ Both::Year.new(hash: both_start_year).validate
202
+ end
203
+
204
+ #
205
+ # 開始日を検証する
206
+ #
207
+ # @return [Array<String>] 不正メッセージ
208
+ #
209
+ def validate_both_start_date
210
+ Both::Date.new(hash: both_start_date).validate
329
211
  end
330
212
  end
331
- end
332
213
 
333
- #
334
- # 検証する
335
- #
336
- # @param [Hash<String, Object>] yaml_hash yaml取得結果
337
- #
338
- # @return [Array<String>] 不正メッセージ
339
- #
340
- def self.run(yaml_hash:)
341
- Set.new(hash: yaml_hash).validate
214
+ #
215
+ # 和暦/西暦
216
+ #
217
+ module Both
218
+ #
219
+ # Year
220
+ #
221
+ class Year
222
+ # @return [String] 和暦元号年
223
+ attr_reader :japan
224
+ # @return [String] 西暦年
225
+ attr_reader :western
226
+
227
+ #
228
+ # 初期化
229
+ #
230
+ # @param [Hash<String, Strin>] hash 年情報
231
+ #
232
+ def initialize(hash:)
233
+ @japan = hash['japan']
234
+ @western = hash['western']
235
+ end
236
+
237
+ #
238
+ # 検証する
239
+ #
240
+ # @return [Array<String>] 不正メッセージ
241
+ #
242
+ def validate
243
+ failed = []
244
+
245
+ failed.push("invalid japan year. #{japan}") unless japan?
246
+
247
+ failed.push("invalid western year. #{western}") unless western?
248
+
249
+ failed
250
+ end
251
+
252
+ #
253
+ # 和暦元号年を検証する
254
+ #
255
+ # @return [True] 正しい
256
+ # @return [False] 正しくない
257
+ #
258
+ def japan?
259
+ return false unless @japan
260
+
261
+ japan.is_a?(Integer)
262
+ end
263
+
264
+ #
265
+ # 和暦元号年を検証する
266
+ #
267
+ # @return [True] 正しい
268
+ # @return [False] 正しくない
269
+ #
270
+ def western?
271
+ return false unless @western
272
+
273
+ western.is_a?(Integer)
274
+ end
275
+ end
276
+
277
+ #
278
+ # Date 日
279
+ #
280
+ class Date
281
+ # @return [String] 和暦日
282
+ attr_reader :japan
283
+ # @return [String] 西暦日
284
+ attr_reader :western
285
+
286
+ #
287
+ # 初期化
288
+ #
289
+ # @param [Hash<String, Strin>] hash 日情報
290
+ #
291
+ def initialize(hash:)
292
+ @japan = hash['japan']
293
+ @western = hash['western']
294
+ end
295
+
296
+ #
297
+ # 検証する
298
+ #
299
+ # @return [Array<String>] 不正メッセージ
300
+ #
301
+ def validate
302
+ failed = []
303
+
304
+ failed.push("invalid japan date. #{japan}") unless japan?
305
+
306
+ failed.push("invalid western date. #{western}") unless western?
307
+
308
+ failed
309
+ end
310
+
311
+ #
312
+ # 和暦日を検証する
313
+ #
314
+ # @return [True] 正しい
315
+ # @return [False] 正しくない
316
+ #
317
+ def japan?
318
+ Japan::Calendar.valid_date_string(text: japan)
319
+ end
320
+
321
+ #
322
+ # 西暦日を検証する
323
+ #
324
+ # @return [True] 正しい
325
+ # @return [False] 正しくない
326
+ #
327
+ def western?
328
+ Western::Calendar.valid_date_string(text: western)
329
+ end
330
+ end
331
+ end
332
+
333
+ class << self
334
+ #
335
+ # 検証する
336
+ #
337
+ # @param [Hash<String, Object>] yaml_hash yaml取得結果
338
+ #
339
+ # @return [Array<String>] 不正メッセージ
340
+ #
341
+ def run(yaml_hash:)
342
+ Set.new(hash: yaml_hash).validate
343
+ end
344
+ end
342
345
  end
343
346
  end
344
347
  end
@@ -4,29 +4,30 @@ require_relative './resource/parser'
4
4
 
5
5
  # :nodoc:
6
6
  module Zakuro
7
- #
8
- # Japan 和暦
9
- #
7
+ # :nodoc:
10
8
  module Japan
11
- #
12
- # Resource yaml解析結果
13
- #
14
- module Resource
15
- # @return [Array<Set>] 元号セット情報リスト
16
- LIST = [
17
- Parser.run(filepath: File.expand_path(
18
- './resource/yaml/set-001-until-south.yaml',
19
- __dir__
20
- )),
21
- Parser.run(filepath: File.expand_path(
22
- './resource/yaml/set-002-from-north.yaml',
23
- __dir__
24
- )),
25
- Parser.run(filepath: File.expand_path(
26
- './resource/yaml/set-003-modern.yaml',
27
- __dir__
28
- ))
29
- ].freeze
9
+ # :nodoc:
10
+ module Gengou
11
+ #
12
+ # Resource yaml解析結果
13
+ #
14
+ module Resource
15
+ # @return [Array<Set>] 元号セット情報リスト
16
+ LIST = [
17
+ Parser.run(filepath: File.expand_path(
18
+ './resource/yaml/set-001-until-south.yaml',
19
+ __dir__
20
+ )),
21
+ Parser.run(filepath: File.expand_path(
22
+ './resource/yaml/set-002-from-north.yaml',
23
+ __dir__
24
+ )),
25
+ Parser.run(filepath: File.expand_path(
26
+ './resource/yaml/set-003-modern.yaml',
27
+ __dir__
28
+ ))
29
+ ].freeze
30
+ end
30
31
  end
31
32
  end
32
33
  end