zakuro 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/VERSION +1 -1
  4. data/lib/zakuro/calculation/base/gengou.rb +5 -5
  5. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  6. data/lib/zakuro/calculation/base/operated_year.rb +23 -21
  7. data/lib/zakuro/calculation/base/year.rb +3 -3
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
  9. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  10. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  11. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
  12. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  13. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
  22. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  23. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  24. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  25. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  26. data/lib/zakuro/calculation/monthly/initialized_month.rb +39 -37
  27. data/lib/zakuro/calculation/monthly/month.rb +15 -15
  28. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  29. data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
  30. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  31. data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
  32. data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
  33. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  34. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  35. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  36. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  37. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  38. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  39. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  40. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +5 -5
  41. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  42. data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
  43. data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
  44. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  45. data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
  46. data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
  47. data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
  48. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
  49. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  50. data/lib/zakuro/calculation/summary/western/range.rb +95 -92
  51. data/lib/zakuro/calculation/summary/western/single.rb +78 -76
  52. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -124
  53. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
  54. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  55. data/lib/zakuro/condition.rb +121 -111
  56. data/lib/zakuro/context/context.rb +1 -1
  57. data/lib/zakuro/context/option.rb +31 -29
  58. data/lib/zakuro/context/version_class_resolver.rb +26 -24
  59. data/lib/zakuro/era/japan/calendar.rb +35 -33
  60. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -4
  61. data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
  62. data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
  63. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
  64. data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
  65. data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -36
  66. data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -37
  67. data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
  68. data/lib/zakuro/era/japan/gengou.rb +28 -26
  69. data/lib/zakuro/era/japan/version.rb +18 -16
  70. data/lib/zakuro/era/western/calendar.rb +102 -90
  71. data/lib/zakuro/exception/case/preset.rb +2 -2
  72. data/lib/zakuro/exception/exception.rb +15 -13
  73. data/lib/zakuro/exception/zakuro_error.rb +1 -1
  74. data/lib/zakuro/gateway/locale/date.rb +2 -2
  75. data/lib/zakuro/gateway/locale/range.rb +3 -3
  76. data/lib/zakuro/gateway/range.rb +1 -1
  77. data/lib/zakuro/gateway/single.rb +13 -2
  78. data/lib/zakuro/merchant.rb +1 -1
  79. data/lib/zakuro/operation/month/parser.rb +252 -251
  80. data/lib/zakuro/operation/month/type.rb +17 -8
  81. data/lib/zakuro/operation/month/validator.rb +148 -144
  82. data/lib/zakuro/operation/operation.rb +38 -36
  83. data/lib/zakuro/output/response.rb +112 -113
  84. data/lib/zakuro/result/operation/month/annotation.rb +2 -2
  85. data/lib/zakuro/result/operation/month/history.rb +2 -2
  86. data/lib/zakuro/result/operation/month.rb +31 -0
  87. data/lib/zakuro/result/operation.rb +39 -0
  88. data/lib/zakuro/result/result.rb +3 -3
  89. data/lib/zakuro/tools/stringifier.rb +66 -64
  90. data/lib/zakuro/tools/typeconv.rb +17 -15
  91. data/lib/zakuro/tools/typeof.rb +15 -13
  92. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  93. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  94. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
  95. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  96. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
  97. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  98. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  99. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  100. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  101. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  102. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  103. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  104. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  105. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  106. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  107. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  108. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  109. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  110. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  111. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
  112. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  113. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
  114. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  115. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  116. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  117. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  118. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  119. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  120. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  121. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  122. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  123. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
  124. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  125. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
  126. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  127. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  128. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  129. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  130. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  131. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  132. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  133. metadata +12 -9
  134. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
  135. data/lib/zakuro/result/operation/bundle.rb +0 -44
  136. data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -43,25 +43,13 @@ module Zakuro
43
43
  # @param [Western::Calendar] last_date 西暦終了日
44
44
  #
45
45
  def renew(last_date: Western::Calendar.new)
46
- native_start_date = Western::Calendar.new
47
- [@first_list, @second_list].each do |list|
48
- next unless list.change_start_date?
49
-
50
- if native_start_date.invalid?
51
- native_start_date = list.native_start_date.clone
52
- next
53
- end
54
-
55
- next if native_start_date <= list.native_start_date
56
-
57
- native_start_date = list.native_start_date.clone
58
- end
46
+ start_date = native_start_date
59
47
 
