zakuro 0.4.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -3
  3. data/VERSION +1 -0
  4. data/doc/operation/csv/month.csv +21 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  7. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  8. data/lib/zakuro/calculation/base/operated_year.rb +5 -15
  9. data/lib/zakuro/calculation/base/year.rb +26 -14
  10. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +0 -13
  11. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/list.rb +244 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +42 -0
  17. data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -0
  18. data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
  19. data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
  20. data/lib/zakuro/calculation/era/version/version.rb +24 -0
  21. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  22. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  23. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  24. data/lib/zakuro/calculation/range/full_range.rb +68 -107
  25. data/lib/zakuro/calculation/range/operated_range.rb +13 -9
  26. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  27. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  28. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  29. data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
  30. data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
  31. data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
  32. data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
  33. data/lib/zakuro/calculation/summary/range.rb +120 -0
  34. data/lib/zakuro/calculation/summary/single.rb +45 -64
  35. data/lib/zakuro/condition.rb +14 -0
  36. data/lib/zakuro/era/japan/calendar.rb +133 -0
  37. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
  38. data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
  39. data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
  40. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
  41. data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
  42. data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
  43. data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
  44. data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
  45. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
  46. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
  47. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
  48. data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
  49. data/lib/zakuro/era/japan/gengou.rb +35 -74
  50. data/lib/zakuro/era/japan/version.rb +151 -0
  51. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  52. data/lib/zakuro/merchant.rb +50 -3
  53. data/lib/zakuro/operation/month/parser.rb +1 -1
  54. data/lib/zakuro/operation/month/type.rb +1 -1
  55. data/lib/zakuro/operation/month/validator.rb +2 -2
  56. data/lib/zakuro/operation/yaml/month.yaml +672 -0
  57. data/lib/zakuro/output/response.rb +5 -5
  58. data/lib/zakuro/result/result.rb +17 -0
  59. data/lib/zakuro/tools/typeconv.rb +38 -0
  60. data/lib/zakuro/tools/typeof.rb +4 -1
  61. data/lib/zakuro/version/context.rb +24 -3
  62. data/lib/zakuro/version/daien/cycle/remainder.rb +26 -0
  63. data/lib/zakuro/version/daien/daien.rb +1 -26
  64. data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
  65. data/lib/zakuro/version/genka/const/number.rb +43 -0
  66. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  67. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  68. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  69. data/lib/zakuro/version/genka/genka.rb +1 -9
  70. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  71. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  72. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  73. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  74. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  75. data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
  76. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  77. data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
  78. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  79. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  80. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  81. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  82. data/lib/zakuro/version/senmyou/README.md +11 -7
  83. data/lib/zakuro/version/senmyou/cycle/remainder.rb +26 -0
  84. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  85. data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
  86. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  87. data/lib/zakuro/version/version_class_resolver.rb +4 -0
  88. data/zakuro.gemspec +1 -3
  89. metadata +45 -16
  90. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  91. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  92. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  93. data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
  94. data/lib/zakuro/era/japan/gengou/type.rb +0 -178
  95. data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
  96. data/lib/zakuro/era/japan/reki.rb +0 -91
  97. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  98. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  99. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  100. data/lib/zakuro/version/abstract_version.rb +0 -29
  101. data/lib/zakuro/version.rb +0 -7
  102. data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,193 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../../era/western/calendar'
