zakuro 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +46 -17
  4. data/VERSION +1 -1
  5. data/doc/dropped_date.md +93 -0
  6. data/doc/error.md +45 -0
  7. data/doc/operation/transfer.rb +8 -8
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +49 -3
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  11. data/lib/zakuro/calculation/base/operated_year.rb +26 -24
  12. data/lib/zakuro/calculation/base/year.rb +7 -7
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
  14. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  15. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  16. data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +44 -37
  17. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  19. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  20. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +156 -0
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  27. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +73 -0
  28. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
  29. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  30. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  31. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  32. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  33. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  34. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  35. data/lib/zakuro/calculation/monthly/month.rb +55 -16
  36. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  37. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  38. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  39. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  40. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  41. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +45 -29
  42. data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
  43. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  44. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  45. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  46. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  47. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  48. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  49. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  50. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  51. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  52. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  53. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  54. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  55. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  56. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  57. data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
  58. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  59. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  60. data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
  61. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  62. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
  63. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  64. data/lib/zakuro/calculation/summary/western/range.rb +127 -0
  65. data/lib/zakuro/calculation/summary/western/single.rb +115 -0
  66. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
  67. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
  68. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  69. data/lib/zakuro/calculation/type/optional.rb +46 -0
  70. data/lib/zakuro/condition.rb +143 -94
  71. data/lib/zakuro/context/context.rb +44 -0
  72. data/lib/zakuro/context/option.rb +119 -0
  73. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  74. data/lib/zakuro/era/japan/calendar.rb +35 -33
  75. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
  76. data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
  77. data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
  78. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
  79. data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
  80. data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
  81. data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
  82. data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
  83. data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
  84. data/lib/zakuro/era/japan/gengou.rb +28 -41
  85. data/lib/zakuro/era/japan/version.rb +18 -16
  86. data/lib/zakuro/era/western/calendar.rb +104 -88
  87. data/lib/zakuro/exception/case/pattern.rb +71 -0
  88. data/lib/zakuro/exception/case/preset.rb +51 -0
  89. data/lib/zakuro/exception/case/template.rb +48 -0
  90. data/lib/zakuro/exception/cause.rb +28 -0
  91. data/lib/zakuro/exception/exception.rb +39 -0
  92. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  93. data/lib/zakuro/gateway/locale/date.rb +127 -0
  94. data/lib/zakuro/gateway/locale/range.rb +67 -0
  95. data/lib/zakuro/gateway/range.rb +99 -0
  96. data/lib/zakuro/gateway/single.rb +81 -0
  97. data/lib/zakuro/merchant.rb +67 -33
  98. data/lib/zakuro/operation/month/parser.rb +252 -249
  99. data/lib/zakuro/operation/month/type.rb +44 -35
  100. data/lib/zakuro/operation/month/validator.rb +182 -178
  101. data/lib/zakuro/operation/operation.rb +38 -36
  102. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  103. data/lib/zakuro/output/logger.rb +17 -3
  104. data/lib/zakuro/output/response.rb +107 -141
  105. data/lib/zakuro/result/data/day.rb +43 -0
  106. data/lib/zakuro/result/data/gengou.rb +35 -0
  107. data/lib/zakuro/result/data/month.rb +63 -0
  108. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  109. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  110. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  111. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  112. data/lib/zakuro/result/data/single_day.rb +56 -0
  113. data/lib/zakuro/result/data/solar_term.rb +35 -0
  114. data/lib/zakuro/result/data/year.rb +45 -0
  115. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  116. data/lib/zakuro/result/operation/month/history.rb +54 -0
  117. data/lib/zakuro/result/operation/month.rb +31 -0
  118. data/lib/zakuro/result/operation.rb +22 -97
  119. data/lib/zakuro/result/result.rb +6 -4
  120. data/lib/zakuro/tools/stringifier.rb +67 -42
  121. data/lib/zakuro/tools/typeconv.rb +17 -15
  122. data/lib/zakuro/tools/typeof.rb +15 -13
  123. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  124. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  125. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  126. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  127. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  128. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  129. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  130. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  131. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  132. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  133. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  134. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  135. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  136. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  137. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  138. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  139. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  140. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  141. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  142. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  143. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  144. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  145. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  146. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  147. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  148. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  149. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  150. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  151. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  152. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  153. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  154. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  155. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  156. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  157. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  158. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  159. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  160. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  161. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  162. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  163. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  164. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  165. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  166. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  167. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  168. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  169. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  170. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  171. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  172. metadata +68 -16
  173. data/lib/zakuro/calculation/range/operated_range.rb +0 -193
  174. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
  175. data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
  176. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  177. data/lib/zakuro/calculation/summary/range.rb +0 -120
  178. data/lib/zakuro/calculation/summary/single.rb +0 -110
  179. data/lib/zakuro/result/data.rb +0 -187
  180. data/lib/zakuro/version/context.rb +0 -44
  181. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -6,284 +6,293 @@ require_relative '../../calendar'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
