zakuro 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -1
  3. data/VERSION +1 -0
  4. data/doc/gengou.md +22 -22
  5. data/doc/operation/csv/month.csv +468 -202
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  8. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  9. data/lib/zakuro/calculation/base/operated_year.rb +104 -0
  10. data/lib/zakuro/calculation/base/year.rb +28 -13
  11. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +29 -29
  12. data/lib/zakuro/calculation/gengou/internal/counter.rb +129 -0
  13. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +183 -0
  14. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +382 -0
  15. data/lib/zakuro/calculation/gengou/internal/reserve.rb +42 -0
  16. data/lib/zakuro/calculation/gengou/scroll.rb +262 -0
  17. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  18. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  19. data/lib/zakuro/calculation/monthly/operated_month.rb +49 -5
  20. data/lib/zakuro/calculation/range/full_range.rb +65 -103
  21. data/lib/zakuro/calculation/range/operated_range.rb +73 -23
  22. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  23. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  24. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  25. data/lib/zakuro/calculation/specifier/single_day.rb +13 -35
  26. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +9 -7
  27. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +19 -0
  28. data/lib/zakuro/calculation/summary/single.rb +5 -2
  29. data/lib/zakuro/calculation/version/internal/crawler.rb +51 -0
  30. data/lib/zakuro/calculation/version/internal/range.rb +39 -0
  31. data/lib/zakuro/calculation/version/version.rb +24 -0
  32. data/lib/zakuro/era/japan/calendar.rb +133 -0
  33. data/lib/zakuro/era/japan/gengou/parser.rb +95 -25
  34. data/lib/zakuro/era/japan/gengou/type.rb +148 -41
  35. data/lib/zakuro/era/japan/gengou/validator.rb +157 -52
  36. data/lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml +1870 -0
  37. data/lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml +810 -0
  38. data/lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml +50 -0
  39. data/lib/zakuro/era/japan/gengou.rb +5 -5
  40. data/lib/zakuro/era/japan/version.rb +151 -0
  41. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  42. data/lib/zakuro/merchant.rb +12 -3
  43. data/lib/zakuro/operation/month/parser.rb +1 -1
  44. data/lib/zakuro/operation/month/type.rb +59 -1
  45. data/lib/zakuro/operation/month/validator.rb +1 -1
  46. data/lib/zakuro/operation/yaml/month.yaml +8512 -0
  47. data/lib/zakuro/output/response.rb +5 -5
  48. data/lib/zakuro/tools/typeconv.rb +38 -0
  49. data/lib/zakuro/tools/typeof.rb +4 -1
  50. data/lib/zakuro/version/context.rb +25 -4
  51. data/lib/zakuro/version/daien/const/number.rb +55 -0
  52. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  53. data/lib/zakuro/version/daien/cycle/remainder.rb +85 -0
  54. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  55. data/lib/zakuro/version/daien/daien.rb +11 -0
  56. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  57. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  58. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  59. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  60. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  61. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  62. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  63. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  64. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  65. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  66. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  67. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  68. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  69. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  70. data/lib/zakuro/version/genka/const/number.rb +43 -0
  71. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  72. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  73. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  74. data/lib/zakuro/version/genka/genka.rb +1 -9
  75. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  76. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  77. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  78. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  79. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  80. data/lib/zakuro/version/gihou/const/remainder.rb +0 -2
  81. data/lib/zakuro/version/gihou/cycle/remainder.rb +27 -6
  82. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  83. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +1 -1
  84. data/lib/zakuro/version/gihou/stella/lunar/location.rb +2 -8
  85. data/lib/zakuro/version/gihou/stella/lunar/value.rb +3 -2
  86. data/lib/zakuro/version/gihou/stella/solar/average.rb +3 -3
  87. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  88. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  89. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  90. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  91. data/lib/zakuro/version/senmyou/const/remainder.rb +0 -2
  92. data/lib/zakuro/version/senmyou/cycle/remainder.rb +27 -6
  93. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
  94. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  95. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +2 -8
  96. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +3 -2
  97. data/lib/zakuro/version/senmyou/stella/solar/average.rb +3 -3
  98. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  99. data/lib/zakuro/version/version_class_resolver.rb +8 -0
  100. data/zakuro.gemspec +1 -3
  101. metadata +50 -14
  102. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  103. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  104. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  105. data/lib/zakuro/era/japan/reki.rb +0 -91
  106. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  107. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  108. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  109. data/lib/zakuro/version/abstract_version.rb +0 -29
  110. data/lib/zakuro/version/taien/taien.rb +0 -19
  111. data/lib/zakuro/version.rb +0 -7
  112. data/lib/zakuro/version_factory.rb +0 -59
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../western'
3
+ require_relative '../../japan/calendar'
4
+ require_relative '../../western/calendar'
4
5
  require_relative './type'
