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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../../western/calendar'
4
- require_relative './type'
4
+ require_relative '../../type/base/gengou_set'
5
5
  require_relative './validator'
6
6
  require 'yaml'
7
7
 
@@ -41,6 +41,7 @@ module Zakuro
41
41
  #
42
42
  # @param [Hash<String, Strin>] hash 元号情報
43
43
  # @param [Integer] index (元号セット内での)元号の要素位置
44
+ # @param [True, False] operated 運用値設定
44
45
  #
45
46
  def initialize(hash:, index:, operated: false)
46
47
  @index = index
@@ -53,21 +54,21 @@ module Zakuro
53
54
  #
54
55
  # 元号情報を生成する
55
56
  #
56
- # @return [Gengou] 元号情報
57
+ # @return [Type::Base::Gengou] 元号情報
57
58
  #
58
59
  def create
59
60
  year = Both::YearParser.new(hash: start_year).create
60
61
  date = SwitchDateParser.new(hash: start_date, operated: operated).create
61
62
 
62
- Gengou.new(name: name, start_year: year,
63
- start_date: date)
63
+ Type::Base::Gengou.new(name: name, start_year: year,
64
+ start_date: date)
64
65
  end
65
66
  end
66
67
 
67
68
  #
68
- # SetParser 元号セット情報の検証/展開
69
+ # GengouSetParser 元号セット情報の検証/展開
69
70
  #
70
- class SetParser
71
+ class GengouSetParser
71
72
  # @return [String] 元号セットID
72
73
  attr_reader :id
73
74
  # @return [String] 元号セット名
@@ -99,12 +100,12 @@ module Zakuro
99
100
  #
100
101
  # 元号セット情報を生成する
101
102
  #
102
- # @return [Set] 元号セット情報
103
+ # @return [Type::Base::GengouSet] 元号セット情報
103
104
  #
104
105
  def create
105
106
  date = SwitchDateParser.new(hash: last_date, operated: operated).create
106
107
  list = create_list
