zakuro 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,8 @@ module Zakuro
15
15
  #
16
16
  INVALID_DAY_VALUE = -30
17
17
 
18
+ # :reek:TooManyInstanceVariables { max_instance_variables: 6 }
19
+
18
20
  #
19
21
  # MonthHistory 変更履歴
20
22
  #
@@ -32,6 +34,9 @@ module Zakuro
32
34
  # @return [Diffs] 総差分
33
35
  attr_reader :diffs
34
36
 
37
+ # rubocop:disable Metrics/ParameterLists
38
+ # :reek:LongParameterList { max_params: 6 }
39
+
35
40
  #
36
41
  # 初期化
37
42
  #
@@ -51,6 +56,7 @@ module Zakuro
51
56
  @annotations = annotations
52
57
  @diffs = diffs
53
58
  end
59
+ # rubocop:enable Metrics/ParameterLists
54
60
 
55
61
  #
56
62
  # 無効か
@@ -20,50 +20,118 @@ module Zakuro
20
20
  EMPTY_STRING = '-'
21
21
  BOOLEANS = %w[true false].freeze
22
22
 
23
- # :reek:NilCheck
24
-
23
+ #
24
+ # 有効文字列か
25
+ #
26
+ # @param [String] str 対象文字列
27
+ #
28
+ # @return [True] 有効
29
+ # @return [False] 無効
30
+ #
25
31
  def self.string?(str: '')
26
- !str.nil? && !str.empty? && str.is_a?(String)
27
- end
32
+ return false if str == ''
28
33
 
29
- # :reek:NilCheck
34
+ return false unless str
30
35
 
31
- def self.empiable_string?(str: '')
32
- !str.nil? && str.is_a?(String)
36
+ str.is_a?(String)
33
37
  end
34
38
 
35
- # :reek:NilCheck
39
+ #
40
+ # 有効文字列(空文字許容)か
41
+ #
42
+ # @param [String] str 対象文字列
43
+ #
44
+ # @return [True] 有効
45
+ # @return [False] 無効
46
+ #
47
+ def self.empiable_string?(str: '')
48
+ return false unless str
36
49
 
50
+ str.is_a?(String)
51
+ end
52
+
53
+ #
54
+ # 正数か
55
+ #
56
+ # @param [String] str 対象文字列
57
+ #
58
+ # @return [True] 正数
59
+ # @return [False] 負数
60
+ #
37
61
  def self.positive?(str: '')
38
62
  return true if str == EMPTY_STRING
39
63
 
40
- !str.nil? && !str.empty? && /^[0-9]+$/.match?(str)
41
- end
64
+ return false unless str
42
65
 
43
- # :reek:NilCheck
66
+ /^[0-9]+$/.match?(str)
67
+ end
44
68
 
69
+ #
70
+ # 数値か
71
+ #
72
+ # @param [String] str 対象文字列
73
+ #
74
+ # @return [True] 数値
75
+ # @return [False] 非数値
76
+ #
45
77
  def self.num?(str: '')
46
78
  return true if str == EMPTY_STRING
47
79
 
48
- !str.nil? && !str.empty? && /^[-0-9]+$/.match?(str)
80
+ return false unless str
81
+
82
+ /^[-0-9]+$/.match?(str)
49
83
  end
50
84
 
85
+ #
86
+ # booleanか
87
+ #
88
+ # @param [String] str 対象文字列
89
+ #
90
+ # @return [True] boolean
91
+ # @return [False] 非boolean
92
+ #
51
93
  def self.bool?(str: '')
52
94
  BOOLEANS.include?(str)
53
95
  end
54
96
 
97
+ #
98
+ # boolean(空許容)か
99
+ #
100
+ # @param [String] str 対象文字列
101
+ #
102
+ # @return [True] boolean
103
+ # @return [False] 非boolean
104
+ #
55
105
  def self.empiable_bool?(str: '')
56
106
  return true if str == EMPTY_STRING
57
107
 
58
108
  bool?(str: str)
59
109
  end
60
110
 
