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
@@ -1,13 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../era/western'
3
+ require_relative '../../version/context'
4
+
5
+ require_relative '../../era/western/calendar'
4
6
  require_relative '../../output/logger'
5
7
 
6
- require_relative '../base/multi_gengou_roller'
8
+ require_relative '../era/gengou/scroll'
9
+ require_relative '../era/version/version'
10
+
11
+ require_relative '../base/gengou'
7
12
  require_relative '../base/year'
8
13
 
9
14
  require_relative './transfer/year_boundary'
10
- require_relative './transfer/western_date_allocation'
15
+
16
+ require_relative './transfer/gengou_scroller'
11
17
 
12
18
  # :nodoc:
13
19
  module Zakuro
@@ -35,13 +41,9 @@ module Zakuro
35
41
  # @return [Western::Calendar] 開始日
36
42
  attr_reader :start_date
37
43
  # @return [Western::Calendar] 終了日
38
- attr_reader :end_date
44
+ attr_reader :last_date
39
45
  # @return [MultiGengouRoller] 改元処理
40
- attr_reader :multi_gengou_roller
41
- # @return [Western::Calendar] 最過去の元旦
42
- attr_reader :new_year_date
43
- # @return [Integer] 西暦年
44
- attr_reader :western_year
46
+ attr_reader :scroll
45
47
 
46
48
  # @return [Output::Logger] ロガー
47
49
  LOGGER = Output::Logger.new(location: 'full_range')
@@ -51,19 +53,16 @@ module Zakuro
51
53
  #
52
54
  # @param [Context] context 暦コンテキスト
53
55
  # @param [Western::Calendar] start_date 開始日
54
- # @param [Western::Calendar] end_date 終了日
56
+ # @param [Western::Calendar] last_date 終了日
55
57
  #
56
- def initialize(context:, start_date: Western::Calendar.new, end_date: Western::Calendar.new)
58
+ def initialize(context:, start_date: Western::Calendar.new, last_date: Western::Calendar.new)
57
59
  @start_date = start_date
58
- @end_date = end_date
60
+ @last_date = last_date
59
61
  return if invalid?
60
62
 
63
+ # TODO: 現時点では使用していない。特定の暦を指定できるようになった状態で使用する
61
64
  @context = context
62
- @multi_gengou_roller = Base::MultiGengouRoller.new(
63
- start_date: start_date, end_date: end_date
64
- )
65
- @new_year_date = @multi_gengou_roller.oldest_date.clone
66
- @western_year = @new_year_date.year
65
+ @scroll = Gengou::Scroll.new(start_date: start_date, last_date: last_date)
67
66
  end
68
67
 
69
68
  #
@@ -79,130 +78,92 @@ module Zakuro
79
78
  #
80
79
  # 完全範囲を取得する
81
80
  #
82
- # @return [Array<Year>] 完全範囲
81
+ # @return [Array<Base::Year>] 完全範囲
83
82
  #
84
83
  def get
85
84
  return [] if invalid?
86
85
 
87
- years = Transfer::YearBoundary.get(
88
- context: @context, annual_ranges: annual_ranges
89
- )
90
- years = update_gengou(years: years)
91
-
92
- Transfer::WesternDateAllocation.update_first_day(
93
- context: @context, years: years
94
- )
86
+ years = version_ranges
95
87
 
96
- years
97
- end
88
+ years.each(&:commit)
98
89
 
99
- # :reek:TooManyStatements { max_statements: 7 }
100
-
101
- #
102
- # 完全範囲内の年データを取得する
103
- #
104
- # @return [Array<Year>] 年データ(冬至基準)
105
- #
106
- def annual_ranges
107
- oldest_date = @new_year_date
108
- newest_date = @multi_gengou_roller.newest_date
109
- annual_range = context.resolver.annual_range
110
-
111
- years = []
112
- ((oldest_date.year)..(newest_date.year + 2)).each do |year|
113
- years.push(
114
- annual_range.get(
115
- context: @context, western_year: year
116
- )
117
- )
118
- end
90
+ Transfer::GengouScroller.set(scroll: scroll, years: years)
119
91
 
120
92
  years
121
93
  end
122
94
 
123
- # :reek:TooManyStatements { max_statements: 8 }
95
+ private
124
96
 
125
97
  #
126
- # 完全範囲内の年データの元号を開始年基準で更新する
127
- #
128
- # @param [Array<Year>] years 年データ(元旦基準)
98
+ # 暦別範囲
129
99
  #