9
- #
10
- # Japan 和暦
11
- #
9
+ # :nodoc:
12
10
  module Japan
13
- #
14
- # Resource yaml解析結果
15
- #
16
- module Resource
11
+ # :nodoc:
12
+ module Gengou
17
13
  #
18
- # Gengou 元号情報
14
+ # Resource yaml解析結果
19
15
  #
20
- class Gengou
21
- # @return [String] 元号名
22
- attr_reader :name
23
- # @return [Both::Year] 開始年(和暦/西暦)
24
- attr_reader :both_start_year
25
- # @return [Both::Date] 開始日(和暦/西暦)
26
- attr_reader :both_start_date
27
- # @return [Integer] 終了年
28
- attr_reader :last_year
29
- # @return [Western::Calendar] 終了日
30
- attr_reader :last_date
16
+ module Resource
17
+ #
18
+ # Gengou 元号情報
19
+ #
20
+ class Gengou
21
+ # @return [String] 元号名
22
+ attr_reader :name
23
+ # @return [Both::Year] 開始年(和暦/西暦)
24
+ attr_reader :both_start_year
25
+ # @return [Both::Date] 開始日(和暦/西暦)
26
+ attr_reader :both_start_date
27
+ # @return [Integer] 終了年
28
+ attr_reader :last_year
29
+ # @return [Western::Calendar] 終了日
30
+ attr_reader :last_date
31
31
 
32
- #
33
- # 初期化
34
- #
35
- # @param [String] name 元号名
36
- # @param [Both::Year] both_start_year 開始年(和暦/西暦)
37
- # @param [Both::Date] both_start_date 開始日(和暦/西暦)
38
- # @param [Integer] last_date 終了年
39
- # @param [Western::Calendar] last_date 終了日
40
- #
41
- def initialize(name: '', both_start_year: Both::Year.new,
42
- both_start_date: Both::Date.new,
43
- last_date: Western::Calendar.new,
44
- last_year: Both::Year::INVALID)
45
- @name = name
46
- @both_start_year = both_start_year
47
- @both_start_date = both_start_date
48
- @last_year = last_year
49
- @last_date = last_date
50
- end
51
-
52
- #
53
- # 終了年を更新する
54
- #
55
- # @param [Integer] last_year 終了年
56
- #
57
- def write_last_year(last_year:)
58
- unless Gengou.valid_year(year: last_year)
59
- raise ArgumentError, "invalid year format. [#{last_year}]"
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [String] name 元号名
36
+ # @param [Both::Year] both_start_year 開始年(和暦/西暦)
37
+ # @param [Both::Date] both_start_date 開始日(和暦/西暦)
38
+ # @param [Integer] last_date 終了年
39
+ # @param [Western::Calendar] last_date 終了日
40
+ #
41
+ def initialize(name: '', both_start_year: Both::Year.new,
42
+ both_start_date: Both::Date.new,
43
+ last_date: Western::Calendar.new,
44
+ last_year: Both::Year::INVALID)
45
+ @name = name
46
+ @both_start_year = both_start_year
47
+ @both_start_date = both_start_date
48
+ @last_year = last_year
49
+ @last_date = last_date
60
50
  end
61
51
 
62
- @last_year = last_year
63
- end
52
+ #
53
+ # 終了年を更新する
54
+ #
55
+ # @param [Integer] last_year 終了年
56
+ #
57
+ # @raise [ArgumentError] 引数エラー
58
+ #
59
+ def write_last_year(last_year:)
60
+ unless Gengou.valid_year(year: last_year)
61
+ raise ArgumentError, "invalid year format. [#{last_year}]"
62
+ end
64
63
 
