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
@@ -60,7 +60,7 @@ module Zakuro
60
60
  #
61
61
  def replace(gengou:)
62
62
  matched_index = -1
63
- @unsolved_list.each_with_index do |unsolved, index|
63
+ unsolved_list.each_with_index do |unsolved, index|
64
64
  next unless unsolved.name == gengou.name
65
65
 
66
66
  matched_index = index
@@ -68,18 +68,18 @@ module Zakuro
68
68
  end
69
69
 
70
70
  if matched_index == -1
71
- @unsolved_list.push(gengou)
71
+ unsolved_list.push(gengou)
72
72
  return gengou
73
73
  end
74
74
 
75
- matched = @unsolved_list[matched_index]
75
+ matched = unsolved_list[matched_index]
76
76
 
77
77
  result = recreate(gengou: gengou, unsolved: matched)
78
78
 
79
79
  @unsolved_list[matched_index] = result
80
80
 
81
81
  # 分離した元号の末尾まで到達した
82
- @unsolved_list.delete_at(matched_index) unless result.change_last_date?
82
+ unsolved_list.delete_at(matched_index) unless result.change_last_date?
83
83
 
84
84
  result
85
85
  end
@@ -56,9 +56,9 @@ module Zakuro
56
56
  # @return [Japan::Calendar] 和暦開始日
57
57
  #
58
58
  def japan_start_date
59
- return Japan::Calendar.new if @gengou.invalid?
59
+ return Japan::Calendar.new if gengou.invalid?
60
60
 
61
- @gengou.both_start_date.japan
61
+ gengou.both_start_date.japan
62
62
  end
63
63
 
64
64
  #
@@ -67,9 +67,9 @@ module Zakuro
67
67
  # @return [Western::Calendar] 西暦開始日
68
68
  #
69
69
  def western_start_date
70
- return Western::Calendar.new if @gengou.invalid?
70
+ return Western::Calendar.new if gengou.invalid?
71
71
 
72
- @start_date
72
+ start_date
73
73
  end
74
74
 
75
75
  #
@@ -78,9 +78,9 @@ module Zakuro
78
78
  # @return [Western::Calendar] 西暦終了日
79
79
  #
80
80
  def western_last_date
81
- return Western::Calendar.new if @gengou.invalid?
81
+ return Western::Calendar.new if gengou.invalid?
82
82
 
83
- @last_date
83
+ last_date
84
84
  end
85
85
 
86
86
  #
@@ -103,7 +103,7 @@ module Zakuro
103
103
  def name
104
104
  return '' unless @gengou
105
105
 
106
- @gengou.name
106
+ gengou.name
107
107
  end
108
108
 
109
109
  #
@@ -113,7 +113,7 @@ module Zakuro
113
113
  # @return [False] 不正なし
114
114
  #
115
115
  def invalid?
116
- @gengou.invalid? || @japan_year == INVALID_YEAR || @western_year == INVALID_YEAR
116
+ gengou.invalid? || japan_year == INVALID_YEAR || western_year == INVALID_YEAR
117
117
  end
118
118
 
119
119
  #
@@ -125,7 +125,7 @@ module Zakuro
125
125
  # @return [False] 含まれない
126
126
  #
127
127
  def include?
128
- @gengou.include?
128
+ gengou.include?
129
129
  end
130
130
 
131
131
  #
@@ -151,7 +151,7 @@ module Zakuro
151
151
  def change_start_date?
152
152
  return false if invalid?
153
153
 
154
- @start_date != native_start_date
154
+ start_date != native_start_date
155
155
  end
156
156
 
157
157
  #
@@ -163,7 +163,7 @@ module Zakuro
163
163
  def change_last_date?
164
164
  return false if invalid?
165
165
 
166
- @last_date != native_last_date
166
+ last_date != native_last_date
167
167
  end
168
168
 
169
169
  #
@@ -185,10 +185,10 @@ module Zakuro
185
185
  # 有効な日付範囲を選択する