111
+ #
112
+ # 月差分か
113
+ #
114
+ # @param [String] str 対象文字列
115
+ #
116
+ # @return [True] 有効
117
+ # @return [False] 無効
118
+ #
61
119
  def self.month_days?(str: '')
62
120
  return true if str == EMPTY_STRING
63
121
 
64
- !str.nil? && !str.empty? && /^[大小]$/.match?(str)
122
+ return false unless str
123
+
124
+ /^[大小]$/.match?(str)
65
125
  end
66
126
 
127
+ #
128
+ # 西暦日か
129
+ #
130
+ # @param [String] str 対象文字列
131
+ #
132
+ # @return [True] 有効
133
+ # @return [False] 無効
134
+ #
67
135
  def self.western_date?(str: '')
68
136
  return Western::Calendar.new if str == EMPTY_STRING
69
137
 
@@ -71,12 +139,33 @@ module Zakuro
71
139
  end
72
140
  end
73
141
 
142
+ # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
143
+
74
144
  #
75
145
  # MonthHistory 変更履歴
76
146
  #
77
147
  class MonthHistory
78
- attr_reader :index, :id, :parend_id, :western_date, :modified
148
+ # @return [Integer] 連番
149
+ attr_reader :index
150
+ # @return [String] ID
151
+ attr_reader :id
152
+ # @return [String] 親ID
153
+ attr_reader :parend_id
154
+ # @return [String] 西暦日
155
+ attr_reader :western_date
156
+ # @return [String] 有効行
157
+ attr_reader :modified
79
158
 
159
+ #
160
+ # 初期化
161
+ #
162
+ # @param [Integer] index 連番
163
+ # @param [Hash<String, String>] yaml_hash yaml
164
+ # @option yaml_hash [String] :id ID
165
+ # @option yaml_hash [String] :parent_id 親ID
166
+ # @option yaml_hash [String] :western_date 西暦日
167
+ # @option yaml_hash [String] :modified 有効行
168
+ #
80
169
  def initialize(index:, yaml_hash: {})
81
170
  @index = index
82
171
  @id = yaml_hash['id']
@@ -85,6 +174,13 @@ module Zakuro
85
174
  @modified = yaml_hash['modified']
86
175
  end
87
176
 
177
+ # :reek:TooManyStatements { max_statements: 7 }
178
+
179
+ #
180
+ # 検証する
181
+ #
182
+ # @return [Array<String>] エラーメッセージ
183
+ #
88
184
  def validate
89
185
  failed = []
90
186
 
@@ -122,8 +218,24 @@ module Zakuro
122
218
  # Annotation 注釈
123
219
  #
124
220
  class Annotation
125
- attr_reader :index, :id, :description, :note
221
+ # @return [Integer] 連番
222
+ attr_reader :index
223
+ # @return [String] ID
224
+ attr_reader :id
225
+ # @return [String] 注釈内容
226
+ attr_reader :description
227
+ # @return [String] 補足
228
+ attr_reader :note
126
229
 
230
+ #
231
+ # 初期化
232
+ #
233
+ # @param [Integer] index 連番
234
+ # @param [Hash<String, String>] yaml_hash yaml
235
+ # @option yaml_hash [String] :id ID
236
+ # @option yaml_hash [String] :description 注釈内容
237
+ # @option yaml_hash [String] :note 補足
238
+ #
127
239
  def initialize(index:, yaml_hash: {})
128
240
  @index = index
129
241
  @id = yaml_hash['id']
@@ -131,6 +243,13 @@ module Zakuro
131
243
  @note = yaml_hash['note']
132
244
  end
133
245
 
246
+ # :reek:TooManyStatements { max_statements: 6 }
247
+
248
+ #
249
+ # 検証する
250
+ #
251
+ # @return [Array<String>] エラーメッセージ
252
+ #
134
253
  def validate
135
254
  failed = []
136
255
 
@@ -162,8 +281,24 @@ module Zakuro
162
281
  # Reference 参照
163
282
  #
164
283
  class Reference
165
- attr_reader :index, :page, :number, :japan_date
284
+ # @return [Integer] 連番
285
+ attr_reader :index
286
+ # @return [String] 原文頁数
287
+ attr_reader :page
288
+ # @return [String] 原文注釈番号
289
+ attr_reader :number
290
+ # @return [String] 和暦日
291
+ attr_reader :japan_date
166
292
 