65
- #
66
- # 終了日を更新する
67
- #
68
- # @param [Western::Calendar] last_date 終了日
69
- #
70
- def write_last_date(last_date:)
71
- unless Gengou.valid_date(date: last_date)
72
- raise ArgumentError, "invalid date format. [#{last_date}]"
64
+ @last_year = last_year
73
65
  end
74
66
 
75
- @last_date = last_date
76
- nil
77
- end
78
-
79
- #
80
- # 年が不正なしかどうかを確認する
81
- #
82
- # @param [Integer] year 年
83
- #
84
- # @return [True] 不正なし
85
- # @return [False] 不正
86
- #
87
- def self.valid_year(year:)
88
- return false unless year
67
+ #
68
+ # 終了日を更新する
69
+ #
70
+ # @param [Western::Calendar] last_date 終了日
71
+ #
72
+ # @raise [ArgumentError] 引数エラー
73
+ #
74
+ def write_last_date(last_date:)
75
+ unless Gengou.valid_date(date: last_date)
76
+ raise ArgumentError, "invalid date format. [#{last_date}]"
77
+ end
89
78
 
90
- year.is_a?(Integer)
91
- end
79
+ @last_date = last_date
80
+ nil
81
+ end
92
82
 
93
- #
94
- # 日付が不正なしかどうかを確認する
95
- #
96
- # @param [Western::Calendar] date 日付
97
- #
98
- # @return [True] 不正なし
99
- # @return [False] 不正
100
- #
101
- def self.valid_date(date:)
102
- return false unless date
83
+ #
84
+ # 次の元号の開始年から、元号の終了年に変換する
85
+ #
86
+ # @param [Integer] next_start_year 次回開始年
87
+ #
88
+ def convert_next_start_year_to_last_year(next_start_year:)
89
+ if both_start_year.western >= next_start_year
90
+ @last_year = next_start_year
91
+ return
92
+ end
103
93
 
104
- date.is_a?(Western::Calendar)
105
- end
94
+ @last_year = next_start_year - 1
106
95
 
107
- #
108
- # 次の元号の開始年から、元号の終了年に変換する
109
- #
110
- # @param [Integer] next_start_year 次回開始年
111
- #
112
- def convert_next_start_year_to_last_year(next_start_year:)
113
- if @both_start_year.western >= next_start_year
114
- @last_year = next_start_year
115
- return
96
+ nil
116
97
  end
117
98
 
118
- @last_year = next_start_year - 1
119
-
120
- nil
121
- end
99
+ #
100
+ # 次の元号の開始日から、元号の終了日に変換する
101
+ #
102
+ # @param [String] next_start_date 次回開始日
103
+ #
104
+ # @raise [ArgumentError] 引数エラー
105
+ #
106
+ def convert_next_start_date_to_last_date(next_start_date: '')
107
+ raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
122
108
 
123
- #
124
- # 次の元号の開始日から、元号の終了日に変換する
125
- #
126
- # @param [String] next_start_date 次回開始日
127
- #
128
- def convert_next_start_date_to_last_date(next_start_date: '')
129
- raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
109
+ start_date = Western::Calendar.parse(text: next_start_date)
110
+ @last_date = start_date - 1
130
111
 
131
- start_date = Western::Calendar.parse(str: next_start_date)
132
- @last_date = start_date - 1
112
+ nil
113
+ end
133
114
 
134
- nil
135
- end
115
+ #
116
+ # 指定した日が元号に含まれるか
117
+ #
118
+ # @param [Western::Calendar] date 日
119
+ #
120
+ # @return [True] 含まれる
121
+ # @return [False] 含まれない
122
+ #
123
+ def include?(date:)
124
+ date >= both_start_date.western && date <= last_date
125
+ end
136
126
 