186
186
  #
187
187
  def select_valid_date
188
- return if @gengou.invalid?
188
+ return if gengou.invalid?
189
189
 
190
- @start_date = @gengou.both_start_date.western.clone if @start_date.invalid?
191
- @last_date = @gengou.last_date.clone if @last_date.invalid?
190
+ @start_date = gengou.both_start_date.western.clone if start_date.invalid?
191
+ @last_date = gengou.last_date.clone if last_date.invalid?
192
192
  end
193
193
 
194
194
  #
@@ -197,7 +197,7 @@ module Zakuro
197
197
  # @return [Western::Calendar]設定された元号の開始日
198
198
  #
199
199
  def native_start_date
200
- @gengou.both_start_date.western
200
+ gengou.both_start_date.western
201
201
  end
202
202
 
203
203
  #
@@ -206,7 +206,7 @@ module Zakuro
206
206
  # @return [Western::Calendar] 設定された元号の終了日
207
207
  #
208
208
  def native_last_date
209
- @gengou.last_date
209
+ gengou.last_date
210
210
  end
211
211
  end
212
212
  end
@@ -14,89 +14,91 @@ module Zakuro
14
14
  # 元号発行
15
15
  #
16
16
  module Publisher
17
- #
18
- # 発行する
19
- #
20
- # @param [Western::Calendar] start_date 西暦開始日
21
- # @param [Western::Calendar] last_date 西暦終了日
22
- # @param [Array<Counter>] first_gengou 1行目元号
23
- # @param [Array<Counter>] second_gengou 2行目元号
24
- #
25
- # @return [Base::Gengou] 元号
26
- #
27
- def self.run(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
28
- first_gengou: [], second_gengou: [])
17
+ class << self
18
+ #
19
+ # 発行する
20
+ #
21
+ # @param [Western::Calendar] start_date 西暦開始日
22
+ # @param [Western::Calendar] last_date 西暦終了日
23
+ # @param [Array<Counter>] first_gengou 1行目元号
24
+ # @param [Array<Counter>] second_gengou 2行目元号
25
+ #
26
+ # @return [Base::Gengou] 元号
27
+ #
28
+ def run(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
29
+ first_gengou: [], second_gengou: [])
29
30
 