5
6
  require 'yaml'
6
7
 
@@ -14,8 +15,6 @@ module Zakuro
14
15
  # Validator yaml解析
15
16
  #
16
17
  module Validator
17
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
18
-
19
18
  #
20
19
  # Set 元号セット情報の検証/展開
21
20
  #
@@ -24,8 +23,10 @@ module Zakuro
24
23
  attr_reader :id
25
24
  # @return [String] 元号セット名
26
25
  attr_reader :name
27
- # @return [String] 終了日
28
- attr_reader :end_date
26
+ # @return [Hash<String, String>] 終了年
27
+ attr_reader :both_end_year
28
+ # @return [Hash<String, String>] 終了日
29
+ attr_reader :both_end_date
29
30
  # @return [Array<Hash<String, String>>] 元号情報
30
31
  attr_reader :list
31
32
 
@@ -37,12 +38,11 @@ module Zakuro
37
38
  def initialize(hash:)
38
39
  @id = hash['id']
39
40
  @name = hash['name']
40
- @end_date = hash['end_date']
41
+ @both_end_year = hash['end_year']
42
+ @both_end_date = hash['end_date']
41
43
  @list = hash['list']
42
44
  end
43
45
 
44
- # :reek:TooManyStatements { max_statements: 6 }
45
-
46
46
  #
47
47
  # 検証する
48
48
  #
@@ -50,11 +50,13 @@ module Zakuro
50
50
  #
51
51
  def validate
52
52
  failed = []
53
- failed.push("invalid id. #{id}") unless id?
53
+ failed.push("invalid id. #{@id}") unless id?
54
54
 
55
- failed.push("invalid name. #{name}") unless name?
55
+ failed.push("invalid name. #{@name}") unless name?
56
56
 
57
- failed.push("invalid end_date. #{end_date}") unless western_date?
57
+ failed |= validate_both_end_year
58
+
59
+ failed |= validate_both_end_date
58
60
 
59
61
  failed |= validate_list
60
62
  failed
@@ -85,13 +87,21 @@ module Zakuro
85
87
  end
86
88
 
87
89
  #
88
- # 日付文字列を検証する
90
+ # 終了年を検証する
89
91
  #
90
- # @return [True] 正しい
91
- # @return [False] 正しくない
92
+ # @return [Array<String>] 不正メッセージ
93
+ #
94
+ def validate_both_end_year
95
+ Both::Year.new(hash: @both_end_year).validate
96
+ end
97
+
92
98
  #
93
- def western_date?
94
- Western::Calendar.valid_date_string(str: @end_date)
99
+ # 終了日を検証する
100
+ #
101
+ # @return [Array<String>] 不正メッセージ
102
+ #
103
+ def validate_both_end_date
104
+ Both::Date.new(hash: @both_end_date).validate
95
105
  end
96
106
 
97
107
  #
@@ -109,8 +119,7 @@ module Zakuro
109
119
  #
110
120
  # 元号情報を検証する
111
121
  #
112
- # @return [True] 正しい
113
- # @return [False] 正しくない
122
+ # @return [Array<String>] 不正メッセージ
114
123
  #
115
124
  def validate_list
116
125
  return ["invalid list. #{@list.class}"] unless list?
@@ -123,8 +132,6 @@ module Zakuro
123
132
  end
124
133
  end
125
134
 
126
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
127
-
128
135
  #
129
136
  # Gengou 元号情報
130
137
  #
@@ -133,12 +140,10 @@ module Zakuro
133
140
  attr_reader :index
134
141
  # @return [String] 元号名
135
142
  attr_reader :name
136
- # @return [String] 開始日
137
- attr_reader :start_date
138
- # @return [String] 元旦
139
- attr_reader :new_year_date
140
- # @return [String] 開始年
141
- attr_reader :start_year
143
+ # @return [Hash<String, String>] 開始年
144
+ attr_reader :both_start_year
145
+ # @return [Hash<String, String>] 開始日
146
+ attr_reader :both_start_date
142
147
 
143
148
  #
144
149
  # 初期化
@@ -149,13 +154,10 @@ module Zakuro
149
154
  def initialize(hash:, index:)
150
155
  @index = index
151
156
  @name = hash['name']
152
- @start_date = hash['start_date']
153
- @new_year_date = hash['new_year_date']
154
- @start_year = hash['start_year']
157
+ @both_start_year = hash['start_year']
158
+ @both_start_date = hash['start_date']
155
159
  end
156
160
 
157
- # :reek:TooManyStatements { max_statements: 7 }
158
-
159
161
  #
160
162
  # 検証する
161
163
  #
@@ -167,11 +169,9 @@ module Zakuro
167
169
 
168
170
  failed.push(prefix + "invalid name. #{@name}") unless name?