137
- #
138
- # 指定した日が元号に含まれるか
139
- #
140
- # @param [Western::Calendar] date 日
141
- #
142
- # @return [True] 含まれる
143
- # @return [False] 含まれない
144
- #
145
- def include?(date:)
146
- date >= @both_start_date.western && date <= @last_date
147
- end
127
+ #
128
+ # 不正か
129
+ #
130
+ # @return [True] 不正
131
+ # @return [False] 不正なし
132
+ #
133
+ def invalid?
134
+ both_start_year.japan == -1 || both_start_year.invalid? ||
135
+ both_start_date.invalid? || last_date.invalid?
136
+ end
148
137
 
149
- #
150
- # 不正か
151
- #
152
- # @return [True] 不正
153
- # @return [False] 不正なし
154
- #
155
- def invalid?
156
- @both_start_year.japan == -1 || @both_start_year.invalid? ||
157
- @both_start_date.invalid? || @last_date.invalid?
158
- end
138
+ #
139
+ # 1元号年を追加する
140
+ #
141
+ # def next_year
142
+ # @year += 1 unless invalid?
143
+ # nil
144
+ # end
145
+
146
+ def to_s
147
+ "name: #{@name}, both_start_year: #{both_start_year.format}, " \
148
+ "both_start_date: #{both_start_date.format}, last_date: #{last_date.format}"
149
+ end
159
150
 
160
- #
161
- # 1元号年を追加する
162
- #
163
- # def next_year
164
- # @year += 1 unless invalid?
165
- # nil
166
- # end
167
-
168
- def to_s
169
- "name: #{@name}, both_start_year: #{@both_start_year.format}, " \
170
- "both_start_date: #{@both_start_date.format}, last_date: #{@last_date.format}"
151
+ class << self
152
+ #
153
+ # 年が不正なしかどうかを確認する
154
+ #
155
+ # @param [Integer] year
156
+ #
157
+ # @return [True] 不正なし
158
+ # @return [False] 不正
159
+ #
160
+ def valid_year(year:)
161
+ return false unless year
162
+
163
+ year.is_a?(Integer)
164
+ end
165
+
166
+ #
167
+ # 日付が不正なしかどうかを確認する
168
+ #
169
+ # @param [Western::Calendar] date 日付
170
+ #
171
+ # @return [True] 不正なし
172
+ # @return [False] 不正
173
+ #
174
+ def valid_date(date:)
175
+ return false unless date
176
+
177
+ date.is_a?(Western::Calendar)
178
+ end
179
+ end
171
180
  end
172
- end
173
181
 
174
- #
175
- # Set 元号セット
176
- #
177
- class Set
178
- # @return [Integer] 不正値
179
- INVALID = -1
180
- # @return [Integer] 元号セットID
181
- attr_reader :id
182
- # @return [String] 元号セット名
183
- attr_reader :name
184
- # @return [Both::Date] 元号セットでの終了年
185
- attr_reader :both_last_year
186
- # @return [Both::Date] 元号セットでの終了日
187
- attr_reader :both_last_date
188
- # @return [Array<Gengou>] 元号リスト
189
- attr_reader :list
190
-
191
- #
192
- # 初期化
193
182
  #
194
- # @param [Integer] id 元号セットID
195
- # @param [String] name 元号セット名
196
- # @param [Western::Calendar] last_date 元号セットでの終了日
197
- # @param [Array<Gengou>] list 元号リスト
183
+ # Set 元号セット
198
184
  #
199
- def initialize(id: INVALID, name: '', both_last_year: Both::Year.new,
200
- both_last_date: Both::Date.new, list: [])
201
- @id = id
202
- @name = name
203
- @both_last_year = both_last_year
204
- @both_last_date = both_last_date
205
- @list = list
206
- end
185
+ class Set
186
+ # @return [Integer] 不正値
187
+ INVALID = -1
188
+ # @return [Integer] 元号セットID
189
+ attr_reader :id
190
+ # @return [String] 元号セット名
191
+ attr_reader :name
192
+ # @return [Both::Date] 元号セットでの終了年
193
+ attr_reader :both_last_year
194
+ # @return [Both::Date] 元号セットでの終了日
195
+ attr_reader :both_last_date
196
+ # @return [Array<Gengou>] 元号リスト
197
+ attr_reader :list
207
198
 