130
- # @return [Array<Year>] 元号更新済み年データ(元旦基準)
100
+ # @return [Array<Base::Year>] 完全範囲
131
101
  #
132
- def update_gengou(years:)
133
- updated_years = []
134
-
135
- nearest_end_date = choise_nearest_end_date
136
-
137
- years.each do |year|
138
- next_year(years: updated_years, year: year)
139
-
140
- if @new_year_date > nearest_end_date
141
- @multi_gengou_roller.transfer
142
- nearest_end_date = choise_nearest_end_date
143
- end
144
- @multi_gengou_roller.next_year
145
- end
146
-
147
- updated_years
148
- end
102
+ def version_ranges
103
+ result = []
149
104
 
150
- private
105
+ start_year = @scroll.western_start_year
106
+ last_year = @scroll.western_last_year
151
107
 
152
- #
153
- # 元号処理対象の年を進める
154
- #
155
- # @param [Array<Year>] years 元号処理済み年データ(元旦基準)
156
- # @param [Year] year 元号処理前の年(元旦基準)
157
- #
158
- def next_year(years:, year:)
159
- updated_year = update_year(year: year)
108
+ versions = Version.get(start_year: start_year, last_year: last_year)
160
109
 
161
- years.push(updated_year)
110
+ versions.each_with_index do |version, index|
111
+ context = Context.new(version_name: version.name)
112
+ start_year = version.start_year
113
+ last_year = version.last_year
114
+ # 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
115
+ last_year += 1 if (index + 1) == versions.size
162
116
 
163
- next_new_year_date(total_days: updated_year.total_days)
117
+ years = boundary_resolved_ranges(
118
+ context: context, start_year: start_year, last_year: last_year
119
+ )
120
+ result.concat(years)
121
+ end
164
122
 
165
- nil
123
+ result
166
124
  end
167
125
 
168
126
  #
169
- # 年の元号を更新する
127
+ # 年境界解決済みの範囲
170
128
  #
171
- # @param [Year] year 元号処理前の年(元旦基準)
129
+ # @param [Context] context 暦コンテキスト
130
+ # @param [Integer] start_year 開始西暦年
131
+ # @param [Integer] last_year 終了西暦年
172
132
  #
173
- # @return [Year] 元号処理済の年(元旦基準)
133
+ # @return [Array<Base::Year>] 年境界解決済みの範囲
174
134
  #
175
- def update_year(year:)
176
- multi_gengou = @multi_gengou_roller.multi_gengou.clone
177
-
178
- updated_year = Base::Year.new(
179
- multi_gengou: multi_gengou, new_year_date: @new_year_date.clone,
180
- months: year.months
135
+ def boundary_resolved_ranges(context:, start_year:, last_year:)
136
+ ranges = annual_ranges(
137
+ context: context, start_year: start_year, last_year: last_year
181
138
  )
182
- updated_year.commit
183
139
 
184
- updated_year
140
+ Transfer::YearBoundary.get(
141
+ context: context, annual_ranges: ranges
142
+ )
185
143
  end
186
144
 
187
145
  #
188
- # 次の年に進める
146
+ # 完全範囲内の年データを取得する
189
147
  #
190
- # @param [Integer] total_days 年の日数
148
+ # @param [Context] context 暦コンテキスト
149
+ # @param [Integer] start_year 開始西暦年
150
+ # @param [Integer] last_year 終了西暦年
191
151
  #
192
- def next_new_year_date(total_days:)
193
- @new_year_date += total_days
194
- @multi_gengou_roller.next(days: total_days)
152
+ # @return [Array<Base::Year>] 年データ(冬至基準)
153
+ #
154
+ def annual_ranges(context:, start_year:, last_year:)
155
+ annual_range = context.resolver.annual_range
195
156
 
196
- nil
197
- end
157
+ years = []
158
+ (start_year..(last_year + 1)).each do |year|
159
+ years.push(
160
+ annual_range.get(
161
+ context: context, western_year: year
162
+ )
163
+ )
164
+ end
198
165
 
199
- #
200
- # 現在日からみて直近の未来に対する元号の切替前日を求める
201
- #
202
- # @return [Western::Calendar] 元号の切替前日
203
- #
204
- def choise_nearest_end_date
205
- @multi_gengou_roller.choise_nearest_end_date
166
+ years
206
167
  end
207
168
  end
208
169
  end
@@ -4,6 +4,7 @@ require_relative './operated_solar_terms'
4
4
  require_relative '../../operation/operation'
5
5
  require_relative '../base/operated_year'
6
6
  require_relative '../../calculation/monthly/operated_month'
7
+ require_relative './transfer/gengou_scroller'
7
8
 
8
9
  # :nodoc:
9
10
  module Zakuro
@@ -27,11 +28,15 @@ module Zakuro
27
28
  # 初期化
28
29
  #
29
30
  # @param [Context] context 暦コンテキスト
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] last_date 終了日
30
33
  # @param [Array<Year>] years 年データ(完全範囲)