60
- return if native_start_date.invalid?
48
+ return if start_date.invalid?
61
49
 
62
- @first_list = DatedList.new(first: true, start_date: native_start_date,
50
+ @first_list = DatedList.new(first: true, start_date: start_date,
63
51
  last_date: last_date)
64
- @second_list = DatedList.new(first: false, start_date: native_start_date,
52
+ @second_list = DatedList.new(first: false, start_date: start_date,
65
53
  last_date: last_date)
66
54
  end
67
55
 
@@ -72,7 +60,7 @@ module Zakuro
72
60
  # @return [False] 不正なし
73
61
  #
74
62
  def invalid?
75
- @first_list.invalid?
63
+ first_list.invalid?
76
64
  end
77
65
 
78
66
  #
@@ -85,7 +73,7 @@ module Zakuro
85
73
  #
86
74
  def collect_first(start_date: Western::Calendar.new,
87
75
  last_date: Western::Calendar.new)
88
- @first_list.collect(start_date: start_date, last_date: last_date)
76
+ first_list.collect(start_date: start_date, last_date: last_date)
89
77
  end
90
78
 
91
79
  #
@@ -98,7 +86,7 @@ module Zakuro
98
86
  #
99
87
  def collect_second(start_date: Western::Calendar.new,
100
88
  last_date: Western::Calendar.new)
101
- @second_list.collect(start_date: start_date, last_date: last_date)
89
+ second_list.collect(start_date: start_date, last_date: last_date)
102
90
  end
103
91
 
104
92
  #
@@ -133,12 +121,12 @@ module Zakuro
133
121
  # @return [Integer] 開始西暦年
134
122
  #
135
123
  def western_start_year
136
- first_start_year = @first_list.western_start_year
137
- second_start_year = @second_list.western_start_year
124
+ first_start_year = first_list.western_start_year
125
+ second_start_year = second_list.western_start_year
138
126
 
139
- return first_start_year if @first_list.invalid?
127
+ return first_start_year if first_list.invalid?
140
128
 
141
- return first_start_year if @second_list.invalid?
129
+ return first_start_year if second_list.invalid?
142
130
 
143
131
  return first_start_year if first_start_year < second_start_year
144
132
 
@@ -151,12 +139,12 @@ module Zakuro
151
139
  # @return [Integer] 終了西暦年
152
140
  #
153
141
  def western_last_year
154
- first_last_year = @first_list.western_last_year
155
- second_last_year = @second_list.western_last_year
142
+ first_last_year = first_list.western_last_year
143
+ second_last_year = second_list.western_last_year
156
144
 
157
- return first_last_year if @first_list.invalid?
145
+ return first_last_year if first_list.invalid?
158
146
 
159
- return first_last_year if @second_list.invalid?
147
+ return first_last_year if second_list.invalid?
160
148
 
161
149
  return first_last_year if first_last_year > second_last_year
162
150
 
@@ -165,26 +153,61 @@ module Zakuro
165
153
 
166
154
  private
167
155
 
156
+ #
157
+ # 設定された元号の開始日を取得する
158
+ #
159
+ # @return [Western::Calendar] 設定された元号の開始日
160
+ #
161
+ def native_start_date
162
+ result = Western::Calendar.new
163
+ [first_list, second_list].each do |list|
164
+ next unless list.change_start_date?
165
+
166
+ if result.invalid?
167
+ result = list.native_start_date.clone
168
+ next
169
+ end
170
+
171
+ next if result <= list.native_start_date
172
+
173
+ result = list.native_start_date.clone
174
+ end
175
+
176
+ result
177
+ end
178
+
168
179
  #
169
180
  # 最古の元号を取得する
170
181
  #
171
182
  # @return [List] 最古の元号
172
183
  #
173
184
  def oldest_list
174
- return @first_list if @first_list.invalid?
185
+ return first_list if invalid_list?
186
+
187
+ first_western_date = first_list.western_start_date
188
+ second_western_date = second_list.western_start_date
175
189
 
176
- return @first_list if @second_list.invalid?
190
+ return first_list if first_western_date.invalid?
177
191
 
178
- first_western_date = @first_list.western_start_date
179
- second_western_date = @second_list.western_start_date
192
+ return first_list if second_western_date.invalid?
180
193
 
181
- return @first_list if first_western_date.invalid?
194
+ return first_list if first_western_date < second_western_date
182
195
 
183
- return @first_list if second_western_date.invalid?
196
+ second_list
197
+ end
198
+
199
+ #
200
+ # 元号リストが不正か
201
+ #
202
+ # @return [True] 不正
203
+ # @return [False] 不正なし
204
+ #
205
+ def invalid_list?
206
+ return true if first_list.invalid?
184
207
 
185
- return @first_list if first_western_date < second_western_date
208
+ return true if second_list.invalid?
186
209
 
187
- @second_list
210
+ false
188
211
  end
189
212
  end
190
213
  end
@@ -35,11 +35,11 @@ module Zakuro
35
35
  #
36
36
  def update
37
37
  # 開始日の30日前に前の元号がある場合は、前の元号を設定する
38
- start_date = @start_date.clone - (MAX_MONTH_DAYS + 1)
38
+ start = start_date.clone - (MAX_MONTH_DAYS + 1)
39
39
  # 開始日の30日後に次の元号がある場合は、次の元号を設定する
40
- last_date = @last_date.clone + (MAX_MONTH_DAYS + 1)
40
+ last = last_date.clone + (MAX_MONTH_DAYS + 1)
41
41
 
42
- @list |= line(start_date: start_date, last_date: last_date)
42
+ @list |= line(start_date: start, last_date: last)
43
43
  end
44
44
  end
45
45
  end
@@ -23,134 +23,132 @@ module Zakuro
23
23
  # * もし元号が存在しない期間があれば、空の元号を生成する
24
24
  #
25
25
  module EmptyLink
26
- #
27
- # 空元号で満たす
28
- #
29
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
30
- # @param [Western::Calendar] start_date 開始日
31
- # @param [Western::Calendar] last_date 終了日
32
- #
33
- def self.fill(counters:, start_date: Western::Calendar.new,
34
- last_date: Western::Calendar.new)
35
- if counters.size.zero?
36
- counters.push(
26
+ class << self
27
+ #
28
+ # 空元号で満たす
29
+ #
30
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] last_date 終了日
33
+ #
34
+ def fill(counters:, start_date: Western::Calendar.new,
35
+ last_date: Western::Calendar.new)
36
+ if counters.size.zero?
37
+ counters.push(
38
+ create_empty_counter(
39
+ start_date: start_date.clone,
40
+ last_date: last_date.clone
41
+ )
42
+ )
43
+ return counters
44
+ end
45
+
46
+ fill_both_ends(counters: counters, start_date: start_date, last_date: last_date)
47
+
48
+ fill_middle(counters: counters)
49
+ end
50
+
51
+ private
52
+
53
+ #
54
+ # リストの両端を空元号で満たす
55
+ #
56
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
57
+ # @param [Western::Calendar] start_date 開始日
58
+ # @param [Western::Calendar] last_date 終了日
59
+ #
60
+ def fill_both_ends(counters:, start_date: Western::Calendar.new,
61
+ last_date: Western::Calendar.new)
62
+ fill_by_start(counters: counters, start_date: start_date)
63
+
64
+ fill_by_last(counters: counters, last_date: last_date)
65
+ end
66
+
67
+ #
68
+ # 先頭要素の手前を空元号で満たす
69
+ #
70
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
71
+ # @param [Western::Calendar] start_date 開始日
72
+ #
73
+ def fill_by_start(counters:, start_date:)
74
+ return unless start_date < counters[0].start_date
75
+
76
+ counters.unshift(
37
77
  create_empty_counter(
38
78
  start_date: start_date.clone,
79
+ last_date: counters[0].start_date.clone - 1
80
+ )
81
+ )
82
+ end
83
+
84
+ #
85
+ # 最終要素の手前を空元号で満たす
86
+ #
87
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
88
+ # @param [Western::Calendar] last_date 終了日
89
+ #
90
+ def fill_by_last(counters:, last_date:)
91
+ return unless last_date > counters[-1].last_date
92
+
93
+ counters.push(
94
+ create_empty_counter(
95
+ start_date: counters[-1].last_date.clone + 1,
39
96
  last_date: last_date.clone
40
97
  )
41
98
  )
42
- return counters
43
99
  end
44
100
 
45
- fill_both_ends(counters: counters, start_date: start_date, last_date: last_date)
101
+ #
102
+ # 元号間を空元号で満たす
103
+ #
104
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
105
+ #
106
+ def fill_middle(counters:)
107
+ return if counters.size.zero?
46
108
 
47
- fill_middle(counters: counters)
48
- end
109
+ size = counters.size - 1
110
+ (0..size).reverse_each do |index|
111
+ break if index <= 0
49
112
 
50
- #
51
- # リストの両端を空元号で満たす
52
- #
53
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
54
- # @param [Western::Calendar] start_date 開始日
55
- # @param [Western::Calendar] last_date 終了日
56
- #
57
- def self.fill_both_ends(counters:, start_date: Western::Calendar.new,
58
- last_date: Western::Calendar.new)
59
- fill_by_start(counters: counters, start_date: start_date)
60
-
61
- fill_by_last(counters: counters, last_date: last_date)
62
- end
63
- private_class_method :fill_both_ends
64
-
65
- #
66
- # 先頭要素の手前を空元号で満たす
67
- #
68
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
69
- # @param [Western::Calendar] start_date 開始日
70
- #
71
- def self.fill_by_start(counters:, start_date:)
72
- return unless start_date < counters[0].start_date
73
-
74
- counters.unshift(
75
- create_empty_counter(
76
- start_date: start_date.clone,
77
- last_date: counters[0].start_date.clone - 1
78
- )
79
- )
80
- end
81
- private_class_method :fill_by_start
82
-
83
- #
84
- # 最終要素の手前を空元号で満たす
85
- #
86
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
87
- # @param [Western::Calendar] last_date 終了日
88
- #
89
- def self.fill_by_last(counters:, last_date:)
90
- return unless last_date > counters[-1].last_date
91
-
92
- counters.push(
93
- create_empty_counter(
94
- start_date: counters[-1].last_date.clone + 1,
95
- last_date: last_date.clone
96
- )
97
- )
98
- end
99
- private_class_method :fill_by_last
113
+ insert(counters: counters, index: index)
114
+ end
115
+ end
100
116
 
101
- #
102
- # 元号間を空元号で満たす
103
- #
104
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
105
- #
106
- def self.fill_middle(counters:)
107
- return if counters.size.zero?
117
+ #
118
+ # 対象要素に空元号を追加する
119
+ #
120
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
121
+ # @param [Integer] index 要素番号
122
+ #
123
+ def insert(counters:, index:)
124
+ before_last_date = counters[index - 1].last_date.clone
125
+ current_start_date = counters[index].start_date.clone
108
126
 
109
- size = counters.size - 1
110
- (0..size).reverse_each do |index|
111
- break if index <= 0
127
+ return if (before_last_date.clone + 1) == current_start_date
112
128
 
113
- insert(counters: counters, index: index)
129
+ counters.insert(
130
+ index,
131
+ create_empty_counter(
132
+ start_date: before_last_date + 1, last_date: current_start_date - 1
133
+ )
134
+ )
114
135
  end
115
- end
116
- private_class_method :fill_middle
117
-
118
- #
119
- # 対象要素に空元号を追加する
120
- #
121
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
122
- # @param [Integer] index 要素番号
123
- #
124
- def self.insert(counters:, index:)
125
- before_last_date = counters[index - 1].last_date.clone
126
- current_start_date = counters[index].start_date.clone
127
-
128
- return if (before_last_date.clone + 1) == current_start_date
129
-
130
- counters.insert(
131
- index,
132
- create_empty_counter(
133
- start_date: before_last_date + 1, last_date: current_start_date - 1
136
+
137
+ #
138
+ # 空元号を生成する
139
+ #
140
+ # @param [Western::Calendar] start_date 西暦開始日
141
+ # @param [Western::Calendar] last_date 西暦終了日
142
+ #
143
+ # @return [Gengou::Counter] 加算元号(空元号)
144
+ #
145
+ def create_empty_counter(start_date:, last_date:)
146
+ Gengou::Counter.new(
147
+ gengou: Japan::Gengou::Resource::Gengou.new,
148
+ start_date: start_date, last_date: last_date
134
149
  )
135
- )
136
- end
137
- private_class_method :insert
138
-
139
- #
140
- # 空元号を生成する
141
- #
142
- # @param [Western::Calendar] start_date 西暦開始日
143
- # @param [Western::Calendar] last_date 西暦終了日
144
- #
145
- # @return [Gengou::Counter] 加算元号(空元号)
146
- #
147
- def self.create_empty_counter(start_date:, last_date:)
148
- Gengou::Counter.new(
149
- gengou: Japan::Gengou::Resource::Gengou.new,
150
- start_date: start_date, last_date: last_date
151
- )
150
+ end
152
151
  end
153
- private_class_method :create_empty_counter
154
152
  end
155
153
  end
156
154
  end
@@ -31,7 +31,7 @@ module Zakuro
31
31
  @last_date = Western::Calendar.new
32
32
 
33
33
  locate(start_name: start_name, last_name: last_name)
34
- super(index: @index, start_date: @start_date, last_date: @last_date)
34
+ super(index: index, start_date: start_date, last_date: last_date)
35
35
  end
36
36
 
37
37
  private
@@ -71,12 +71,12 @@ module Zakuro
71
71
  def choise_start_date(date:)
72
72
  return if date.invalid?
73
73
 
74
- if @start_date.invalid?
74
+ if start_date.invalid?
75
75
  @start_date = date
76
76
  return
77
77
  end
78
78
 
79
- return if date > @start_date
79
+ return if date > start_date
80
80
 
81
81
  @start_date = date
82
82
  end
@@ -89,12 +89,12 @@ module Zakuro
89
89
  def choise_last_date(date:)
90
90
  return if date.invalid?
91
91
 
92
- if @last_date.invalid?
92
+ if last_date.invalid?
93
93
  @last_date = date
94
94
  return
95
95
  end
96
96
 
97
- return if date < @last_date
97
+ return if date < last_date
98
98
 
99
99
  @last_date = date
100
100
  end
@@ -107,7 +107,7 @@ module Zakuro
107
107
  # @return [Array<Japan::Alignment::LinearGengou>] 元号
108
108
  #
109
109
  def line_by_name(name:)
110
- Japan::Gengou.line_by_name(line: @index, name: name)
110
+ Japan::Gengou.line_by_name(line: index, name: name)
111
111
  end
112
112
 
113
113
  #
@@ -53,20 +53,18 @@ module Zakuro
53
53
  # @return [List] 最新の元号
54
54
  #
55
55
  def newest_list
56
- return @first_list if @first_list.invalid?
56
+ return first_list if invalid_list?
57
57
 
58
- return @first_list if @second_list.invalid?
58
+ first_western_date = first_list.western_last_date
59
+ second_western_date = second_list.western_last_date
59
60
 
60
- first_western_date = @first_list.western_last_date
61
- second_western_date = @second_list.western_last_date
61
+ return first_list if first_western_date.invalid?
62
62
 
63
- return @first_list if first_western_date.invalid?
63
+ return first_list if second_western_date.invalid?
64
64
 
65
- return @first_list if second_western_date.invalid?
65
+ return first_list if first_western_date > second_western_date
66
66
 
67
- return @first_list if first_western_date > second_western_date
68
-
69
- @second_list
67
+ second_list
70
68
  end
71
69
  end
72
70
  end
@@ -14,26 +14,28 @@ module Zakuro
14
14
  # 元号に基づき計算範囲を予約する
15
15
  #
16
16
  module Reserve
17
- #
18
- # 予約結果を取得する
19
- #
20
- # * 開始日・終了日から計算する範囲を求める
21
- # * 開始日・終了日の範囲内にある元号全てが対象となる
22
- # * 元号に応じて計算範囲は変化する
23
- # * 元号の開始日(改元日)が開始日よりも前であれば、結果開始日は前者になる
24
- # * 元号の終了日(改元前日)が終了日よりも後であれば、結果終了日は前者になる
25
- # * 南北朝のように複数元号に属する場合、より広い範囲の元号に合わせる
26
- # * 属する元号よりもさらに範囲を広げる場合がある
27
- # * 開始日が最初の元号の改元後30日以内の場合、さらに前の元号まで対象にする
28
- # * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
29
- #
30
- # @param [Western::Calendar] start_date 開始日
31
- # @param [Western::Calendar] last_date 終了日
32
- #
33
- # @return [Range] 予約済み計算範囲
34
- #
35
- def self.get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
36
- DatedRange.new(start_date: start_date, last_date: last_date)
17
+ class << self
18
+ #
19
+ # 予約結果を取得する
20
+ #
21
+ # * 開始日・終了日から計算する範囲を求める
22
+ # * 開始日・終了日の範囲内にある元号全てが対象となる
23
+ # * 元号に応じて計算範囲は変化する
24
+ # * 元号の開始日(改元日)が開始日よりも前であれば、結果開始日は前者になる
25
+ # * 元号の終了日(改元前日)が終了日よりも後であれば、結果終了日は前者になる
26
+ # * 南北朝のように複数元号に属する場合、より広い範囲の元号に合わせる
27
+ # * 属する元号よりもさらに範囲を広げる場合がある
28
+ # * 開始日が最初の元号の改元後30日以内の場合、さらに前の元号まで対象にする
29
+ # * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
30
+ #
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] last_date 終了日
33
+ #
34
+ # @return [Range] 予約済み計算範囲
35
+ #
36
+ def get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
37
+ DatedRange.new(start_date: start_date, last_date: last_date)
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -13,37 +13,54 @@ module Zakuro
13
13
  # 暦検索
14
14
  #
15
15
  module Crawler
16
- #
17
- # 暦の範囲を取得する
18
- #
19
- # @param [Integer] start_year 開始西暦年
20
- # @param [Integer] last_year 終了西暦年
21
- #
22
- # @return [Array<Range>] 暦の範囲
23
- #
24
- def self.get(start_year:, last_year:)
25
- ranges = Japan::Version.ranges_with_year(start_year: start_year, last_year: last_year)
26
-
27
- result = []
28
-
29
- ranges.each do |range|
30
- next unless range.released
16
+ class << self
17
+ #
18
+ # 暦の範囲を取得する
19
+ #
20
+ # @param [Integer] start_year 開始西暦年
21
+ # @param [Integer] last_year 終了西暦年
22
+ #
23
+ # @return [Array<Range>] 暦の範囲
24
+ #
25
+ def get(start_year:, last_year:)
26
+ ranges = Japan::Version.ranges_with_year(start_year: start_year, last_year: last_year)
31
27
 
28
+ result = []
29
+
30
+ ranges.each do |range|
31
+ next unless range.released
32
+
33
+ narrowed_range = narrow(range: range, start_year: start_year, last_year: last_year)
34
+
35
+ result.push(narrowed_range)
36
+ end
37
+
38
+ result
39
+ end
40
+
41
+ private
42
+
43
+ #
44
+ # 範囲を開始年・終了年に合わせて狭める
45
+ #
46
+ # @param [Range] range 範囲
47
+ # @param [Integer] start_year 開始西暦年
48
+ # @param [Integer] last_year 終了西暦年
49
+ #
50
+ # @return [Range] 範囲
51
+ #
52
+ def narrow(range:, start_year:, last_year:)
32
53
  range_start_year = range.start_year
33
54
  range_start_year = start_year if start_year > range.start_year
34
55
 
35
56
  range_last_year = range.last_year
36
57
  range_last_year = last_year if last_year < range.last_year
37
58
 
38
- result.push(
39
- Range.new(
40
- name: range.name, start_date: range.start_date.clone,
41
- start_year: range_start_year, last_year: range_last_year
42
- )
59
+ Range.new(
60
+ name: range.name, start_date: range.start_date.clone,
61
+ start_year: range_start_year, last_year: range_last_year
43
62
  )
44
63
  end
45
-
46
- result
47
64
  end
48
65
  end
49
66
  end
@@ -8,16 +8,18 @@ module Zakuro
8
8
  module Calculation
9
9
  # :nodoc:
10
10
  module Version
11
- #
12
- # 暦の範囲を取得する
13
- #
14
- # @param [Integer] start_year 開始西暦年
15
- # @param [Integer] last_year 終了西暦年
16
- #
17
- # @return [Array<Range>] 暦の範囲
18
- #
19
- def self.get(start_year:, last_year:)
20
- Crawler.get(start_year: start_year, last_year: last_year)
11
+ class << self
12
+ #
13
+ # 暦の範囲を取得する
14
+ #
15
+ # @param [Integer] start_year 開始西暦年
16
+ # @param [Integer] last_year 終了西暦年
17
+ #
18
+ # @return [Array<Range>] 暦の範囲
19
+ #
20
+ def get(start_year:, last_year:)
21
+ Crawler.get(start_year: start_year, last_year: last_year)
22
+ end
21
23
  end
22
24
  end
23
25
  end