293
+ #
294
+ # 初期化
295
+ #
296
+ # @param [Integer] index 連番
297
+ # @param [Hash<String, String>] yaml_hash yaml
298
+ # @option yaml_hash [String] :page 原文頁数
299
+ # @option yaml_hash [String] :number 原文注釈番号
300
+ # @option yaml_hash [String] :japan_date 和暦日
301
+ #
167
302
  def initialize(index:, yaml_hash: {})
168
303
  @index = index
169
304
  @page = yaml_hash['page']
@@ -171,6 +306,13 @@ module Zakuro
171
306
  @japan_date = yaml_hash['japan_date']
172
307
  end
173
308
 
309
+ # :reek:TooManyStatements { max_statements: 6 }
310
+
311
+ #
312
+ # 検証する
313
+ #
314
+ # @return [Array<String>] エラーメッセージ
315
+ #
174
316
  def validate
175
317
  failed = []
176
318
 
@@ -202,8 +344,24 @@ module Zakuro
202
344
  # Diffs 総差分
203
345
  #
204
346
  class Diffs
205
- attr_reader :index, :month, :solar_term, :days
347
+ # @return [Integer] 連番
348
+ attr_reader :index
349
+ # @return [Hash] 月差分
350
+ attr_reader :month
351
+ # @return [Hash] 二十四節気差分
352
+ attr_reader :solar_term
353
+ # @return [String] 日差分
354
+ attr_reader :days
206
355
 
356
+ #
357
+ # 初期化
358
+ #
359
+ # @param [Integer] index 連番
360
+ # @param [Hash] yaml_hash yaml
361
+ # @option yaml_hash [Hash] :month 月差分
362
+ # @option yaml_hash [Hash] :solar_term 二十四節気差分
363
+ # @option yaml_hash [String] :days 日差分
364
+ #
207
365
  def initialize(index:, yaml_hash: {})
208
366
  @index = index
209
367
  @month = Month.new(index: index, yaml_hash: yaml_hash['month'])
@@ -211,6 +369,13 @@ module Zakuro
211
369
  @days = yaml_hash['days']
212
370
  end
213
371
 
372
+ # :reek:TooManyStatements { max_statements: 6 }
373
+
374
+ #
375
+ # 検証する
376
+ #
377
+ # @return [Array<String>] エラーメッセージ
378
+ #
214
379
  def validate
215
380
  failed = []
216
381
 
@@ -234,8 +399,24 @@ module Zakuro
234
399
  # Month 月
235
400
  #
236
401
  class Month
237
- attr_reader :index, :number, :leaped, :days
402
+ # @return [Integer] 連番
403
+ attr_reader :index
404
+ # @return [Hash] 月差分
405
+ attr_reader :number
406
+ # @return [Hash] 閏有無差分
407
+ attr_reader :leaped
408
+ # @return [String] 中気差分
409
+ attr_reader :days
238
410
 
411
+ #
412
+ # 初期化
413
+ #
414
+ # @param [Integer] index 連番
415
+ # @param [Hash<String, Object>] yaml_hash yaml
416
+ # @option yaml_hash [Hash] :number 月差分
417
+ # @option yaml_hash [Hash] :leaped 閏有無差分
418
+ # @option yaml_hash [String] :days 中気差分
419
+ #
239
420
  def initialize(index:, yaml_hash: {})
240
421
  @index = index
241
422
  @number = Number.new(index: index, yaml_hash: yaml_hash['number'])
@@ -243,6 +424,11 @@ module Zakuro
243
424
  @days = Days.new(index: index, yaml_hash: yaml_hash['days'])
244
425
  end
245
426
 
427
+ #
428
+ # 検証する
429
+ #
430
+ # @return [Array<String>] エラーメッセージ
431
+ #
246
432
  def validate
247
433
  failed = []
248
434
 
@@ -261,14 +447,23 @@ module Zakuro
261
447
  # Direction 二十四節気(移動)
262
448
  #
263
449
  class Direction