31
34
  #
32
- def initialize(context:, years: [])
35
+ def initialize(context:, start_date: Western::Calendar.new, last_date: Western::Calendar.new,
36
+ years: [])
33
37
  @context = context
34
38
  @years = years
39
+ @scroll = Gengou::Scroll.new(start_date: start_date, last_date: last_date)
35
40
  @operated_solar_terms = OperatedSolarTerms.new(context: context, years: @years)
36
41
  @operated_solar_terms.create
37
42
  end
@@ -48,6 +53,8 @@ module Zakuro
48
53
 
49
54
  OperatedRange.commit(operated_years: operated_years)
50
55
 
56
+ Transfer::GengouScroller.set(scroll: @scroll, years: operated_years)
57
+
51
58
  operated_years
52
59
  end
53
60
 
@@ -61,7 +68,7 @@ module Zakuro
61
68
 
62
69
  years.each do |year|
63
70
  operated_year = OperatedRange.rewrite_year(
64
- context: context, year: year,
71
+ year: year,
65
72
  operated_solar_terms: @operated_solar_terms
66
73
  )
67
74
  operated_years.push(operated_year)
@@ -76,7 +83,6 @@ module Zakuro
76
83
  # @param [Array<OperatedYear>] operated_years 運用結果範囲
77
84
  #
78
85
  def self.move(operated_years:)
79
- # FIXME: この方式は完全ではない。範囲の1年前/1年後が必要
80
86
  move_into_next_year(operated_years: operated_years)
81
87
  move_into_last_year(operated_years: operated_years)
82
88
  end
@@ -121,16 +127,14 @@ module Zakuro
121
127
  #
122
128
  # 年を書き換える
123
129
  #
124
- # @param [Context] context 暦コンテキスト
125
130
  # @param [Year] year 年
126
131
  # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
127
132
  #
128
133
  # @return [OperatedYear] 年
129
134
  #
130
- def self.rewrite_year(context:, year:, operated_solar_terms:)
131
- result = Base::OperatedYear.new(
132
- multi_gengou: year.multi_gengou, new_year_date: year.new_year_date
133
- )
135
+ def self.rewrite_year(year:, operated_solar_terms:)
136
+ context = year.context
137
+ result = Base::OperatedYear.new(context: context)
134
138
  year.months.each do |month|