169
171
 
170
- failed.push(prefix + "invalid start_date. #{@start_date}") unless start_date?
171
-
172
- failed.push(prefix + "invalid start_year. #{@start_year}") unless year?
172
+ failed |= validate_both_start_year
173
173
 
174
- failed.push(prefix + "invalid new_year_date. #{@new_year_date}") unless new_year_date?
174
+ failed |= validate_both_start_date
175
175
 
176
176
  failed
177
177
  end
@@ -189,35 +189,140 @@ module Zakuro
189
189
  end
190
190
 
191
191
  #
192
- # 開始日文字列を検証する
192
+ # 開始年を検証する
193
193
  #
194
- # @return [True] 正しい
195
- # @return [False] 正しくない
194
+ # @return [Array<String>] 不正メッセージ
196
195
  #
197
- def start_date?
198
- Western::Calendar.valid_date_string(str: @start_date)
196
+ def validate_both_start_year
197
+ Both::Year.new(hash: @both_start_year).validate
199
198
  end
200
199
 
201
200
  #
202
- # 元旦文字列を検証する
201
+ # 開始日を検証する
203
202
  #
204
- # @return [True] 正しい
205
- # @return [False] 正しくない
203
+ # @return [Array<String>] 不正メッセージ
206
204
  #
207
- def new_year_date?
208
- Western::Calendar.valid_date_string(str: @new_year_date)
205
+ def validate_both_start_date
206
+ Both::Date.new(hash: @both_start_date).validate
207
+ end
208
+ end
209
+
210
+ #
211
+ # 和暦/西暦
212
+ #
213
+ module Both
214
+ #
215
+ # Year 年
216
+ #
217
+ class Year
218
+ # @return [String] 和暦元号年
219
+ attr_reader :japan
220
+ # @return [String] 西暦年
221
+ attr_reader :western
222
+
223
+ #
224
+ # 初期化
225
+ #
226
+ # @param [Hash<String, Strin>] hash 年情報
227
+ #
228
+ def initialize(hash:)
229
+ @japan = hash['japan']
230
+ @western = hash['western']
231
+ end
232
+
233
+ #
234
+ # 検証する
235
+ #
236
+ # @return [Array<String>] 不正メッセージ
237
+ #
238
+ def validate
239
+ failed = []
240
+
241
+ failed.push("invalid japan year. #{@japan}") unless japan?
242
+
243
+ failed.push("invalid western year. #{@western}") unless western?
244
+
245
+ failed
246
+ end
247
+
248
+ #
249
+ # 和暦元号年を検証する
250
+ #
251
+ # @return [True] 正しい
252
+ # @return [False] 正しくない
253
+ #
254
+ def japan?
255
+ return false unless @japan
256
+
257
+ @japan.is_a?(Integer)
258
+ end
259
+
260
+ #
261
+ # 和暦元号年を検証する
262
+ #
263
+ # @return [True] 正しい
264
+ # @return [False] 正しくない
265
+ #
266
+ def western?
267
+ return false unless @western
268
+
269
+ @western.is_a?(Integer)
270
+ end
209
271
  end
210
272
 
211
273
  #
212
- # 元号年を検証する
213
- #
214
- # @return [True] 正しい
215
- # @return [False] 正しくない
274
+ # Date 日
216
275
  #
217
- def year?
218
- return true unless @start_year
276
+ class Date
277
+ # @return [String] 和暦日
278
+ attr_reader :japan
279
+ # @return [String] 西暦日
280
+ attr_reader :western
281
+
282
+ #
283
+ # 初期化
284
+ #
285
+ # @param [Hash<String, Strin>] hash 日情報
286
+ #
287
+ def initialize(hash:)
288
+ @japan = hash['japan']
289
+ @western = hash['western']
290
+ end
291
+
292
+ #
293
+ # 検証する
294
+ #
295
+ # @return [Array<String>] 不正メッセージ
296
+ #
297
+ def validate
298
+ failed = []
299
+
300
+ failed.push("invalid japan date. #{@japan}") unless japan?
219
301
 
220
- @start_year.is_a?(Integer)
302
+ failed.push("invalid western date. #{@western}") unless western?
303
+
304
+ failed
305
+ end
306
+
307
+ #
308
+ # 和暦日を検証する
309
+ #
310
+ # @return [True] 正しい
311
+ # @return [False] 正しくない
312
+ #
313
+ def japan?
314
+ Japan::Calendar.valid_date_string(text: @japan)
315
+ end
316
+
317
+ #
318
+ # 西暦日を検証する
319
+ #
320
+ # @return [True] 正しい
321
+ # @return [False] 正しくない
322
+ #
323
+ def western?
324
+ Western::Calendar.valid_date_string(str: @western)
325
+ end
221
326
  end
222
327
  end
223
328