4
+
5
+ require_relative './list'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Calculation
11
+ # :nodoc:
12
+ module Gengou
13
+ # :nodoc:
14
+ module Reserve
15
+ #
16
+ # Range 予約済み計算範囲
17
+ #
18
+ class Range
19
+ # @return [List] 1行目元号
20
+ attr_reader :first_list
21
+ # @return [List] 2行目元号
22
+ attr_reader :second_list
23
+
24
+ #
25
+ # 初期化
26
+ #
27
+ # @param [Western::Calendar] start_date 西暦開始日
28
+ # @param [Western::Calendar] last_date 西暦終了日
29
+ #
30
+ def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
31
+ last_date = start_date.clone if last_date.invalid?
32
+
33
+ @first_list = List.new(first: true, start_date: start_date, last_date: last_date)
34
+ @second_list = List.new(first: false, start_date: start_date, last_date: last_date)
35
+
36
+ renew(last_date: last_date)
37
+ end
38
+
39
+ #
40
+ # 再初期化
41
+ # 含まれる最初の元号が別の行にまたがっている場合に開始日を前倒しする
42
+ #
43
+ # @param [Western::Calendar] last_date 西暦終了日
44
+ #
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
59
+
60
+ return if native_start_date.invalid?
61
+
62
+ @first_list = List.new(first: true,
63
+ start_date: native_start_date, last_date: last_date)
64
+ @second_list = List.new(first: false,
65
+ start_date: native_start_date, last_date: last_date)
66
+ end
67
+
68
+ #
69
+ # 不正か
70
+ #
71
+ # @return [True] 不正
72
+ # @return [False] 不正なし
73
+ #
74
+ def invalid?
75
+ @first_list.invalid?
76
+ end
77
+
78
+ #
79
+ # 範囲内元号(1行目元号)を取得する
80
+ #
81
+ # @param [Western::Calendar] start_date 西暦開始日
82
+ # @param [Western::Calendar] last_date 西暦終了日
83
+ #
84
+ # @return [Array<Gengou::Counter>] 範囲内元号(1行目元号)
85
+ #
86
+ def collect_first(start_date: Western::Calendar.new,
87
+ last_date: Western::Calendar.new)
88
+ @first_list.collect(start_date: start_date, last_date: last_date)
89
+ end
90
+
91
+ #
92
+ # 範囲内元号(2行目元号)を取得する
93
+ #
94
+ # @param [Western::Calendar] start_date 西暦開始日
95
+ # @param [Western::Calendar] last_date 西暦終了日
96
+ #
97
+ # @return [Array<Gengou::Counter>] 範囲内元号(2行目元号)
98
+ #
99
+ def collect_second(start_date: Western::Calendar.new,
100
+ last_date: Western::Calendar.new)
101
+ @second_list.collect(start_date: start_date, last_date: last_date)
102
+ end
103
+
104
+ #
105
+ # 最古の元号から和暦開始日を取得する
106
+ #
107
+ # @return [Japan::Calendar] 和暦開始日
108
+ #
109
+ def japan_start_date
110
+ gengou = oldest_gengou
111
+
112
+ return Japan::Calendar.new if gengou.invalid?
113
+
114
+ gengou.japan_start_date
115
+ end
116
+
117
+ #
118
+ # 最古の元号から西暦開始日を取得する
119
+ #
120
+ # @return [Western::Calendar] 西暦開始日
121
+ #
122
+ def western_start_date
123
+ gengou = oldest_gengou
124
+
125
+ return Western::Calendar.new if gengou.invalid?
126
+
127
+ gengou.western_start_date
128
+ end
129
+
130
+ #
131
+ # 開始西暦年を取得する
132
+ #
133
+ # @return [Integer] 開始西暦年
134
+ #
135
+ def western_start_year
136
+ first_start_year = @first_list.western_start_year
137
+ second_start_year = @second_list.western_start_year
138
+
139
+ return first_start_year if @first_list.invalid?
140
+
141
+ return first_start_year if @second_list.invalid?
142
+
143
+ return first_start_year if first_start_year < second_start_year
144
+
145
+ second_start_year
146
+ end
147
+
148
+ #
149
+ # 終了西暦年を取得する
150
+ #
151
+ # @return [Integer] 終了西暦年
152
+ #
153
+ def western_last_year
154
+ first_last_year = @first_list.western_last_year
155
+ second_last_year = @second_list.western_last_year
156
+
157
+ return first_last_year if @first_list.invalid?
158
+
159
+ return first_last_year if @second_list.invalid?
160
+
161
+ return first_last_year if first_last_year > second_last_year
162
+
163
+ second_last_year
164
+ end
165
+
166
+ private
167
+
168
+ #
169
+ # 最古の元号を取得する
170
+ #
171
+ # @return [Japan::Gengou] 最古の元号
172
+ #
173
+ def oldest_gengou
174
+ return @first_list if @first_list.invalid?
175
+
176
+ return @first_list if @second_list.invalid?
177
+
178
+ first_western_date = @first_list.western_start_date
179
+ second_western_date = @second_list.western_start_date
180
+
181
+ return @first_list if first_western_date.invalid?
182
+
183
+ return @first_list if second_western_date.invalid?
184
+
185
+ return @first_list if first_western_date < second_western_date
186
+
187
+ @second_list
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../era/western/calendar'
4
+ require_relative './reserve/range'
5
+ require_relative './reserve/list'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Calculation
11
+ # :nodoc:
12
+ module Gengou
13
+ # Reserve
14
+ #
15
+ # 元号に基づき計算範囲を予約する
16
+ #
17
+ module Reserve
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 self.get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
37
+ Range.new(start_date: start_date, last_date: last_date)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,211 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../era/western/calendar'
4
+ require_relative '../../base/gengou'
5
+ require_relative '../../base/linear_gengou'
6
+ require_relative './internal/reserve/range'
7
+ require_relative './internal/connector'
8
+ require_relative './internal/publisher'
9
+
10
+ # :nodoc:
11
+ module Zakuro
12
+ # :nodoc:
13
+ module Calculation
14
+ # :nodoc:
15
+ module Gengou
16
+ # Scroll
17
+ #
18
+ # 元号スクロール
19
+ #
20
+ class Scroll
21
+ # @return [Western::Calendar] 月初日
22
+ attr_reader :monthly_start_date
23
+ # @return [Western::Calendar] 月末日
24
+ attr_reader :monthly_last_date
25
+ # @return [Reserve::Range] 予約範囲
26
+ attr_reader :range
27
+ # @return [Array<Counte>] 1行目元号
28
+ attr_reader :first_gengou
29
+ # @return [Array<Counte>] 2行目元号
30
+ attr_reader :second_gengou
31
+ # @return [Connector] 行変更済元号
32
+ attr_reader :connector
33
+
34
+ #
35
+ # 初期化
36
+ #
37
+ # @param [Western::Calendar] start_date 西暦開始日(最大範囲)
38
+ # @param [Western::Calendar] last_date 西暦終了日(最大範囲)
39
+ #
40
+ def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
41
+ @monthly_start_date = Western::Calendar.new
42
+ @monthly_last_date = Western::Calendar.new
43
+ @range = Reserve::Range.new(start_date: start_date, last_date: last_date)
44
+ @first_gengou = []
45
+ @second_gengou = []
46
+ @ignited = false
47
+ @connector = Connector.new
48
+ end
49
+
50
+ #
51
+ # 進める
52
+ #
53
+ # @param [Monthly::Month] month 月
54
+ #
55
+ def run(month:)
56
+ unless @ignited
57
+ # 開始日の検索を行う
58
+ @ignited = ignite(month: month)
59
+ return
60
+ end
61
+
62
+ # 時間を進める
63
+ advance(month: month)
64
+ end
65
+
66
+ #
67
+ # 元号開始を試みる
68
+ #
69
+ # @param [Monthly::Month] month 月
70
+ #
71
+ # @return [True] 開始あり
72
+ # @return [False] 開始なし
73
+ #
74
+ def ignite(month:)
75
+ return false unless ignitable?(month: month)
76
+
77
+ japan_start_date = @range.japan_start_date
78
+
79
+ western_start_date = @range.western_start_date
80
+
81
+ # 今月初日(和暦日が1月2日であれば、開始日の1日前が初日)
82
+ @monthly_start_date = western_start_date.clone - japan_start_date.day + 1
83
+
84
+ # 今月末
85
+ @monthly_last_date = @monthly_start_date.clone + month.days - 1
86
+
87
+ update_current_gengou
88
+
89
+ true
90
+ end
91
+
92
+ #
93
+ # 進める
94
+ #
95
+ # @param [Monthly::Month] month 月
96
+ #
97
+ def advance(month:)
98
+ @monthly_start_date = @monthly_last_date.clone + 1
99
+
100
+ @monthly_last_date = @monthly_start_date.clone + month.days - 1
101
+
102
+ next_year if month.number == 1 && !month.leaped?
103
+
104
+ update_current_gengou
105
+ end
106
+
107
+ #
108
+ # 共通の元号に変換する
109
+ #
110
+ # @return [Base::Gengou] 元号
111
+ #
112
+ def to_gengou
113
+ start_date = @monthly_start_date.clone
114
+ last_date = @monthly_last_date.clone
115
+
116
+ # 行を超えた元号切り替え処理
117
+ continue_year
118
+
119
+ Publisher.run(
120
+ start_date: start_date, last_date: last_date,
121
+ first_gengou: @first_gengou, second_gengou: @second_gengou
122
+ )
123
+ end
124
+
125
+ #
126
+ # 開始西暦年を取得する
127
+ #
128
+ # @return [Integer] 開始西暦年
129
+ #
130
+ def western_start_year
131
+ @range.western_start_year
132
+ end
133
+
134
+ #
135
+ # 終了西暦年を取得する
136
+ #
137
+ # @return [Integer] 終了西暦年
138
+ #
139
+ def western_last_year
140
+ @range.western_last_year
141
+ end
142
+
143
+ private
144
+
145
+ #
146
+ # 行を跨ぐ元号年を継続させる
147
+ #
148
+ def continue_year
149
+ @connector.update(lines: [@first_gengou, @second_gengou])
150
+ end
151
+
152
+ #
153
+ # 現在月に合わせて元号を更新する
154
+ #
155
+ def update_current_gengou
156
+ start_date = @monthly_start_date
157
+ last_date = @monthly_last_date
158
+ first_gengou = @range.collect_first(start_date: start_date, last_date: last_date)
159
+ second_gengou = @range.collect_second(start_date: start_date,
160
+ last_date: last_date)
161
+
162
+ @first_gengou = replace_gengou(source: @first_gengou, destination: first_gengou)
163
+ @second_gengou = replace_gengou(source: @second_gengou, destination: second_gengou)
164
+ end
165
+
166
+ #
167
+ # 元号を差し替える
168
+ #
169
+ # @param [Array<Counter>] source 元の元号
170
+ # @param [Array<Counter>] destination 次の元号
171
+ #
172
+ # @return [Array<Counter>] 差し替え結果
173
+ #
174
+ def replace_gengou(source: [], destination: [])
175
+ return destination if destination.size.zero?
176
+
177
+ return destination if source.size.zero?
178
+
179
+ last = source[-1]
180
+ destination[0] = last if destination[0].name == last.name
181
+
182
+ destination
183
+ end
184
+
185
+ #
186
+ # 開始可能か
187
+ #
188
+ # @param [Monthly::Month] month 月
189
+ #
190
+ # @return [True] 開始可
191
+ # @return [True] 開始不可
192
+ #
193
+ def ignitable?(month:)
194
+ return false unless @monthly_start_date.invalid?
195
+
196
+ japan_start_date = @range.japan_start_date
197
+
198
+ japan_start_date.same_month?(leaped: month.leaped?, month: month.number)
199
+ end
200
+
201
+ #
202
+ # 次年にする
203
+ #
204
+ def next_year
205
+ @first_gengou.each(&:next_year)
206
+ @second_gengou.each(&:next_year)
207
+ end
208
+ end
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../era/japan/version'
4
+ require_relative './range'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Version
12
+ #
13
+ # 暦検索
14
+ #
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
31
+
32
+ range_start_year = range.start_year
33
+ range_start_year = start_year if start_year > range.start_year
34
+
35
+ range_last_year = range.last_year
36
+ range_last_year = last_year if last_year < range.last_year
37
+
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
+ )
43
+ )
44
+ end
45
+
46
+ result
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Version
9
+ #
10
+ # Range 暦(範囲)
11
+ #
12
+ class Range
13
+ # @return [String] 暦名
14
+ attr_reader :name
15
+ # @return [Western::Calendar] 暦の開始日
16
+ attr_reader :start_date
17
+ # @return [Integer] 開始西暦年
18
+ attr_reader :start_year
19
+ # @return [Integer] 終了西暦年
20
+ attr_reader :last_year
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [String] name 暦名
26
+ # @param [Western::Calendar] start_date 暦の開始日
27
+ # @param [Integer] start_year 開始西暦年
28
+ # @param [Integer] last_year 終了西暦年
29
+ #
30
+ def initialize(name:, start_date:, start_year:, last_year:)
31
+ @name = name
32
+ @start_date = start_date
33
+ @start_year = start_year
34
+ @last_year = last_year
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './internal/crawler'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
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)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../era/western'
3
+ require_relative '../../era/western/calendar'
4
4
 