107
- Set.new(
108
+ Type::Base::GengouSet.new(
108
109
  id: id, name: name, last_date: date, list: list
109
110
  )
110
111
  end
@@ -114,7 +115,7 @@ module Zakuro
114
115
  #
115
116
  # 元号情報を生成する
116
117
  #
117
- # @return [Array<Gengou>] 元号情報
118
+ # @return [Array<Type::Base::Gengou>] 元号情報
118
119
  #
119
120
  def create_list
120
121
  result = []
@@ -200,13 +201,13 @@ module Zakuro
200
201
  #
201
202
  # 切替日(運用/計算)情報を生成する
202
203
  #
203
- # @return [SwitchDate] 切替日(運用/計算)情報
204
+ # @return [Type::Base::SwitchDate] 切替日(運用/計算)情報
204
205
  #
205
206
  def create
206
207
  calculation_date = Both::DateParser.new(hash: calculation).create
207
208
  operation_date = Both::DateParser.new(hash: operation).create
208
209
 
209
- Japan::Gengou::Resource::SwitchDate.new(
210
+ Type::Base::SwitchDate.new(
210
211
  calculation: calculation_date, operation: operation_date,
211
212
  operated: operated
212
213
  )
@@ -245,7 +246,7 @@ module Zakuro
245
246
  japan_year = japan.to_i
246
247
  western_year = western.to_i
247
248
 
248
- Japan::Gengou::Resource::Both::Year.new(
249
+ Type::Base::Both::Year.new(
249
250
  japan: japan_year, western: western_year
250
251
  )
251
252
  end
@@ -273,7 +274,7 @@ module Zakuro
273
274
  #
274
275
  # 日情報を生成する
275
276
  #
276
- # @return [Both::Date] 日情報
277
+ # @return [Type::Base::Both::Date] 日情報
277
278
  #
278
279
  def create
279
280
  japan_date = Japan::Calendar.new
@@ -282,7 +283,7 @@ module Zakuro
282
283
  japan_date = Japan::Calendar.parse(text: japan) unless japan == ''
283
284
  western_date = Western::Calendar.parse(text: western) unless western == ''
284
285
 
285
- Japan::Gengou::Resource::Both::Date.new(
286
+ Type::Base::Both::Date.new(
286
287
  japan: japan_date, western: western_date
287
288
  )
288
289
  end
@@ -296,7 +297,7 @@ module Zakuro
296
297
  # @param [String] filepath 元号セットファイルパス
297
298
  # @param [True, False] operated 運用値設定
298
299
  #
299
- # @return [Set] 元号セット情報
300
+ # @return [Type::Base::GengouSet] 元号セット情報
300
301
  #
301
302
  # @raise [ArgumentError] 引数エラー
302
303
  #
@@ -307,7 +308,7 @@ module Zakuro
307
308
 
308
309
  raise ArgumentError, failed.join("\n") unless failed.empty?
309
310
 
310
- parser = SetParser.new(hash: yaml, operated: operated)
311
+ parser = GengouSetParser.new(hash: yaml, operated: operated)
311
312
  parser.create
312
313
  end
313
314
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../japan/calendar'
4
- require_relative '../../../western/calendar'
5
- require_relative './type'
3
+ require_relative '../../type/validation/gengou_set'
4
+
6
5
  require 'yaml'
7
6
 
8
7
  # :nodoc:
@@ -19,396 +18,6 @@ module Zakuro
19
18
  # Validator yaml解析
20
19
  #
21
20
  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 :last_year
32
- # @return [Hash<String, String>] 終了日
33
- attr_reader :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
- @last_year = hash['last_year']
46
- @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_last_year
62
-
63
- failed |= validate_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_last_year
99
- Both::Year.new(hash: last_year).validate
100
- end
101
-
102
- #
103
- # 終了日を検証する
104
- #
105
- # @return [Array<String>] 不正メッセージ
106
- #
107
- def validate_last_date
108
- SwitchDate.new(hash: 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 :start_year
149
- # @return [Hash<String, String>] 開始日
150
- attr_reader :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
- @start_year = hash['start_year']
162
- @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_start_year
177
-
178
- failed |= validate_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_start_year
201
- Both::Year.new(hash: start_year).validate
202
- end
203
-
204
- #
205
- # 開始日を検証する
206
- #
207
- # @return [Array<String>] 不正メッセージ
208
- #
209
- def validate_start_date
210
- SwitchDate.new(hash: start_date).validate
211
- end
212
- end
213
-
214
- #
215
- # SwitchDate 切替日(運用/計算)
216
- #
217
- class SwitchDate
218
- # @return [Hash<String, Strin>] 計算値
219
- attr_reader :calculation
220
- # @return [Hash<String, Strin>] 運用値
221
- attr_reader :operation
222
-
223
- #
224
- # 初期化
225
- #
226
- # @param [Hash<String, Strin>] hash 切替日(運用/計算)
227
- #
228
- def initialize(hash:)
229
- @calculation = hash['calculation']
230
- @operation = hash['operation']
231
- end
232
-
233
- #
234
- # 検証する
235
- #
236
- # @return [Array<String>] 不正メッセージ
237
- #
238
- def validate
239
- failed = []
240
-
241
- failed |= validate_calculation_date
242
-
243
- failed |= validate_operation_date
244
-
245
- failed
246
- end
247
-
248
- private
249
-
250
- #
251
- # 日(計算値)を検証する
252
- #
253
- # @return [Array<String>] 不正メッセージ
254
- #
255
- def validate_calculation_date
256
- Both::Date.new(hash: calculation, optional: true).validate
257
- end
258
-
259
- #
260
- # 日(運用値)を検証する
261
- #
262
- # @return [Array<String>] 不正メッセージ
263
- #
264
- def validate_operation_date
265
- Both::Date.new(hash: operation).validate
266
- end
267
- end
268
-
269
- #
270
- # 和暦/西暦
271
- #
272
- module Both
273
- #
274
- # Year 年
275
- #
276
- class Year
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 year. #{japan}") unless japan?
301
-
302
- failed.push("invalid western year. #{western}") unless western?
303
-
304
- failed
305
- end
306
-
307
- #
308
- # 和暦元号年を検証する
309
- #
310
- # @return [True] 正しい
311
- # @return [False] 正しくない
312
- #
313
- def japan?
314
- return false unless @japan
315
-
316
- japan.is_a?(Integer)
317
- end
318
-
319
- #
320
- # 和暦元号年を検証する
321
- #
322
- # @return [True] 正しい
323
- # @return [False] 正しくない
324
- #
325
- def western?
326
- return false unless @western
327
-
328
- western.is_a?(Integer)
329
- end
330
- end
331
-
332
- #
333
- # Date 日
334
- #
335
- class Date
336
- # @return [String] 和暦日
337
- attr_reader :japan
338
- # @return [String] 西暦日
339
- attr_reader :western
340
- # @return [True] 省略可
341
- # @return [False] 省略不可
342
- attr_reader :optional
343
-
344
- #
345
- # 初期化
346
- #
347
- # @param [Hash<String, Strin>] hash 日情報
348
- #
349
- def initialize(hash:, optional: false)
350
- @japan = hash['japan']
351
- @western = hash['western']
352
- @optional = optional
353
- end
354
-
355
- #
356
- # 検証する
357
- #
358
- # @return [Array<String>] 不正メッセージ
359
- #
360
- def validate
361
- failed = []
362
-
363
- failed.push("invalid japan date. #{japan}") unless japan?
364
-
365
- failed.push("invalid western date. #{western}") unless western?
366
-
367
- failed
368
- end
369
-
370
- #
371
- # 和暦日を検証する
372
- #
373
- # @return [True] 正しい
374
- # @return [False] 正しくない
375
- #
376
- def japan?
377
- return true if optional?(text: japan)
378
-
379
- Japan::Calendar.valid_date_text(text: japan)
380
- end
381
-
382
- #
383
- # 西暦日を検証する
384
- #
385
- # @return [True] 正しい
386
- # @return [False] 正しくない
387
- #
388
- def western?
389
- return true if optional?(text: western)
390
-
391
- Western::Calendar.valid_date_text(text: western)
392
- end
393
-
394
- #
395
- # 省略可で省略されているか
396
- #
397
- # @param [String] text 文字列
398
- #
399
- # @return [True] 省略あり
400
- # @return [False] 省略なし
401
- #
402
- def optional?(text: '')
403
- return false unless optional
404
-
405
- return true if text == ''
406
-
407
- false
408
- end
409
- end
410
- end
411
-
412
21
  class << self
413
22
  #
414
23
  # 検証する
@@ -418,7 +27,7 @@ module Zakuro
418
27
  # @return [Array<String>] 不正メッセージ
419
28
  #
420
29
  def run(yaml_hash:)
421
- Set.new(hash: yaml_hash).validate
30
+ Type::Validation::GengouSet.new(hash: yaml_hash).validate
422
31
  end
423
32
  end
424
33
  end
@@ -1125,13 +1125,13 @@ list:
1125
1125
  start_date:
1126
1126
  calculation:
1127
1127
  japan: ''
1128
- western: ''
1128
+ western: '1037-5-8'
1129
1129
  operation:
1130
1130
  japan: 長暦01年04月21日
1131
1131
  western: '1037-5-9'
1132
1132
  disuse:
1133
1133
  new_year_date: '1037-1-19'
1134
- note: ''
1134
+ note: '行親記(計算:1037-5-8)'
1135
1135
  - name: 長久
1136
1136
  start_year:
1137
1137
  japan: 1
@@ -27,29 +27,31 @@ module Zakuro
27
27
  # @param [Western::Calendar] start_date 開始日
28
28
  # @param [Western::Calendar] last_date 終了日
29
29
  # @param [True, False] operated 運用値設定
30
+ # @param [True, False] restored 運用値から計算値に戻すか
30
31
  #
31
32
  # @return [Array<LinearGengou>] 該当行の元号
32
33
  #
33
34
  def line(line: FIRST_LINE,
34
35
  start_date: Western::Calendar.new, last_date: Western::Calendar.new,
35
- operated: false)
36
+ operated: false, restored: false)
36
37
  Alignment.get(
37
- line: line, start_date: start_date, last_date: last_date, operated: operated
38
+ line: line, start_date: start_date, last_date: last_date, operated: operated,
39
+ restored: restored
38
40
  )
39
41
  end
40
42
 
41
43
  #
42
44
  # 該当行の元号を取得する(元号名)
43
45
  #
46
+ # @param [String] name 元号名
44
47
  # @param [Integer] line 行番号
45
- # @param [Western::Calendar] start_date 開始日
46
- # @param [Western::Calendar] last_date 終了日
47
48
  # @param [True, False] operated 運用値設定
49
+ # @param [True, False] restored 運用値から計算値に戻すか
48
50
  #
49
51
  # @return [Array<LinearGengou>] 該当行の元号
50
52
  #
51
- def line_by_name(line: FIRST_LINE, name:, operated: false)
52
- Alignment.get_by_name(line: line, name: name, operated: operated)
53
+ def line_by_name(name:, line: FIRST_LINE, operated: false, restored: false)
54
+ Alignment.get_by_name(name: name, line: line, operated: operated, restored: restored)
53
55
  end
54
56
  end
55
57
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../western/calendar'
4
+
5
+ require_relative '../../../calendar'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Japan
11
+ # :nodoc:
12
+ module Type
13
+ # :nodoc:
14
+ module Base
15
+ # :nodoc:
16
+ module Both
17
+ #
18
+ # Date 日
19
+ #
20
+ class Date
21
+ # @return [Japan::Calendar] 和暦日
22
+ attr_reader :japan
23
+ # @return [Western::Calendar] 西暦日
24
+ attr_reader :western
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [Japan::Calendar] japan 和暦日
30
+ # @param [Western::Calendar] western 西暦日
31
+ #
32
+ def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
33
+ @japan = japan
34
+ @western = western
35
+ end
36
+
37
+ #
38
+ # 不正か
39
+ #
40
+ # @return [True] 不正
41
+ # @return [False] 不正なし
42
+ #
43
+ def invalid?
44
+ japan.invalid? || western.invalid?
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../western/calendar'
4
+
5
+ require_relative '../../../calendar'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Japan
11
+ # :nodoc:
12
+ module Type
13
+ # :nodoc:
14
+ module Base
15
+ # :nodoc:
16
+ module Both
17
+ #
18
+ # Year 年
19
+ #
20
+ class Year
21
+ # @return [Integer] 不正値
22
+ INVALID = -1
23
+ # @return [Integer] 和暦元号年
24
+ attr_reader :japan
25
+ # @return [Integer] 西暦年
26
+ attr_reader :western
27
+
28
+ #
29
+ # 初期化
30
+ #
31
+ # @param [Integer] japan 和暦元号年
32
+ # @param [Integer] western 西暦年
33
+ #
34
+ def initialize(japan: INVALID, western: INVALID)
35
+ @japan = japan
36
+ @western = western
37
+ end
38
+
39
+ #
40
+ # 不正か
41
+ #
42
+ # @return [True] 不正
43
+ # @return [False] 不正なし
44
+ #
45
+ def invalid?
46
+ japan == INVALID || western == INVALID
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end