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,177 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../western/calendar'
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 Base
14
+ #
15
+ # Gengou 元号情報
16
+ #
17
+ class Gengou
18
+ # @return [String] 元号名
19
+ attr_reader :name
20
+ # @return [Both::Year] 開始年(和暦/西暦)
21
+ attr_reader :start_year
22
+ # @return [SwitchDate] 開始日(和暦/西暦)
23
+ attr_reader :start_date
24
+ # @return [Integer] 終了年
25
+ attr_reader :last_year
26
+ # @return [Western::Calendar] 終了日
27
+ attr_reader :last_date
28
+
29
+ #
30
+ # 初期化
31
+ #
32
+ # @param [String] name 元号名
33
+ # @param [Both::Year] start_year 開始年(和暦/西暦)
34
+ # @param [SwitchDate] start_date 開始日(和暦/西暦)
35
+ # @param [Integer] last_date 終了年
36
+ # @param [Western::Calendar] last_date 終了日
37
+ #
38
+ def initialize(name: '', start_year: Both::Year.new,
39
+ start_date: SwitchDate.new,
40
+ last_date: Western::Calendar.new,
41
+ last_year: Both::Year::INVALID)
42
+ @name = name
43
+ @start_year = start_year
44
+ @start_date = start_date
45
+ @last_year = last_year
46
+ @last_date = last_date
47
+ end
48
+
49
+ #
50
+ # 終了年を更新する
51
+ #
52
+ # @param [Integer] last_year 終了年
53
+ #
54
+ # @raise [ArgumentError] 引数エラー
55
+ #
56
+ def write_last_year(last_year:)
57
+ unless self.class.valid_year(year: last_year)
58
+ raise ArgumentError, "invalid year format. [#{last_year}]"
59
+ end
60
+
61
+ @last_year = last_year
62
+ end
63
+
64
+ #
65
+ # 終了日を更新する
66
+ #
67
+ # @param [Western::Calendar] last_date 終了日
68
+ #
69
+ # @raise [ArgumentError] 引数エラー
70
+ #
71
+ def write_last_date(last_date:)
72
+ unless self.class.valid_date(date: last_date)
73
+ raise ArgumentError, "invalid date format. [#{last_date}]"
74
+ end
75
+
76
+ @last_date = last_date
77
+ nil
78
+ end
79
+
80
+ #
81
+ # 次の元号の開始年から、元号の終了年に変換する
82
+ #
83
+ # @param [Integer] next_start_year 次回開始年
84
+ #
85
+ def convert_next_start_year_to_last_year(next_start_year:)
86
+ if start_year.western >= next_start_year
87
+ @last_year = next_start_year
88
+ return
89
+ end
90
+
91
+ @last_year = next_start_year - 1
92
+
93
+ nil
94
+ end
95
+
96
+ #
97
+ # 次の元号の開始日から、元号の終了日に変換する
98
+ #
99
+ # @param [Western::Calendar] next_start_date 次回開始日
100
+ #
101
+ # @raise [ArgumentError] 引数エラー
102
+ #
103
+ def convert_next_start_date_to_last_date(next_start_date: Western::Calendar.new)
104
+ raise ArgumentError, 'invalid value. cannot convert' if next_start_date.invalid?
105
+
106
+ @last_date = next_start_date.clone - 1
107
+
108
+ nil
109
+ end
110
+
111
+ #
112
+ # 指定した日が元号に含まれるか
113
+ #
114
+ # @param [Western::Calendar] date 日
115
+ #
116
+ # @return [True] 含まれる
117
+ # @return [False] 含まれない
118
+ #
119
+ def include?(date:)
120
+ date >= start_date.western && date <= last_date
121
+ end
122
+
123
+ #
124
+ # 不正か
125
+ #
126
+ # @return [True] 不正
127
+ # @return [False] 不正なし
128
+ #
129
+ def invalid?
130
+ start_year.japan == -1 || start_year.invalid? ||
131
+ start_date.invalid? || last_date.invalid?
132
+ end
133
+
134
+ #
135
+ # インスタンス値(文字列)を取得する
136
+ #
137
+ # @return [String] インスタンス値(文字列)
138
+ #
139
+ def to_s
140
+ "name: #{@name}, start_year: #{start_year.format}, " \
141
+ "start_date: #{start_date.format}, last_date: #{last_date.format}"
142
+ end
143
+
144
+ class << self
145
+ #
146
+ # 年が不正なしかどうかを確認する
147
+ #
148
+ # @param [Integer] year 年
149
+ #
150
+ # @return [True] 不正なし
151
+ # @return [False] 不正
152
+ #
153
+ def valid_year(year:)
154
+ return false unless year
155
+
156
+ year.is_a?(Integer)
157
+ end
158
+
159
+ #
160
+ # 日付が不正なしかどうかを確認する
161
+ #
162
+ # @param [Western::Calendar] date 日付
163
+ #
164
+ # @return [True] 不正なし
165
+ # @return [False] 不正
166
+ #
167
+ def valid_date(date:)
168
+ return false unless date
169
+
170
+ date.is_a?(Western::Calendar)
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './both/date'
4
+ require_relative './both/year'
5
+ require_relative './gengou'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Japan
11
+ # :nodoc:
12
+ module Type
13
+ # :nodoc:
14
+ module Base
15
+ #
16
+ # GengouSet 元号セット
17
+ #
18
+ class GengouSet
19
+ # @return [Integer] 不正値
20
+ INVALID = -1
21
+ # @return [Integer] 元号セットID
22
+ attr_reader :id
23
+ # @return [String] 元号セット名
24
+ attr_reader :name
25
+ # @return [Both::Year] 元号セットでの終了年
26
+ attr_reader :last_year
27
+ # @return [Both::Date] 元号セットでの終了日
28
+ attr_reader :last_date
29
+ # @return [Array<Gengou>] 元号リスト
30
+ attr_reader :list
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [Integer] id 元号セットID
36
+ # @param [String] name 元号セット名
37
+ # @param [Both::Year] last_year 元号セットでの終了年
38
+ # @param [Both::Date] last_date 元号セットでの終了日
39
+ # @param [Array<Gengou>] list 元号リスト
40
+ #
41
+ def initialize(id: INVALID, name: '', last_year: Both::Year.new,
42
+ last_date: Both::Date.new, list: [])
43
+ @id = id
44
+ @name = name
45
+ @last_year = last_year
46
+ @last_date = last_date
47
+ @list = list
48
+ end
49
+
50
+ #
51
+ # 指定した日付を含む元号を返す
52
+ #
53
+ # @param [Western::Calendar] date 日
54
+ #
55
+ # @return [Gengou] 元号
56
+ #
57
+ def include_item(date:)
58
+ list.each do |item|
59
+ return item if item.include?(date: date)
60
+ end
61
+
62
+ Gengou.new
63
+ end
64
+
65
+ #
66
+ # 元号セットが不正かどうかを確認する
67
+ #
68
+ # @return [True] 正しくない
69
+ # @return [False] 正しい
70
+ #
71
+ def invalid?
72
+ @id == INVALID
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,74 @@
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 Base
16
+ #
17
+ # SwitchDate 切替日(運用/計算)
18
+ #
19
+ class SwitchDate
20
+ # @return [Both::Date] 計算値
21
+ attr_reader :calculation
22
+ # @return [Both::Date] 運用値
23
+ attr_reader :operation
24
+ # @return [True, False] 運用値
25
+ attr_reader :operated
26
+ # @return [Japan::Calendar] 和暦日
27
+ attr_reader :japan
28
+ # @return [Western::Calendar] 西暦日
29
+ attr_reader :western
30
+
31
+ #
32
+ # 初期化
33
+ #
34
+ # @param [Both::Date] calculation 計算値
35
+ # @param [Both::Date] operation 運用値
36
+ # @param [True, False] operated 運用値設定
37
+ #
38
+ def initialize(calculation: Both::Date.new, operation: Both::Date.new, operated: false)
39
+ @calculation = calculation
40
+ @operation = operation
41
+ @operated = operated
42
+
43
+ select
44
+ end
45
+
46
+ #
47
+ # 不正か
48
+ #
49
+ # @return [True] 不正
50
+ # @return [False] 不正なし
51
+ #
52
+ def invalid?
53
+ japan.invalid? || western.invalid?
54
+ end
55
+
56
+ private
57
+
58
+ def select
59
+ @japan = operation.japan
60
+ @western = operation.western
61
+
62
+ return if operated
63
+
64
+ calc_japan = calculation.japan
65
+ calc_western = calculation.western
66
+
67
+ @japan = calc_japan unless calc_japan.invalid?
68
+ @western = calc_western unless calc_western.invalid?
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../western/calendar'
4
+ require_relative './both/date'
5
+ require_relative './both/year'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Japan
11
+ # :nodoc:
12
+ module Type
13
+ # :nodoc:
14
+ module Base
15
+ #
16
+ # VersionRange 暦範囲情報
17
+ #
18
+ class VersionRange
19
+ # @return [String] 暦名
20
+ attr_reader :name
21
+ # @return [Both::Year] 開始年(和暦/西暦)
22
+ attr_reader :start_year
23
+ # @return [Both::Date] 開始日(和暦/西暦)
24
+ attr_reader :start_date
25
+ # @return [Integer] 終了年
26
+ attr_reader :last_year
27
+ # @return [Western::Calendar] 終了日
28
+ attr_reader :last_date
29
+ # @return [True] リリース有
30
+ # @return [False] リリース無
31
+ attr_reader :released
32
+
33
+ # rubocop:disable Metrics/ParameterLists
34
+
35
+ #
36
+ # 初期化
37
+ #
38
+ # @param [String] name 暦名
39
+ # @param [Both::Year] start_year 開始年(和暦/西暦)
40
+ # @param [Both::Date] start_date 開始日(和暦/西暦)
41
+ # @param [Integer] last_date 終了年
42
+ # @param [Western::Calendar] last_date 終了日
43
+ # @param [True, False] released リリース有無
44
+ #
45
+ def initialize(
46
+ name: '', start_year: Both::Year.new,
47
+ start_date: Both::Date.new,
48
+ last_date: Western::Calendar.new, last_year: Both::Year::INVALID,
49
+ released: false
50
+ )
51
+ @name = name
52
+ @start_year = start_year
53
+ @start_date = start_date
54
+ @last_year = last_year
55
+ @last_date = last_date
56
+ @released = released
57
+ end
58
+ # rubocop:enable Metrics/ParameterLists
59
+
60
+ #
61
+ # 終了年を更新する
62
+ #
63
+ # @param [Integer] last_year 終了年
64
+ #
65
+ # @raise [ArgumentError] 引数エラー
66
+ #
67
+ def write_last_year(last_year:)
68
+ unless self.class.valid_year(year: last_year)
69
+ raise ArgumentError, "invalid year format. [#{last_year}]"
70
+ end
71
+
72
+ @last_year = last_year
73
+ end
74
+
75
+ #
76
+ # 終了日を更新する
77
+ #
78
+ # @param [Western::Calendar] last_date 終了日
79
+ #
80
+ # @raise [ArgumentError] 引数エラー
81
+ #
82
+ def write_last_date(last_date:)
83
+ unless self.class.valid_date(date: last_date)
84
+ raise ArgumentError, "invalid date format. [#{last_date}]"
85
+ end
86
+
87
+ @last_date = last_date
88
+
89
+ nil
90
+ end
91
+
92
+ #
93
+ # 次の元号の開始年から、元号の終了年に変換する
94
+ #
95
+ # @param [Integer] next_start_year 次回開始年
96
+ #
97
+ def convert_next_start_year_to_last_year(next_start_year:)
98
+ if start_year.western >= next_start_year
99
+ @last_year = next_start_year
100
+ return
101
+ end
102
+
103
+ @last_year = next_start_year - 1
104
+
105
+ nil
106
+ end
107
+
108
+ #
109
+ # 次の元号の開始日から、元号の終了日に変換する
110
+ #
111
+ # @param [Western::Calendar] next_start_date 次回開始日
112
+ #
113
+ # @raise [ArgumentError] 引数エラー
114
+ #
115
+ def convert_next_start_date_to_last_date(next_start_date: Western::Calendar.new)
116
+ raise ArgumentError, 'invalid value. cannot convert' if next_start_date.invalid?
117
+
118
+ @last_date = next_start_date.clone - 1
119
+
120
+ nil
121
+ end
122
+
123
+ #
124
+ # 指定した日が元号に含まれるか
125
+ #
126
+ # @param [Western::Calendar] date 日
127
+ #
128
+ # @return [True] 含まれる
129
+ # @return [False] 含まれない
130
+ #
131
+ def include?(date:)
132
+ date >= start_date.western && date <= last_date
133
+ end
134
+
135
+ #
136
+ # 不正か
137
+ #
138
+ # @return [True] 不正
139
+ # @return [False] 不正なし
140
+ #
141
+ def invalid?
142
+ start_year.japan == -1 || start_year.invalid? ||
143
+ start_date.invalid? || last_date.invalid?
144
+ end
145
+
146
+ #
147
+ # インスタンス値(文字列)を取得する
148
+ #
149
+ # @return [String] インスタンス値(文字列)
150
+ #
151
+ def to_s
152
+ "name: #{@name}, start_year: #{start_year.format}, " \
153
+ "start_date: #{start_date.format}, last_date: #{last_date.format}"
154
+ end
155
+
156
+ class << self
157
+ #
158
+ # 年が不正なしかどうかを確認する
159
+ #
160
+ # @param [Integer] year 年
161
+ #
162
+ # @return [True] 不正なし
163
+ # @return [False] 不正
164
+ #
165
+ def valid_year(year:)
166
+ return false unless year
167
+
168
+ year.is_a?(Integer)
169
+ end
170
+
171
+ #
172
+ # 日付が不正なしかどうかを確認する
173
+ #
174
+ # @param [Western::Calendar] date 日付
175
+ #
176
+ # @return [True] 不正なし
177
+ # @return [False] 不正
178
+ #
179
+ def valid_date(date:)
180
+ return false unless date
181
+
182
+ date.is_a?(Western::Calendar)
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,99 @@
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 Validation
15
+ # :nodoc:
16
+ module Both
17
+ #
18
+ # Date 日
19
+ #
20
+ class Date
21
+ # @return [String] 和暦日
22
+ attr_reader :japan
23
+ # @return [String] 西暦日
24
+ attr_reader :western
25
+ # @return [True] 省略可
26
+ # @return [False] 省略不可
27
+ attr_reader :optional
28
+
29
+ #
30
+ # 初期化
31
+ #
32
+ # @param [Hash<String, Strin>] hash 日情報
33
+ #
34
+ def initialize(hash:, optional: false)
35
+ @japan = hash['japan']
36
+ @western = hash['western']
37
+ @optional = optional
38
+ end
39
+
40
+ #
41
+ # 検証する
42
+ #
43
+ # @return [Array<String>] 不正メッセージ
44
+ #
45
+ def validate
46
+ failed = []
47
+
48
+ failed.push("invalid japan date. #{japan}") unless japan?
49
+
50
+ failed.push("invalid western date. #{western}") unless western?
51
+
52
+ failed
53
+ end
54
+
55
+ #
56
+ # 和暦日を検証する
57
+ #
58
+ # @return [True] 正しい
59
+ # @return [False] 正しくない
60
+ #
61
+ def japan?
62
+ return true if optional?(text: japan)
63
+
64
+ Japan::Calendar.valid_date_text(text: japan)
65
+ end
66
+
67
+ #
68
+ # 西暦日を検証する
69
+ #
70
+ # @return [True] 正しい
71
+ # @return [False] 正しくない
72
+ #
73
+ def western?
74
+ return true if optional?(text: western)
75
+
76
+ Western::Calendar.valid_date_text(text: western)
77
+ end
78
+
79
+ #
80
+ # 省略可で省略されているか
81
+ #
82
+ # @param [String] text 文字列
83
+ #
84
+ # @return [True] 省略あり
85
+ # @return [False] 省略なし
86
+ #
87
+ def optional?(text: '')
88
+ return false unless optional
89
+
90
+ return true if text == ''
91
+
92
+ false
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Japan
7
+ # :nodoc:
8
+ module Type
9
+ # :nodoc:
10
+ module Validation
11
+ # :nodoc:
12
+ module Both
13
+ #
14
+ # Year 年
15
+ #
16
+ class Year
17
+ # @return [String] 和暦元号年
18
+ attr_reader :japan
19
+ # @return [String] 西暦年
20
+ attr_reader :western
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Hash<String, Strin>] hash 年情報
26
+ #
27
+ def initialize(hash:)
28
+ @japan = hash['japan']
29
+ @western = hash['western']
30
+ end
31
+
32
+ #
33
+ # 検証する
34
+ #
35
+ # @return [Array<String>] 不正メッセージ
36
+ #
37
+ def validate
38
+ failed = []
39
+
40
+ failed.push("invalid japan year. #{japan}") unless japan?
41
+
42
+ failed.push("invalid western year. #{western}") unless western?
43
+
44
+ failed
45
+ end
46
+
47
+ #
48
+ # 和暦元号年を検証する
49
+ #
50
+ # @return [True] 正しい
51
+ # @return [False] 正しくない
52
+ #
53
+ def japan?
54
+ return false unless @japan
55
+
56
+ japan.is_a?(Integer)
57
+ end
58
+
59
+ #
60
+ # 和暦元号年を検証する
61
+ #
62
+ # @return [True] 正しい
63
+ # @return [False] 正しくない
64
+ #
65
+ def western?
66
+ return false unless @western
67
+
68
+ western.is_a?(Integer)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end