5
5
  # :nodoc:
6
6
  module Zakuro
@@ -23,7 +23,8 @@ module Zakuro
23
23
  # @param [Remainder] remainder 西暦日
24
24
  # @param [Western::Calendar] western_date 大余小余
25
25
  #
26
- def initialize(western_date: Western::Calendar.new, remainder:)
26
+ def initialize(western_date: Western::Calendar.new,
27
+ remainder: Calculation::Cycle::AbstractRemainder.new)
27
28
  # 西暦日
28
29
  @western_date = western_date
29
30
  # 大余小余
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../base/gengou'
3
4
  require_relative './first_day'
4
5
  require_relative './month_label'
5
6
 
@@ -21,6 +22,8 @@ module Zakuro
21
22
  attr_reader :first_day
22
23
  # @return [Array<SolarTerm>] 二十四節気
23
24
  attr_reader :solar_terms
25
+ # @return [Base::Gengou] 元号
26
+ attr_reader :gengou
24
27
 
25
28
  #
26
29
  # 初期化
@@ -29,13 +32,25 @@ module Zakuro
29
32
  # @param [MonthLabel] month_label 月表示名
30
33
  # @param [FirstDay] first_day 月初日(朔日)
31
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
35
+ # @param [Base::Gengou] gengou 元号
32
36
  #