264
- attr_reader :index, :source, :destination, :days
450
+ # @return [Integer] 連番
451
+ attr_reader :index
452
+ # @return [Source] 移動元
453
+ attr_reader :source
454
+ # @return [Destination] 移動先
455
+ attr_reader :destination
456
+ # @return [String] 中気差分
457
+ attr_reader :days
265
458
 
266
459
  #
267
460
  # 初期化
268
461
  #
269
- # @param [Source] source 二十四節気(移動元)
270
- # @param [Destination] destination 二十四節気(移動先)
271
- # @param [Integer] day 大余差分
462
+ # @param [Integer] index 連番
463
+ # @param [Hash<String, Object>] yaml_hash yaml
464
+ # @option yaml_hash [Hash] :calc 移動元
465
+ # @option yaml_hash [Hash] :actual 移動先
466
+ # @option yaml_hash [String] :days 中気差分
272
467
  #
273
468
  def initialize(index:, yaml_hash: {})
274
469
  @index = index
@@ -281,6 +476,13 @@ module Zakuro
281
476
  Types.positive?(str: @days)
282
477
  end
283
478
 
479
+ # :reek:TooManyStatements { max_statements: 6 }
480
+
481
+ #
482
+ # 検証する
483
+ #
484
+ # @return [Array<String>] エラーメッセージ
485
+ #
284
486
  def validate
285
487
  failed = []
286
488
 
@@ -300,8 +502,24 @@ module Zakuro
300
502
  # Source 二十四節気(移動元)
301
503
  #
302
504
  class Source
303
- attr_reader :diff_index, :index, :to, :zodiac_name
505
+ # @return [Integer] 連番
506
+ attr_reader :diff_index
507
+ # @return [String] 移動対象の二十四節気番号
508
+ attr_reader :index
509
+ # @return [String] 移動先の月初日
510
+ attr_reader :to
511
+ # @return [String] 十干十二支
512
+ attr_reader :zodiac_name
304
513
 
514
+ #
515
+ # 初期化
516
+ #
517
+ # @param [Integer] diff_index 連番
518
+ # @param [Hash<String, String>] yaml_hash yaml
519
+ # @option yaml_hash [String] :index 移動対象の二十四節気番号
520
+ # @option yaml_hash [String] :to 移動先の月初日
521
+ # @option yaml_hash [String] :zodiac_name 十干十二支
522
+ #
305
523
  def initialize(diff_index:, yaml_hash: {})
306
524
  @diff_index = diff_index
307
525
  @index = yaml_hash['index']
@@ -309,6 +527,13 @@ module Zakuro
309
527
  @zodiac_name = yaml_hash['zodiac_name']
310
528
  end
311
529
 
530
+ # :reek:TooManyStatements { max_statements: 6 }
531
+
532
+ #
533
+ # 検証する
534
+ #
535
+ # @return [Array<String>] エラーメッセージ
536
+ #
312
537
  def validate
313
538
  failed = []
314
539
 
@@ -340,8 +565,24 @@ module Zakuro
340
565
  # Destination 二十四節気(移動先)
341
566
  #
342
567
  class Destination
343
- attr_reader :diff_index, :index, :from, :zodiac_name
568
+ # @return [Integer] 連番
569
+ attr_reader :diff_index
570
+ # @return [String] 移動対象の二十四節気番号
571
+ attr_reader :index
572
+ # @return [String] 移動元の月初日
573
+ attr_reader :from
574
+ # @return [String] 十干十二支
575
+ attr_reader :zodiac_name
344
576
 
577
+ #
578
+ # 初期化
579
+ #
580
+ # @param [Integer] diff_index 連番
581
+ # @param [Hash<String, String>] yaml_hash yaml
582
+ # @option yaml_hash [String] :index 移動対象の二十四節気番号
583
+ # @option yaml_hash [String] :from 移動元の月初日
584
+ # @option yaml_hash [String] :zodiac_name 十干十二支
585
+ #
345
586
  def initialize(diff_index:, yaml_hash: {})
346
587
  @diff_index = diff_index
347
588
  @index = yaml_hash['index']
@@ -349,6 +590,13 @@ module Zakuro
349
590
  @zodiac_name = yaml_hash['zodiac_name']
