zakuro 0.9.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/README.md +41 -8
  4. data/VERSION +1 -1
  5. data/doc/gengou.md +1 -1
  6. data/doc/operation/csv/month.csv +8 -9
  7. data/doc/operation/operation.xlsx +0 -0
  8. data/images/logo-text.png +0 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +2 -4
  10. data/lib/zakuro/calculation/base/year.rb +1 -1
  11. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +6 -0
  12. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +2 -2
  13. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +4 -2
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +1 -1
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +13 -7
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +18 -9
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +6 -2
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +5 -2
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +3 -3
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +12 -4
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +10 -4
  22. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +5 -2
  23. data/lib/zakuro/calculation/era/version/internal/crawler.rb +3 -3
  24. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +1 -1
  25. data/lib/zakuro/calculation/monthly/internal/date_comparer.rb +78 -0
  26. data/lib/zakuro/calculation/monthly/{meta → internal/meta}/all_solar_term.rb +1 -1
  27. data/lib/zakuro/calculation/monthly/{meta → internal/meta}/meta_collector.rb +2 -2
  28. data/lib/zakuro/calculation/monthly/{first_day.rb → internal/part/first_day.rb} +2 -2
  29. data/lib/zakuro/calculation/monthly/{meta.rb → internal/part/meta.rb} +1 -1
  30. data/lib/zakuro/calculation/monthly/internal/solar_term_selector.rb +203 -0
  31. data/lib/zakuro/calculation/monthly/month.rb +38 -74
  32. data/lib/zakuro/calculation/monthly/operated_month.rb +7 -2
  33. data/lib/zakuro/calculation/option/dropped_date/location.rb +8 -1
  34. data/lib/zakuro/calculation/range/dated_full_range.rb +6 -3
  35. data/lib/zakuro/calculation/range/dated_operation_range.rb +2 -1
  36. data/lib/zakuro/calculation/range/medieval_annual_range.rb +0 -2
  37. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  38. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +24 -10
  39. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +3 -3
  40. data/lib/zakuro/calculation/summary/internal/option/dropped_date.rb +102 -0
  41. data/lib/zakuro/calculation/summary/internal/option/vanished_date.rb +111 -0
  42. data/lib/zakuro/calculation/summary/internal/option.rb +4 -137
  43. data/lib/zakuro/calculation/summary/japan/range.rb +4 -5
  44. data/lib/zakuro/calculation/summary/western/range.rb +8 -1
  45. data/lib/zakuro/calculation/summary/western/single.rb +10 -5
  46. data/lib/zakuro/context/version_class_resolver.rb +5 -5
  47. data/lib/zakuro/era/japan/calendar.rb +4 -4
  48. data/lib/zakuro/era/japan/gengou/alignment/division.rb +2 -2
  49. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +2 -2
  50. data/lib/zakuro/era/japan/gengou/alignment.rb +35 -6
  51. data/lib/zakuro/era/japan/gengou/resource/parser.rb +17 -16
  52. data/lib/zakuro/era/japan/gengou/resource/validator.rb +3 -394
  53. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +2 -2
  54. data/lib/zakuro/era/japan/gengou.rb +8 -6
  55. data/lib/zakuro/era/japan/type/base/both/date.rb +51 -0
  56. data/lib/zakuro/era/japan/type/base/both/year.rb +53 -0
  57. data/lib/zakuro/era/japan/type/base/gengou.rb +177 -0
  58. data/lib/zakuro/era/japan/type/base/gengou_set.rb +78 -0
  59. data/lib/zakuro/era/japan/type/base/switch_date.rb +74 -0
  60. data/lib/zakuro/era/japan/type/base/version_range.rb +189 -0
  61. data/lib/zakuro/era/japan/type/validation/both/date.rb +99 -0
  62. data/lib/zakuro/era/japan/type/validation/both/year.rb +75 -0
  63. data/lib/zakuro/era/japan/type/validation/gengou.rb +93 -0
  64. data/lib/zakuro/era/japan/type/validation/gengou_set.rb +133 -0
  65. data/lib/zakuro/era/japan/type/validation/switch_date.rb +73 -0
  66. data/lib/zakuro/era/japan/type/validation/version_range.rb +109 -0
  67. data/lib/zakuro/era/japan/type/validation/version_root.rb +102 -0
  68. data/lib/zakuro/era/japan/version/resource/parser.rb +266 -0
  69. data/lib/zakuro/era/japan/version/resource/validator.rb +37 -0
  70. data/lib/zakuro/era/japan/version/resource/yaml/version.yaml +80 -0
  71. data/lib/zakuro/era/japan/version/resource.rb +22 -0
  72. data/lib/zakuro/era/japan/version.rb +4 -115
  73. data/lib/zakuro/era/western/calendar.rb +2 -2
  74. data/lib/zakuro/exception/zakuro_error.rb +1 -1
  75. data/lib/zakuro/merchant.rb +5 -5
  76. data/lib/zakuro/operation/month/parser.rb +2 -2
  77. data/lib/zakuro/operation/yaml/month.yaml +8 -40
  78. data/lib/zakuro/output/logger.rb +4 -4
  79. data/lib/zakuro/parameter/catalog/basis_date.rb +55 -0
  80. data/lib/zakuro/parameter/catalog/column.rb +57 -0
  81. data/lib/zakuro/parameter/catalog/option.rb +60 -0
  82. data/lib/zakuro/parameter/catalog/range.rb +81 -0
  83. data/lib/zakuro/parameter/condition.rb +108 -0
  84. data/lib/zakuro/result/core.rb +2 -2
  85. data/lib/zakuro/{tools → tool}/remainder_comparer.rb +3 -2
  86. data/lib/zakuro/{tools → tool}/stringifier.rb +3 -3
  87. data/lib/zakuro/{tools → tool}/typeconv.rb +2 -2
  88. data/lib/zakuro/{tools → tool}/typeof.rb +2 -2
  89. data/lib/zakuro/version/daien/const/number.rb +42 -39
  90. data/lib/zakuro/version/daien/const/remainder.rb +38 -35
  91. data/lib/zakuro/version/daien/cycle/remainder.rb +77 -74
  92. data/lib/zakuro/version/daien/cycle/solar_term.rb +18 -15
  93. data/lib/zakuro/version/daien/daien.rb +8 -5
  94. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +67 -64
  95. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +15 -12
  96. data/lib/zakuro/version/daien/option/vanished_date/parameter.rb +15 -12
  97. data/lib/zakuro/version/daien/range/annual_range.rb +27 -24
  98. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +209 -206
  99. data/lib/zakuro/version/daien/stella/lunar/localization.rb +32 -29
  100. data/lib/zakuro/version/daien/stella/lunar/location.rb +53 -50
  101. data/lib/zakuro/version/daien/stella/lunar/value.rb +65 -62
  102. data/lib/zakuro/version/daien/stella/origin/average_november.rb +23 -20
  103. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +42 -39
  104. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +44 -41
  105. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +74 -71
  106. data/lib/zakuro/version/daien/stella/solar/average.rb +68 -65
  107. data/lib/zakuro/version/daien/stella/solar/interval.rb +95 -92
  108. data/lib/zakuro/version/daien/stella/solar/location.rb +41 -38
  109. data/lib/zakuro/version/daien/stella/solar/value.rb +21 -18
  110. data/lib/zakuro/version/genka/const/number.rb +31 -28
  111. data/lib/zakuro/version/genka/const/remainder.rb +20 -17
  112. data/lib/zakuro/version/genka/cycle/remainder.rb +72 -69
  113. data/lib/zakuro/version/genka/cycle/solar_term.rb +18 -15
  114. data/lib/zakuro/version/genka/genka.rb +8 -5
  115. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +82 -79
  116. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +13 -10
  117. data/lib/zakuro/version/genka/option/vanished_date/parameter.rb +13 -10
  118. data/lib/zakuro/version/genka/range/annual_range.rb +57 -54
  119. data/lib/zakuro/version/genka/stella/origin/first_term.rb +44 -41
  120. data/lib/zakuro/version/genka/stella/origin/january.rb +38 -35
  121. data/lib/zakuro/version/genka/stella/solar/average.rb +24 -21
  122. data/lib/zakuro/version/gihou/const/number.rb +40 -37
  123. data/lib/zakuro/version/gihou/const/remainder.rb +32 -29
  124. data/lib/zakuro/version/gihou/cycle/remainder.rb +38 -35
  125. data/lib/zakuro/version/gihou/cycle/solar_term.rb +18 -15
  126. data/lib/zakuro/version/gihou/gihou.rb +8 -5
  127. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +68 -65
  128. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +13 -10
  129. data/lib/zakuro/version/gihou/option/vanished_date/parameter.rb +13 -10
  130. data/lib/zakuro/version/gihou/range/annual_range.rb +27 -24
  131. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +212 -209
  132. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +32 -29
  133. data/lib/zakuro/version/gihou/stella/lunar/location.rb +53 -50
  134. data/lib/zakuro/version/gihou/stella/lunar/value.rb +65 -62
  135. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +23 -20
  136. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +42 -39
  137. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +44 -41
  138. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +74 -71
  139. data/lib/zakuro/version/gihou/stella/solar/average.rb +67 -64
  140. data/lib/zakuro/version/gihou/stella/solar/interval.rb +95 -92
  141. data/lib/zakuro/version/gihou/stella/solar/location.rb +41 -38
  142. data/lib/zakuro/version/gihou/stella/solar/value.rb +21 -18
  143. data/lib/zakuro/version/gregorio/gregorio.rb +8 -5
  144. data/lib/zakuro/version/houryaku/houryaku.rb +8 -5
  145. data/lib/zakuro/version/joukyou/joukyou.rb +8 -5
  146. data/lib/zakuro/version/kansei/kansei.rb +8 -5
  147. data/lib/zakuro/version/senmyou/const/number.rb +40 -37
  148. data/lib/zakuro/version/senmyou/const/remainder.rb +35 -32
  149. data/lib/zakuro/version/senmyou/cycle/remainder.rb +74 -71
  150. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +18 -15
  151. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +69 -66
  152. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +15 -12
  153. data/lib/zakuro/version/senmyou/option/vanished_date/parameter.rb +15 -12
  154. data/lib/zakuro/version/senmyou/range/annual_range.rb +27 -24
  155. data/lib/zakuro/version/senmyou/senmyou.rb +8 -5
  156. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +206 -203
  157. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +32 -29
  158. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +60 -57
  159. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -63
  160. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +23 -20
  161. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +42 -39
  162. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +44 -41
  163. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +74 -71
  164. data/lib/zakuro/version/senmyou/stella/solar/average.rb +67 -64
  165. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +93 -90
  166. data/lib/zakuro/version/senmyou/stella/solar/location.rb +41 -38
  167. data/lib/zakuro/version/senmyou/stella/solar/value.rb +23 -20
  168. data/lib/zakuro/version/tenpou/tenpou.rb +8 -5
  169. metadata +40 -15
  170. data/lib/zakuro/condition.rb +0 -306
  171. data/lib/zakuro/era/japan/gengou/resource/type.rb +0 -356
  172. /data/lib/zakuro/calculation/monthly/{operated_solar_term.rb → internal/operated_solar_term.rb} +0 -0
  173. /data/lib/zakuro/calculation/monthly/{const.rb → internal/part/const.rb} +0 -0
  174. /data/lib/zakuro/calculation/monthly/{month_label.rb → internal/part/month_label.rb} +0 -0
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../western/calendar'
4
+ require_relative '../../calendar'
5
+ require_relative './both/date'
6
+ require_relative './both/year'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Japan
12
+ # :nodoc:
13
+ module Type
14
+ # :nodoc:
15
+ module Validation
16
+ #
17
+ # Gengou 元号情報
18
+ #
19
+ class Gengou
20
+ # @return [Integer] 要素位置
21
+ attr_reader :index
22
+ # @return [String] 元号名
23
+ attr_reader :name
24
+ # @return [Hash<String, String>] 開始年
25
+ attr_reader :start_year
26
+ # @return [Hash<String, String>] 開始日
27
+ attr_reader :start_date
28
+
29
+ #
30
+ # 初期化
31
+ #
32
+ # @param [Hash<String, Strin>] hash 元号情報
33
+ # @param [Integer] index (元号セット内での)元号の要素位置
34
+ #
35
+ def initialize(hash:, index:)
36
+ @index = index
37
+ @name = hash['name']
38
+ @start_year = hash['start_year']
39
+ @start_date = hash['start_date']
40
+ end
41
+
42
+ #
43
+ # 検証する
44
+ #
45
+ # @return [Array<String>] 不正メッセージ
46
+ #
47
+ def validate
48
+ prefix = "list[#{index}]. "
49
+ failed = []
50
+
51
+ failed.push(prefix + "invalid name. #{name}") unless name?
52
+
53
+ failed |= validate_start_year
54
+
55
+ failed |= validate_start_date
56
+
57
+ failed
58
+ end
59
+
60
+ #
61
+ # 元号名を検証する
62
+ #
63
+ # @return [True] 正しい
64
+ # @return [False] 正しくない
65
+ #
66
+ def name?
67
+ return false unless name
68
+
69
+ name.is_a?(String)
70
+ end
71
+
72
+ #
73
+ # 開始年を検証する
74
+ #
75
+ # @return [Array<String>] 不正メッセージ
76
+ #
77
+ def validate_start_year
78
+ Both::Year.new(hash: start_year).validate
79
+ end
80
+
81
+ #
82
+ # 開始日を検証する
83
+ #
84
+ # @return [Array<String>] 不正メッセージ
85
+ #
86
+ def validate_start_date
87
+ SwitchDate.new(hash: start_date).validate
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './gengou'
4
+ require_relative './switch_date'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Japan
10
+ # :nodoc:
11
+ module Type
12
+ # :nodoc:
13
+ module Validation
14
+ #
15
+ # GengouSet 元号セット情報の検証/展開
16
+ #
17
+ class GengouSet
18
+ # @return [String] 元号セットID
19
+ attr_reader :id
20
+ # @return [String] 元号セット名
21
+ attr_reader :name
22
+ # @return [Hash<String, String>] 終了年
23
+ attr_reader :last_year
24
+ # @return [Hash<String, String>] 終了日
25
+ attr_reader :last_date
26
+ # @return [Array<Hash<String, String>>] 元号情報
27
+ attr_reader :list
28
+
29
+ #
30
+ # 初期化
31
+ #
32
+ # @param [Hash<String, Object>] hash 元号セット情報
33
+ #
34
+ def initialize(hash:)
35
+ @id = hash['id']
36
+ @name = hash['name']
37
+ @last_year = hash['last_year']
38
+ @last_date = hash['last_date']
39
+ @list = hash['list']
40
+ end
41
+
42
+ #
43
+ # 検証する
44
+ #
45
+ # @return [Array<String>] 不正メッセージ
46
+ #
47
+ def validate
48
+ failed = []
49
+ failed.push("invalid id. #{id}") unless id?
50
+
51
+ failed.push("invalid name. #{name}") unless name?
52
+
53
+ failed |= validate_last_year
54
+
55
+ failed |= validate_last_date
56
+
57
+ failed |= validate_list
58
+ failed
59
+ end
60
+
61
+ #
62
+ # IDを検証する
63
+ #
64
+ # @return [True] 正しい
65
+ # @return [False] 正しくない
66
+ #
67
+ def id?
68
+ return false unless id
69
+
70
+ id.is_a?(Integer)
71
+ end
72
+
73
+ #
74
+ # 元号セット名を検証する
75
+ #
76
+ # @return [True] 正しい
77
+ # @return [False] 正しくない
78
+ #
79
+ def name?
80
+ return false unless @name
81
+
82
+ name.is_a?(String)
83
+ end
84
+
85
+ #
86
+ # 終了年を検証する
87
+ #
88
+ # @return [Array<String>] 不正メッセージ
89
+ #
90
+ def validate_last_year
91
+ Both::Year.new(hash: last_year).validate
92
+ end
93
+
94
+ #
95
+ # 終了日を検証する
96
+ #
97
+ # @return [Array<String>] 不正メッセージ
98
+ #
99
+ def validate_last_date
100
+ SwitchDate.new(hash: last_date).validate
101
+ end
102
+
103
+ #
104
+ # 元号情報を検証する
105
+ #
106
+ # @return [True] 正しい
107
+ # @return [False] 正しくない
108
+ #
109
+ def list?
110
+ return false unless list
111
+
112
+ list.is_a?(Array)
113
+ end
114
+
115
+ #
116
+ # 元号情報を検証する
117
+ #
118
+ # @return [Array<String>] 不正メッセージ
119
+ #
120
+ def validate_list
121
+ return ["invalid list. #{list.class}"] unless list?
122
+
123
+ failed = []
124
+ list.each_with_index do |li, index|
125
+ failed |= Gengou.new(hash: li, index: index).validate
126
+ end
127
+ failed
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../western/calendar'
4
+ require_relative '../../calendar'
5
+ require_relative './both/date'
6
+ require_relative './both/year'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Japan
12
+ # :nodoc:
13
+ module Type
14
+ # :nodoc:
15
+ module Validation
16
+ #
17
+ # SwitchDate 切替日(運用/計算)
18
+ #
19
+ class SwitchDate
20
+ # @return [Hash<String, Strin>] 計算値
21
+ attr_reader :calculation
22
+ # @return [Hash<String, Strin>] 運用値
23
+ attr_reader :operation
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [Hash<String, Strin>] hash 切替日(運用/計算)
29
+ #
30
+ def initialize(hash:)
31
+ @calculation = hash['calculation']
32
+ @operation = hash['operation']
33
+ end
34
+
35
+ #
36
+ # 検証する
37
+ #
38
+ # @return [Array<String>] 不正メッセージ
39
+ #
40
+ def validate
41
+ failed = []
42
+
43
+ failed |= validate_calculation_date
44
+
45
+ failed |= validate_operation_date
46
+
47
+ failed
48
+ end
49
+
50
+ private
51
+
52
+ #
53
+ # 日(計算値)を検証する
54
+ #
55
+ # @return [Array<String>] 不正メッセージ
56
+ #
57
+ def validate_calculation_date
58
+ Both::Date.new(hash: calculation, optional: true).validate
59
+ end
60
+
61
+ #
62
+ # 日(運用値)を検証する
63
+ #
64
+ # @return [Array<String>] 不正メッセージ
65
+ #
66
+ def validate_operation_date
67
+ Both::Date.new(hash: operation).validate
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './both/date'
4
+ require_relative './both/year'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Japan
10
+ # :nodoc:
11
+ module Type
12
+ # :nodoc:
13
+ module Validation
14
+ #
15
+ # VersionRange 暦期間情報
16
+ #
17
+ class VersionRange
18
+ # @return [Integer] 要素位置
19
+ attr_reader :index
20
+ # @return [String] 元号名
21
+ attr_reader :name
22
+ # @return [Hash<String, String>] 開始年
23
+ attr_reader :start_year
24
+ # @return [Hash<String, String>] 開始日
25
+ attr_reader :start_date
26
+ # @return [True] リリース有
27
+ # @return [False] リリース無
28
+ attr_reader :released
29
+
30
+ #
31
+ # 初期化
32
+ #
33
+ # @param [Hash<String, Strin>] hash 元号情報
34
+ # @param [Integer] index 暦情報の要素位置
35
+ #
36
+ def initialize(hash:, index:)
37
+ @index = index
38
+ @name = hash['name']
39
+ @start_year = hash['start_year']
40
+ @start_date = hash['start_date']
41
+ @released = hash['released']
42
+ end
43
+
44
+ #
45
+ # 検証する
46
+ #
47
+ # @return [Array<String>] 不正メッセージ
48
+ #
49
+ def validate
50
+ prefix = "list[#{index}]. "
51
+ failed = []
52
+
53
+ failed.push(prefix + "invalid name. #{name}") unless name?
54
+
55
+ failed |= validate_start_year
56
+
57
+ failed |= validate_start_date
58
+
59
+ failed.push(prefix + "invalid released. #{released}") unless released?
60
+
61
+ failed
62
+ end
63
+
64
+ #
65
+ # 元号名を検証する
66
+ #
67
+ # @return [True] 正しい
68
+ # @return [False] 正しくない
69
+ #
70
+ def name?
71
+ return false unless name
72
+
73
+ name.is_a?(String)
74
+ end
75
+
76
+ #
77
+ # 開始年を検証する
78
+ #
79
+ # @return [Array<String>] 不正メッセージ
80
+ #
81
+ def validate_start_year
82
+ Both::Year.new(hash: start_year).validate
83
+ end
84
+
85
+ #
86
+ # 開始日を検証する
87
+ #
88
+ # @return [Array<String>] 不正メッセージ
89
+ #
90
+ def validate_start_date
91
+ Both::Date.new(hash: start_date).validate
92
+ end
93
+
94
+ #
95
+ # リリース有無を検証する
96
+ #
97
+ # @return [True] 正しい
98
+ # @return [False] 正しくない
99
+ #
100
+ def released?
101
+ return false if released.nil?
102
+
103
+ released.is_a?(TrueClass) || released.is_a?(FalseClass)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './both/date'
4
+ require_relative './both/year'
5
+ require_relative './version_range'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Japan
11
+ # :nodoc:
12
+ module Type
13
+ # :nodoc:
14
+ module Validation
15
+ #
16
+ # VersionRoot 暦基本情報
17
+ #
18
+ class VersionRoot
19
+ # @return [Hash<String, String>] 終了年
20
+ attr_reader :last_year
21
+ # @return [Hash<String, String>] 終了日
22
+ attr_reader :last_date
23
+ # @return [Array<Hash<String, String>>] 暦期間情報
24
+ attr_reader :list
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [Hash<String, Object>] hash 暦情報
30
+ #
31
+ def initialize(hash:)
32
+ @last_year = hash['last_year']
33
+ @last_date = hash['last_date']
34
+ @list = hash['list']
35
+ end
36
+
37
+ #
38
+ # 検証する
39
+ #
40
+ # @return [Array<String>] 不正メッセージ
41
+ #
42
+ def validate
43
+ failed = []
44
+
45
+ failed |= validate_last_year
46
+
47
+ failed |= validate_last_date
48
+
49
+ failed |= validate_list
50
+
51
+ failed
52
+ end
53
+
54
+ #
55
+ # 終了年を検証する
56
+ #
57
+ # @return [Array<String>] 不正メッセージ
58
+ #
59
+ def validate_last_year
60
+ Both::Year.new(hash: last_year).validate
61
+ end
62
+
63
+ #
64
+ # 終了日を検証する
65
+ #
66
+ # @return [Array<String>] 不正メッセージ
67
+ #
68
+ def validate_last_date
69
+ Both::Date.new(hash: last_date).validate
70
+ end
71
+
72
+ #
73
+ # 暦期間情報を検証する
74
+ #
75
+ # @return [True] 正しい
76
+ # @return [False] 正しくない
77
+ #
78
+ def list?
79
+ return false unless list
80
+
81
+ list.is_a?(Array)
82
+ end
83
+
84
+ #
85
+ # 暦期間情報を検証する
86
+ #
87
+ # @return [Array<String>] 不正メッセージ
88
+ #
89
+ def validate_list
90
+ return ["invalid list. #{list.class}"] unless list?
91
+
92
+ failed = []
93
+ list.each_with_index do |li, index|
94
+ failed |= VersionRange.new(hash: li, index: index).validate
95
+ end
96
+ failed
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end