33
- def initialize(context:, month_label: MonthLabel.new, first_day: FirstDay.new,
34
- solar_terms: [])
37
+ def initialize(context: Context.new, month_label: MonthLabel.new, first_day: FirstDay.new,
38
+ solar_terms: [], gengou: Base::Gengou.new)
35
39
  @context = context
36
40
  @month_label = month_label
37
41
  @first_day = first_day
38
42
  @solar_terms = solar_terms
43
+ @gengou = gengou
44
+ end
45
+
46
+ #
47
+ # 不正か
48
+ #
49
+ # @return [True] 不正
50
+ # @return [False] 不正なし
51
+ #
52
+ def invalid?
53
+ @context.invalid?
39
54
  end
40
55
 
41
56
  #
@@ -181,6 +196,38 @@ module Zakuro
181
196
  def same?(other:)
182
197
  number == other.number && leaped? == other.leaped?
183
198
  end
199
+
200
+ #
201
+ # 月の終了日を返す
202
+ #
203
+ # @return [Western::Calendar] 月の終了日
204
+ #
205
+ def last_date
206
+ return Western::Calendar.new if western_date.invalid?
207
+
208
+ western_date.clone + days - 1
209
+ end
210
+
211
+ #
212
+ # 範囲内か
213
+ #
214
+ # @param [Western::Calendar] date 日付
215
+ #
216
+ # @return [True] 範囲内
217
+ # @return [False] 範囲外
218
+ #
219
+ def include?(date:)
220
+ return false if invalid?
221
+
222
+ start_date = western_date
223
+ return false if start_date.invalid?
224
+
225
+ return false if date < start_date
226
+
227
+ return false if date > last_date
228
+
229
+ true
230
+ end
184
231
  end
185
232
  end
186
233
  end
@@ -34,10 +34,10 @@ module Zakuro
34
34
  # @param [Operation::MonthHistory] history 変更履歴(月)
35
35
  #
36
36
  def initialize(context:, operated_solar_terms:, month_label: MonthLabel.new,
37
- first_day: FirstDay.new, solar_terms: [],
37
+ first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
38
38
  history: Operation::MonthHistory.new)
39
39
  super(context: context, month_label: month_label, first_day: first_day,
40
- solar_terms: solar_terms)
40
+ solar_terms: solar_terms, gengou: gengou)
41
41
  @history = history
42
42
  @operated_solar_terms = operated_solar_terms
43
43
  @moved = false