30
- Base::Gengou.new(
31
- start_date: start_date,
32
- last_date: last_date,
33
- first_line: to_linear_gengou(
34
- start_date: start_date, last_date: last_date, gengou_list: first_gengou
35
- ),
36
- second_line: to_linear_gengou(
37
- start_date: start_date, last_date: last_date, gengou_list: second_gengou
31
+ Base::Gengou.new(
32
+ start_date: start_date,
33
+ last_date: last_date,
34
+ first_line: to_linear_gengou(
35
+ start_date: start_date, last_date: last_date, gengou_list: first_gengou
36
+ ),
37
+ second_line: to_linear_gengou(
38
+ start_date: start_date, last_date: last_date, gengou_list: second_gengou
39
+ )
38
40
  )
39
- )
40
- end
41
+ end
42
+
43
+ #
44
+ # 直列元号に変換する
45
+ #
46
+ # * 最初の元号:開始日~その元号の終了日
47
+ # * 中間の元号:その元号の開始日~その元号の終了日
48
+ # * 最後の元号:その元号の開始日~終了日
49
+ #
50
+ # @param [Western::Calendar] start_date 西暦開始日
51
+ # @param [Western::Calendar] last_date 西暦終了日
52
+ # @param [Array<Counter>] gengou_list 元号リスト
53
+ #
54
+ # @return [Array<Base::LinearGengou>] 元号リスト
55
+ #
56
+ def to_linear_gengou(start_date:, last_date:, gengou_list: [])
57
+ return [] if gengou_list.size.zero?
41
58
 
42
- #
43
- # 直列元号に変換する
44
- #
45
- # * 最初の元号:開始日~その元号の終了日
46
- # * 中間の元号:その元号の開始日~その元号の終了日
47
- # * 最後の元号:その元号の開始日~終了日
48
- #
49
- # @param [Western::Calendar] start_date 西暦開始日
50
- # @param [Western::Calendar] last_date 西暦終了日
51
- # @param [Array<Counter>] gengou_list 元号リスト
52
- #
53
- # @return [Array<Base::LinearGengou>] 元号リスト
54
- #
55
- def self.to_linear_gengou(start_date:, last_date:, gengou_list: [])
56
- return [] if gengou_list.size.zero?
59
+ result = []
57
60
 
58
- result = []
61
+ gengou_list.each do |gengou|
62
+ if gengou.invalid?
63
+ # 無効元号は無効のままにする
64
+ result.push(Base::LinearGengou.new)
65
+ next
66
+ end
59
67
 
60
- gengou_list.each do |gengou|
61
- if gengou.invalid?
62
- # 無効元号は無効のままにする
63
- result.push(Base::LinearGengou.new)
64
- next
68
+ linear_gengou = to_limited_linear_gengou(
69
+ start_date: start_date,
70
+ last_date: last_date,
71
+ gengou: gengou
72
+ )
73
+ result.push(linear_gengou)
65
74
  end
66
75
 
67
- linear_gengou = to_limited_linear_gengou(
68
- start_date: start_date,
69
- last_date: last_date,
70
- gengou: gengou
71
- )
72
- result.push(linear_gengou)
76
+ result
73
77
  end
74
78
 
75
- result
76
- end
77
-
78
- #
79
- # 範囲を限定した直列元号に変換する
80
- #
81
- # * 開始日・終了日により範囲を狭める
82
- #
83
- # @param [Western::Calendar] start_date 西暦開始日
84
- # @param [Western::Calendar] last_date 西暦終了日
85
- # @param [Counter] gengou 加算元号
86
- #
87
- # @return [Base::LinearGengou] 元号
88
- #
89
- def self.to_limited_linear_gengou(start_date:, last_date:, gengou:)
90
- gengou_start_date = gengou.western_start_date.clone
91
- gengou_last_date = gengou.western_last_date.clone
79
+ #
80
+ # 範囲を限定した直列元号に変換する
81
+ #
82
+ # * 開始日・終了日により範囲を狭める
83
+ #
84
+ # @param [Western::Calendar] start_date 西暦開始日
85
+ # @param [Western::Calendar] last_date 西暦終了日
86
+ # @param [Counter] gengou 加算元号
87
+ #
88
+ # @return [Base::LinearGengou] 元号
89
+ #
90
+ def to_limited_linear_gengou(start_date:, last_date:, gengou:)
91
+ gengou_start_date = gengou.western_start_date.clone
92
+ gengou_last_date = gengou.western_last_date.clone
92
93
 
93
- gengou_start_date = start_date.clone if start_date > gengou_start_date
94
- gengou_last_date = last_date.clone if last_date < gengou_last_date
94
+ gengou_start_date = start_date.clone if start_date > gengou_start_date
95
+ gengou_last_date = last_date.clone if last_date < gengou_last_date
95
96
 
96
- Base::LinearGengou.new(
97
- start_date: gengou_start_date, last_date: gengou_last_date,
98
- name: gengou.name, year: gengou.japan_year
99
- )
97
+ Base::LinearGengou.new(
98
+ start_date: gengou_start_date, last_date: gengou_last_date,
99
+ name: gengou.name, year: gengou.japan_year
100
+ )
101
+ end
100
102
  end
101
103
  end
102
104
  end
@@ -7,6 +7,8 @@ require_relative '../../../../../era/western/calendar'
7
7
 
8
8
  require_relative '../counter'
9
9
 
10
+ require_relative './empty_link'
11
+
10
12
  # :nodoc:
11
13
  module Zakuro
12
14
  # :nodoc:
@@ -15,11 +17,11 @@ module Zakuro
15
17
  module Gengou
16
18
  # :nodoc:
17
19
  module Reserve
18
- # List
20
+ # AbstractList
19
21
  #
20
- # 予約元号一覧
22
+ # 抽象予約元号一覧
21
23
  #
22
- class List
24
+ class AbstractList
23
25
  # @return [Integer] 不正年
24
26
  INVALID_YEAR = -1
25
27
  # @return [Integer] 最大月日数
@@ -37,15 +39,15 @@ module Zakuro
37
39
  #
38
40
  # 初期化
39
41
  #
40
- # @param [True, False] first true:1行目元号, false:2行目元号
42
+ # @param [Integer] index n行目元号
41
43
  # @param [Western::Calendar] start_date 開始日
42
44
  # @param [Western::Calendar] last_date 終了日
43
45
  #
44
- def initialize(first: true, start_date: Western::Calendar.new,
46
+ def initialize(index:, start_date: Western::Calendar.new,
45
47
  last_date: Western::Calendar)
46
- @index = first ? Japan::Gengou::FIRST_LINE : Japan::Gengou::SECOND_LINE
48
+ @index = index
47
49
  @start_date = start_date.clone
48
- @last_date = last_date.invalid? ? start_date.clone : last_date.clone
50
+ @last_date = last_date.clone
49
51
  @list = []
50
52
 
51
53
  update
@@ -59,7 +61,7 @@ module Zakuro
59
61
  # @return [Gengou::Counter] 加算元号
60
62
  #
61
63
  def get(western_date: Western::Calendar.new)
62
- @list.each do |linear_gengou|
64
+ list.each do |linear_gengou|
63
65
  next if linear_gengou.out?(start_date: western_date, last_date: western_date)
64
66
 
65
67
  Gengou::Counter.new(gengou: linear_gengou.gengou).clone
@@ -79,7 +81,7 @@ module Zakuro
79
81
  def collect(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
80
82
  result = []
81
83
 
82
- @list.each do |linear_gengou|
84
+ list.each do |linear_gengou|
83
85
  next if linear_gengou.out?(start_date: start_date, last_date: last_date)
84
86
 
85
87
  result.push(
@@ -91,41 +93,7 @@ module Zakuro
91
93
  )
92
94
  end
93
95
 
94
- # TODO: refactor
95
- if result.size.zero?
96
- result.push(
97
- Gengou::Counter.new(
98
- gengou: Japan::Resource::Gengou.new(
99
- both_start_date: Japan::Resource::Both::Date.new(
100
- western: start_date.clone
101
- ),
102
- last_date: last_date.clone
103
- )
104
- )
105
- )
106
- return result
107
- end
108
-
109
- # FIXME: 有効元号の前後しか見ていない
110
- if start_date < result[0].start_date
111
- result.unshift(
112
- Gengou::Counter.new(
113
- gengou: Japan::Resource::Gengou.new,
114
- start_date: start_date.clone,
115
- last_date: result[0].start_date.clone - 1
116
- )
117
- )
118
- end
119
-
120
- if last_date > result[-1].last_date
121
- result.push(
122
- Gengou::Counter.new(
123
- gengou: Japan::Resource::Gengou.new,
124
- start_date: result[0].last_date.clone + 1,
125
- last_date: last_date.clone
126
- )
127
- )
128
- end
96
+ EmptyLink.fill(counters: result, start_date: start_date, last_date: last_date)
129
97
 
130
98
  result
131
99
  end
@@ -138,7 +106,7 @@ module Zakuro
138
106
  def japan_start_date
139
107
  return Japan::Calendar.new if invalid?
140
108
 
141
- @list[0].gengou.both_start_date.japan.clone
109
+ list[0].gengou.both_start_date.japan.clone
142
110
  end
143
111
 
144
112
  #
@@ -149,7 +117,18 @@ module Zakuro
149
117
  def western_start_date
150
118
  return Western::Calendar.new if invalid?
151
119
 
152
- @list[0].gengou.both_start_date.western.clone
120
+ list[0].gengou.both_start_date.western.clone
121
+ end
122
+
123
+ #
124
+ # 西暦終了日を取得する
125
+ #
126
+ # @return [Western::Calendar] 西暦開始日
127
+ #
128
+ def western_last_date
129
+ return Western::Calendar.new if invalid?
130
+
131
+ list[-1].gengou.last_date.clone
153
132
  end
154
133
 
155
134
  #
@@ -160,7 +139,7 @@ module Zakuro
160
139
  def western_start_year
161
140
  return INVALID_YEAR if invalid?
162
141
 
163
- @list[0].gengou.both_start_year.western.clone
142
+ list[0].gengou.both_start_year.western.clone
164
143
  end
165
144
 
166
145
  #
@@ -171,9 +150,9 @@ module Zakuro
171
150
  def western_last_year
172
151
  return INVALID_YEAR if invalid?
173
152
 
174
- return INVALID_YEAR if @list.size.zero?
153
+ return INVALID_YEAR if list.size.zero?
175
154
 
176
- @list[-1].gengou.last_year
155
+ list[-1].gengou.last_year
177
156
  end
178
157
 
179
158
  #
@@ -183,9 +162,9 @@ module Zakuro
183
162
  # @return [False] 不正なし
184
163
  #
185
164
  def invalid?
186
- return true unless @list
165
+ return true unless list
187
166
 
188
- return true if @list.size.zero?
167
+ return true if list.size.zero?
189
168
 
190
169
  false
191
170
  end
@@ -196,9 +175,9 @@ module Zakuro
196
175
  # @return [Western::Calendar]設定された元号の開始日
197
176
  #
198
177
  def native_start_date
199
- return Western::Calendar.new if @list.size.zero?
178
+ return Western::Calendar.new if list.size.zero?
200
179
 
201
- @list[0].native_start_date
180
+ list[0].native_start_date
202
181
  end
203
182
 
204
183
  #
@@ -208,9 +187,9 @@ module Zakuro
208
187
  # @return [False] 同一
209
188
  #
210
189
  def change_start_date?
211
- return false if @list.size.zero?
190
+ return false if list.size.zero?
212
191
 
213
- @list[0].change_start_date?
192
+ list[0].change_start_date?
214
193
  end
215
194
 
216
195
  private
@@ -219,23 +198,30 @@ module Zakuro
219
198
  # 予約元号一覧を更新する
220
199
  #
221
200
  def update
222
- # 開始日の30日前に前の元号がある場合は、前の元号を設定する
223
- start_date = @start_date.clone - (MAX_MONTH_DAYS + 1)
224
- # 開始日の30日後に次の元号がある場合は、次の元号を設定する
225
- last_date = @last_date.clone + (MAX_MONTH_DAYS + 1)
226
-
227
- @list |= line(start_date: start_date, last_date: last_date)
201
+ # override
228
202
  end
229
203
 
230
204
  #
231
- # 元号
205
+ # 元号を取得する
232
206
  #
233
- # @param [Western::Calendar] date 日付
207
+ # @param [Western::Calendar] start_date 開始日
208
+ # @param [Western::Calendar] last_date 終了日
234
209
  #
235
210
  # @return [Array<Japan::Alignment::LinearGengou>] 元号
236
211
  #
237
212
  def line(start_date:, last_date:)
238
- Japan::Gengou.line(line: @index, start_date: start_date, last_date: last_date)
213
+ Japan::Gengou.line(line: index, start_date: start_date, last_date: last_date)
214
+ end
215
+
216
+ #
217
+ # 行番号に変換する
218
+ #
219
+ # @param [True, False] first 1行目/2行目
220
+ #
221
+ # @return [<Integer] 行番号
222
+ #
223
+ def parse_index(first: true)
224
+ first ? Japan::Gengou::FIRST_LINE : Japan::Gengou::SECOND_LINE
239
225
  end
240
226
  end
241
227
  end