350
591
  end
351
592
 
593
+ # :reek:TooManyStatements { max_statements: 6 }
594
+
595
+ #
596
+ # 検証する
597
+ #
598
+ # @return [Array<String>] エラーメッセージ
599
+ #
352
600
  def validate
353
601
  failed = []
354
602
 
@@ -383,14 +631,32 @@ module Zakuro
383
631
  class Number
384
632
  NAME = 'number'
385
633
 
386
- attr_reader :index, :calc, :actual
634
+ # @return [Integer] 連番
635
+ attr_reader :index
636
+ # @return [String] 計算
637
+ attr_reader :calc
638
+ # @return [String] 運用
639
+ attr_reader :actual
387
640
 
641
+ #
642
+ # 初期化
643
+ #
644
+ # @param [Integer] index 連番
645
+ # @param [Hash<String, String>] yaml_hash yaml
646
+ # @option yaml_hash [String] :calc 計算
647
+ # @option yaml_hash [String] :actual 運用
648
+ #
388
649
  def initialize(index:, yaml_hash: {})
389
650
  @index = index
390
651
  @calc = yaml_hash['calc']
391
652
  @actual = yaml_hash['actual']
392
653
  end
393
654
 
655
+ #
656
+ # 検証する
657
+ #
658
+ # @return [Array<String>] エラーメッセージ
659
+ #
394
660
  def validate
395
661
  failed = []
396
662
 
@@ -418,14 +684,32 @@ module Zakuro
418
684
  class Leaped
419
685
  NAME = 'leaped'
420
686
 
421
- attr_reader :index, :calc, :actual
687
+ # @return [Integer] 連番
688
+ attr_reader :index
689
+ # @return [String] 計算
690
+ attr_reader :calc
691
+ # @return [String] 運用
692
+ attr_reader :actual
422
693
 
694
+ #
695
+ # 初期化
696
+ #
697
+ # @param [Integer] index 連番
698
+ # @param [Hash<String, String>] yaml_hash yaml
699
+ # @option yaml_hash [String] :calc 計算
700
+ # @option yaml_hash [String] :actual 運用
701
+ #
423
702
  def initialize(index:, yaml_hash: {})
424
703
  @index = index
425
704
  @calc = yaml_hash['calc']
426
705
  @actual = yaml_hash['actual']
427
706
  end
428
707
 
708
+ #
709
+ # 検証する
710
+ #
711
+ # @return [Array<String>] エラーメッセージ
712
+ #
429
713
  def validate
430
714
  failed = []
431
715
 
@@ -448,19 +732,37 @@ module Zakuro
448
732
  end
449
733
 
450
734
  #
451
- # 月日数(大小)
735
+ # Days 月日数(大小)
452
736
  #
453
737
  class Days
454
738
  NAME = 'days'
455
739
 
456
- attr_reader :index, :calc, :actual
740
+ # @return [Integer] 連番
741
+ attr_reader :index
742
+ # @return [String] 計算
743
+ attr_reader :calc
744
+ # @return [String] 運用
745
+ attr_reader :actual
457
746
 
747
+ #
748
+ # 初期化
749
+ #
750
+ # @param [Integer] index 連番
751
+ # @param [Hash<String, String>] yaml_hash yaml
752
+ # @option yaml_hash [String] :calc 計算
753
+ # @option yaml_hash [String] :actual 運用
754
+ #
458
755
  def initialize(index:, yaml_hash: {})
459
756
  @index = index
460
757
  @calc = yaml_hash['calc']
461
758
  @actual = yaml_hash['actual']
462
759
  end
463
760
 
761
+ #
762
+ # 検証する
763
+ #
764
+ # @return [Array<String>] エラーメッセージ
765
+ #
464
766
  def validate
465
767
  failed = []
466
768
 
@@ -482,6 +784,8 @@ module Zakuro
482
784
  end
483
785
  end
484
786
 
787
+ # :reek:TooManyStatements { max_statements: 7 }
788
+
485
789
  def self.run(yaml_hash: {})
486
790
  failed = []
487
791
  yaml_hash.each_with_index do |history, index|