135
139
  result.push(month: resolve_month(
136
140
  context: context, month: month,
@@ -175,7 +179,7 @@ module Zakuro
175
179
  operated_month = Monthly::OperatedMonth.new(
176
180
  context: context,
177
181
  month_label: month.month_label, first_day: month.first_day,
178
- solar_terms: month.solar_terms, history: history,
182
+ solar_terms: month.solar_terms, history: history, gengou: month.gengou,
179
183
  operated_solar_terms: operated_solar_terms
180
184
  )
181
185
 
@@ -57,6 +57,8 @@ module Zakuro
57
57
  # @return [SolarTerm] 二十四節気
58
58
  #
59
59
  def get(western_date: Western::Calendar.new)
60
+ context = current_context(western_date: western_date)
61
+
60
62
  solar_term_class = context.resolver.solar_term
61
63
  solar_term = @directions.fetch(western_date.format, solar_term_class.new)
62
64
 
@@ -68,23 +70,6 @@ module Zakuro
68
70
  [true, solar_term]
69
71
  end
70
72
 
71
- #
72
- # 二十四節気の移動元/移動先を生成する
73
- #
74
- # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
75
- #
76
- def create_directions
77
- directions = {}
78
-
79
- years.each do |year|
80
- OperatedSolarTerms.create_directions_with_months(
81
- context: context, directions: directions, months: year.months
82
- )
83
- end
84
-
85
- directions
86
- end
87
-
88
73
  # :reek:TooManyStatements { max_statements: 6 }
89
74
 
90
75
  #
@@ -195,6 +180,40 @@ module Zakuro
195
180
  index: destination.index
196
181
  )
197
182
  end
183
+
184
+ private
185
+
186
+ #
187
+ # 日付に対応する暦コンテキストを取得する
188
+ #
189
+ # @param [Western::Calendar] western_date 西暦日
190
+ #
191
+ # @return [Context] 暦コンテキスト
192
+ #
193
+ def current_context(western_date: Western::Calendar.new)
194
+ @years.each do |year|
195
+ return year.context if western_date >= year.new_year_date
196
+ end
197
+
198
+ Context.new
199
+ end
200
+
201
+ #
202
+ # 二十四節気の移動元/移動先を生成する
203
+ #
204
+ # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
205
+ #
206
+ def create_directions
207
+ directions = {}
208
+
209
+ years.each do |year|
210
+ OperatedSolarTerms.create_directions_with_months(
211
+ context: year.context, directions: directions, months: year.months
212
+ )
213
+ end
214
+
215
+ directions
216
+ end
198
217
  end
199
218
  end
200
219
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../monthly/month'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Range
11
+ # :nodoc:
12
+ module Transfer
13
+ #
14
+ # GengouScroller 元号スクロール
15
+ #
16
+ module GengouScroller
17
+ #
18
+ # 元号を年に設定する
19
+ #
20
+ # @param [Gengou::Scroll] scroll 元号スクロール
21
+ # @param [Array<Base::Year>] years 年
22
+ #
23
+ def self.set(scroll:, years: [])
24
+ years.each do |year|
25
+ update_gengou_year(scroll: scroll, year: year)
26
+ end
27
+ end
28
+
29
+ #
30
+ # 年の元号を更新する
31
+ #
32
+ # @param [Base::Year] year 年
33
+ #
34
+ def self.update_gengou_year(scroll:, year:)
35
+ year.months.each_with_index do |month, index|
36
+ scroll.run(month: month)
37
+ gengou = scroll.to_gengou
38
+ year.months[index] = Monthly::Month.new(
39
+ context: month.context,
40
+ month_label: month.month_label,
41
+ first_day: Monthly::FirstDay.new(
42
+ remainder: month.first_day.remainder,
43
+ western_date: gengou.start_date.clone
44
+ ),
45
+ solar_terms: month.solar_terms, gengou: gengou
46
+ )
47
+ end
48
+ end
49
+ private_class_method :update_gengou_year
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../calculation/base/multi_gengou_roller'
4
3
  require_relative '../../../calculation/base/year'
5
4
 
6
- require_relative '../../../era/western'
5
+ require_relative '../../../era/western/calendar'
7
6
 
8
7
  # :nodoc:
9
8
  module Zakuro
@@ -21,27 +20,30 @@ module Zakuro
21
20
  # 年間範囲内の年データの開始月を変更する
22
21
  #
23
22
  # @param [Context] context 暦コンテキスト
24
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
23
+ # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
25
24
  #
26
- # @return [Array<Year>] 年データ(元旦基準)
25
+ # @return [Array<Base::Year>] 年データ(元旦基準)
27
26
  #
28
27
  def self.get(context:, annual_ranges:)
29
28
  categorize(context: context, annual_ranges: annual_ranges)
30
- rearranged_years(annual_ranges: annual_ranges)
29
+ rearranged_years(context: context, annual_ranges: annual_ranges)
31
30
  end
32
31
 
33
32
  #
34
33
  # 年間範囲内の年データの開始月を変更する
35
34
  #
36
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
35
+ # @param [Context] context 暦コンテキスト
36
+ # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
37
37
  #
38
- # @return [Array<Year>] 年データ(元旦基準)
38
+ # @return [Array<Base::Year>] 年データ(元旦基準)
39
39
  #
40
- def self.rearranged_years(annual_ranges:)
40
+ def self.rearranged_years(context:, annual_ranges:)
41
41
  years = []
42
42
 
43
43
  (0..(annual_ranges.size - 2)).each do |index|
44
- year = rearranged_year(annual_ranges: annual_ranges, index: index)
44
+ year = rearranged_year(
45
+ context: context, annual_ranges: annual_ranges, index: index
46
+ )
45
47
  years.push(year)
46
48
  end
47
49
 
@@ -53,7 +55,7 @@ module Zakuro
53
55
  # 年間範囲を昨年/今年で分類する
54
56
  #
55
57
  # @param [Context] context 暦コンテキスト
56
- # @param [Array<Year>] annual_range 1年データ
58
+ # @param [Array<Base::Year>] annual_range 1年データ
57
59
  #
58
60
  def self.categorize(context:, annual_ranges:)
59
61
  annual_ranges.each do |annual_range|
@@ -86,16 +88,17 @@ module Zakuro
86
88
  #
87
89
  # 年データの開始月を変更する
88
90
  #
89
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
91
+ # @param [Context] context 暦コンテキスト
92
+ # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
90
93
  # @param [Integer] index 対象年の要素番号
91
94
  #
92
- # @return [Year] 年データ(元旦基準)
95
+ # @return [Base::Year] 年データ(元旦基準)
93
96
  #
94
- def self.rearranged_year(annual_ranges:, index:)
97
+ def self.rearranged_year(context:, annual_ranges:, index:)
95
98
  current_annual_range = annual_ranges[index]
96
99
  next_annual_range = annual_ranges[index + 1]
97
100
 
98
- year = push_current_year(annual_range: current_annual_range)
101
+ year = push_current_year(context: context, annual_range: current_annual_range)
99
102
  push_last_year(annual_range: next_annual_range, year: year)
100
103
 
101
104
  year
@@ -105,12 +108,13 @@ module Zakuro
105
108
  #
106
109
  # 当年データを生成する
107
110
  #
108
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
109
- # @param [Year] year 対象年
111
+ # @param [Context] context 暦コンテキスト
112
+ # @param [Array<Month>] annual_range 1年データ
110
113
  #
111
- # @return [Year] 当年月ありの対象年
114
+ # @return [Base::Year] 当年月ありの対象年
112
115
  #
113
- def self.push_current_year(annual_range:, year: Base::Year.new)
116
+ def self.push_current_year(context:, annual_range:)
117
+ year = Base::Year.new(context: context)
114
118
  annual_range.each do |month|
115
119
  next if month.is_last_year
116
120
 
@@ -124,10 +128,10 @@ module Zakuro
124
128
  #
125
129
  # 昨年データを生成する
126
130
  #
127
- # @param [Array<Year>] annual_ranges 年データ(冬至基準)
128
- # @param [Year] year 対象年
131
+ # @param [Array<Month>] annual_range 1年データ
132
+ # @param [Base::Year] year 対象年
129
133
  #
130
- # @return [Year] 昨年月ありの対象年
134
+ # @return [Base::Year] 昨年月ありの対象年
131
135
  #
132
136
  def self.push_last_year(annual_range:, year: Base::Year.new)
133
137
  annual_range.each do |month|
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../output/response'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Specifier
11
+ #
12
+ # Month 特定月
13
+ #
14
+ class Month
15
+ # @return [Western::Calendar] 西暦開始日
16
+ attr_reader :start_date
17
+ # @return [Western::Calendar] 西暦終了日
18
+ attr_reader :last_date
19
+ # @return [Base::Year] 年
20
+ attr_reader :year
21
+ # @return [Monthly::Month] 月
22
+ attr_reader :month
23
+
24
+ #
25
+ # 初期化
26
+ #
27
+ # @param [Western::Calendar] start_date 西暦開始日
28
+ # @param [Western::Calendar] last_date 西暦終了日
29
+ # @param [Base::Year] year 年
30
+ # @param [Monthly::Month] month 月
31
+ #
32
+ def initialize(start_date:, last_date:, year:, month:)
33
+ @start_date = start_date
34
+ @last_date = last_date
35
+ @year = year
36
+ @month = month
37
+ end
38
+
39
+ #
40
+ # 取得する
41
+ #
42
+ # @return [Array<Result::Data::SingleDay>] 1日データ
43
+ #
44
+ def get
45
+ result = []
46
+ first_date = @month.western_date.clone
47
+
48
+ (0..@month.days).each do |index|
49
+ current_date = first_date.clone + index
50
+
51
+ next unless include?(date: current_date)
52
+
53
+ day = Output::Response::SingleDay.save_single_day(
54
+ param: Output::Response::SingleDay::Param.new(
55
+ year: @year, month: @month,
56
+ date: current_date, days: index
57
+ )
58
+ )
59
+
60
+ result.push(day)
61
+ end
62
+
63
+ result
64
+ end
65
+
66
+ #
67
+ # 含まれるか
68
+ #
69
+ # @param [Western::Calendar] date 西暦日
70
+ #
71
+ # @return [True] 含む
72
+ # @return [False] 含まない
73
+ #
74
+ def include?(date:)
75
+ return false if date < @start_date
76
+
77
+ return false if date > @last_date
78
+
79
+ true
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end