208
- #
209
- # 指定した日付を含む元号を返す
210
- #
211
- # @param [Western::Calendar] date
212
- #
213
- # @return [Gengou] 元号
214
- #
215
- def include_item(date:)
216
- @list.each do |item|
217
- return item if item.include?(date: date)
199
+ #
200
+ # 初期化
201
+ #
202
+ # @param [Integer] id 元号セットID
203
+ # @param [String] name 元号セット名
204
+ # @param [Western::Calendar] last_date 元号セットでの終了日
205
+ # @param [Array<Gengou>] list 元号リスト
206
+ #
207
+ def initialize(id: INVALID, name: '', both_last_year: Both::Year.new,
208
+ both_last_date: Both::Date.new, list: [])
209
+ @id = id
210
+ @name = name
211
+ @both_last_year = both_last_year
212
+ @both_last_date = both_last_date
213
+ @list = list
218
214
  end
219
215
 
220
- Gengou.new
221
- end
222
-
223
- #
224
- # 元号セットが不正かどうかを確認する
225
- #
226
- # @return [True] 正しくない
227
- # @return [False] 正しい
228
- #
229
- def invalid?
230
- @id == INVALID
231
- end
232
- end
216
+ #
217
+ # 指定した日付を含む元号を返す
218
+ #
219
+ # @param [Western::Calendar] date 日
220
+ #
221
+ # @return [Gengou] 元号
222
+ #
223
+ def include_item(date:)
224
+ list.each do |item|
225
+ return item if item.include?(date: date)
226
+ end
233
227
 
234
- #
235
- # 和暦/西暦
236
- #
237
- module Both
238
- #
239
- # Year 年
240
- #
241
- class Year
242
- # @return [Integer] 不正値
243
- INVALID = -1
244
- # @return [Integer] 和暦元号年
245
- attr_reader :japan
246
- # @return [Integer] 西暦年
247
- attr_reader :western
248
-
249
- def initialize(japan: INVALID, western: INVALID)
250
- @japan = japan
251
- @western = western
228
+ Gengou.new
252
229
  end
253
230
 
254
231
  #
255
- # 不正か
232
+ # 元号セットが不正かどうかを確認する
256
233
  #
257
- # @return [True] 不正
258
- # @return [False] 不正なし
234
+ # @return [True] 正しくない
235
+ # @return [False] 正しい
259
236
  #
260
237
  def invalid?
261
- @japan == INVALID || @western == INVALID
238
+ @id == INVALID
262
239
  end
263
240
  end
264
241
 
265
242
  #
266
- # Date 日
243
+ # 和暦/西暦
267
244
  #
268
- class Date
269
- # @return [Japan::Calendar] 和暦日
270
- attr_reader :japan
271
- # @return [Western::Calendar] 西暦日
272
- attr_reader :western
273
-
274
- def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
275
- @japan = japan
276
- @western = western
245
+ module Both
246
+ #
247
+ # Year 年
248
+ #
249
+ class Year
250
+ # @return [Integer] 不正値
251
+ INVALID = -1
252
+ # @return [Integer] 和暦元号年
253
+ attr_reader :japan
254
+ # @return [Integer] 西暦年
255
+ attr_reader :western
256
+
257
+ def initialize(japan: INVALID, western: INVALID)
258
+ @japan = japan
259
+ @western = western
260
+ end
261
+
262
+ #
263
+ # 不正か
264
+ #
265
+ # @return [True] 不正
266
+ # @return [False] 不正なし
267
+ #
268
+ def invalid?
269
+ japan == INVALID || western == INVALID
270
+ end
277
271
  end
278
272
 
279
273
  #
280
- # 不正か
274
+ # Date 日
281
275
  #
282
- # @return [True] 不正
283
- # @return [False] 不正なし
284
- #
285
- def invalid?
286
- @japan.invalid? || @western.invalid?
276
+ class Date
277
+ # @return [Japan::Calendar] 和暦日
278
+ attr_reader :japan
279
+ # @return [Western::Calendar] 西暦日
280
+ attr_reader :western
281
+
282
+ def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
283
+ @japan = japan
284
+ @western = western
285
+ end
286
+
287
+ #
288
+ # 不正か
289
+ #
290
+ # @return [True] 不正
291
+ # @return [False] 不正なし
292
+ #
293
+ def invalid?
294
+ japan.invalid? || western.invalid?
295
+ end
287
296
  end
288
297
  end
289
298
  end