zakuro 0.0.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +4 -0
  3. data/.gitignore +7 -1
  4. data/.rubocop.yml +3 -0
  5. data/Gemfile +2 -0
  6. data/Makefile +2 -0
  7. data/README.md +156 -10
  8. data/Rakefile +1 -1
  9. data/doc/gengou.md +315 -0
  10. data/doc/operation.md +25 -0
  11. data/doc/operation/csv/month.csv +202 -0
  12. data/doc/operation/operation.xlsx +0 -0
  13. data/doc/operation/transfer.rb +77 -0
  14. data/lib/zakuro/condition.rb +19 -15
  15. data/lib/zakuro/cycle/abstract_remainder.rb +3 -4
  16. data/lib/zakuro/era/japan/gengou.rb +106 -0
  17. data/lib/zakuro/era/japan/gengou/parser.rb +167 -0
  18. data/lib/zakuro/era/japan/gengou/type.rb +178 -0
  19. data/lib/zakuro/era/japan/gengou/validator.rb +236 -0
  20. data/lib/zakuro/era/japan/reki.rb +91 -0
  21. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +1121 -0
  22. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +485 -0
  23. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +28 -0
  24. data/lib/zakuro/era/western.rb +11 -1
  25. data/lib/zakuro/merchant.rb +3 -1
  26. data/lib/zakuro/operation/month/parser.rb +373 -0
  27. data/lib/zakuro/operation/month/type.rb +458 -0
  28. data/lib/zakuro/operation/month/validator.rb +802 -0
  29. data/lib/zakuro/operation/operation.rb +66 -0
  30. data/lib/zakuro/operation/yaml/month.yaml +6452 -0
  31. data/lib/zakuro/output/error.rb +2 -0
  32. data/lib/zakuro/output/logger.rb +2 -0
  33. data/lib/zakuro/output/response.rb +21 -19
  34. data/lib/zakuro/result/core.rb +52 -0
  35. data/lib/zakuro/result/data.rb +187 -0
  36. data/lib/zakuro/result/operation.rb +114 -0
  37. data/lib/zakuro/result/result.rb +37 -0
  38. data/lib/zakuro/{output → tools}/stringifier.rb +16 -9
  39. data/lib/zakuro/tools/typeof.rb +33 -0
  40. data/lib/zakuro/version.rb +1 -1
  41. data/lib/zakuro/version/senmyou/README.md +3 -1
  42. data/lib/zakuro/version/senmyou/base/era.rb +3 -1
  43. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +98 -0
  44. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +217 -0
  45. data/lib/zakuro/version/senmyou/base/remainder.rb +4 -4
  46. data/lib/zakuro/version/senmyou/base/solar_term.rb +20 -0
  47. data/lib/zakuro/version/senmyou/base/year.rb +52 -6
  48. data/lib/zakuro/version/senmyou/monthly/first_day.rb +44 -0
  49. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +48 -0
  50. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
  51. data/lib/zakuro/version/senmyou/monthly/month.rb +136 -67
  52. data/lib/zakuro/version/senmyou/monthly/month_label.rb +87 -0
  53. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +167 -0
  54. data/lib/zakuro/version/senmyou/{summary/annual_data.rb → range/annual_range.rb} +38 -40
  55. data/lib/zakuro/version/senmyou/range/full_range.rb +324 -0
  56. data/lib/zakuro/version/senmyou/range/operated_range.rb +126 -0
  57. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +181 -0
  58. data/lib/zakuro/version/senmyou/senmyou.rb +2 -2
  59. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +102 -0
  60. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +1 -1
  61. data/lib/zakuro/version/senmyou/stella/solar_average.rb +54 -32
  62. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +3 -7
  63. data/lib/zakuro/version/senmyou/summary/single.rb +125 -0
  64. data/lib/zakuro/version_factory.rb +1 -1
  65. metadata +40 -13
  66. data/.travis.yml +0 -6
  67. data/lib/zakuro/era/gengou/set-001-until-south.yaml +0 -375
  68. data/lib/zakuro/era/gengou/set-002-from-north.yaml +0 -166
  69. data/lib/zakuro/era/gengou/set-003-modern.yaml +0 -12
  70. data/lib/zakuro/era/japan.rb +0 -630
  71. data/lib/zakuro/output/result.rb +0 -219
  72. data/lib/zakuro/version/senmyou/base/gengou.rb +0 -210
  73. data/lib/zakuro/version/senmyou/summary/gengou_data.rb +0 -294
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './full_range'
4
+ require_relative './operated_solar_terms'
5
+ require_relative '../../../operation/operation'
6
+ require_relative '../monthly/operated_month'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Senmyou
12
+ #
13
+ # OperatedRange 運用結果範囲
14
+ #
15
+ # 何らかの理由により、計算された暦とは異なる運用結果である場合、その結果に合わせて計算結果を上書きする
16
+ class OperatedRange
17
+ # @return [Array<Year>] 年データ(完全範囲)
18
+ attr_reader :years
19
+ # @return [OperatedSolarTerms] 運用時二十四節気
20
+ attr_reader :operated_solar_terms
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Array<Year>] years 年データ(完全範囲)
26
+ #
27
+ def initialize(years: [])
28
+ @years = years
29
+ @operated_solar_terms = OperatedSolarTerms.new(years: @years)
30
+ @operated_solar_terms.create
31
+ end
32
+
33
+ #
34
+ # 運用結果範囲を取得する
35
+ #
36
+ # @return [Array<Year>] 運用結果範囲
37
+ #
38
+ def get
39
+ rewrite
40
+ end
41
+
42
+ #
43
+ # 運用結果に書き換える
44
+ #
45
+ # @return [Array<Year>] 運用結果範囲
46
+ #
47
+ def rewrite
48
+ operated_years = []
49
+
50
+ years.each do |year|
51
+ operated_year = OperatedRange.rewrite_year(
52
+ year: year, operated_solar_terms: @operated_solar_terms
53
+ )
54
+ operated_years.push(operated_year)
55
+ end
56
+
57
+ operated_years
58
+ end
59
+
60
+ #
61
+ # 年を書き換える
62
+ #
63
+ # @param [Year] year 年
64
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
65
+ #
66
+ # @return [Year] 年
67
+ #
68
+ def self.rewrite_year(year:, operated_solar_terms:)
69
+ result = Year.new(multi_gengou: year.multi_gengou, new_year_date: year.new_year_date)
70
+ year.months.each do |month|
71
+ result.push(month: resolve_month(
72
+ month: month, operated_solar_terms: operated_solar_terms
73
+ ))
74
+ end
75
+
76
+ result.commit
77
+
78
+ result
79
+ end
80
+
81
+ #
82
+ # 履歴情報の有無に応じた月にする
83
+ #
84
+ # @param [Month] month 月
85
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
86
+ #
87
+ # @return [Month] 月
88
+ #
89
+ def self.resolve_month(month:, operated_solar_terms:)
90
+ history = Operation.specify_history(western_date: month.western_date)
91
+
92
+ return month if history.invalid?
93
+
94
+ OperatedRange.rewrite_month(
95
+ month: month, history: history, operated_solar_terms: operated_solar_terms
96
+ )
97
+ end
98
+
99
+ #
100
+ # 月を運用結果に書き換える
101
+ #
102
+ # @param [Month] month 月
103
+ # @param [Operation::MonthHistory] history 変更履歴
104
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
105
+ #
106
+ # @return [Month] 月(運用結果)
107
+ #
108
+ def self.rewrite_month(month:, history:, operated_solar_terms:)
109
+ return month unless month.western_date == history.western_date
110
+
111
+ operated_month = OperatedMonth.new(
112
+ month_label: month.month_label, first_day: month.first_day,
113
+ solar_terms: month.solar_terms, history: history,
114
+ operated_solar_terms: operated_solar_terms
115
+ )
116
+
117
+ operated_month.rewrite
118
+
119
+ Month.new(
120
+ month_label: operated_month.month_label, first_day: operated_month.first_day,
121
+ solar_terms: operated_month.solar_terms
122
+ )
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './full_range'
4
+ require_relative '../../../operation/operation'
5
+ require_relative '../monthly/month'
6
+
7
+ # TODO: solar_termの中はsrc/destだが、yamlはcalc/actual。統一したい。
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Senmyou
13
+ #
14
+ # OperatedSolarTerm 運用時二十四節気
15
+ #
16
+ class OperatedSolarTerms
17
+ # @return [Array<Year>] 完全範囲(年データ)
18
+ attr_reader :years
19
+ # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
20
+ #
21
+ # * 移動元の二十四節気:無効な大余小余あり(削除対象)
22
+ # * 移動先の二十四節気:移動元からの二十四節気(追加対象)
23
+ #
24
+ attr_reader :directions
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [Array<Year>] years 完全範囲(年データ)
30
+ #
31
+ def initialize(years: [])
32
+ @years = years
33
+ @directions = {}
34
+ end
35
+
36
+ #
37
+ # データ生成する
38
+ #
39
+ # @return [<Type>] <description>
40
+ #
41
+ def create
42
+ @directions = create_directions
43
+ end
44
+
45
+ #
46
+ # 二十四節気を取得する
47
+ #
48
+ # @param [Western::Calendar] western_date 月初日の西暦日
49
+ #
50
+ # @return [True] 対象あり
51
+ # @return [False] 対象なし
52
+ # @return [SolarTerm] 二十四節気
53
+ #
54
+ def get(western_date: Western::Calendar.new)
55
+ solar_term = @directions.fetch(western_date.format, SolarTerm.new)
56
+
57
+ # 合致しない場合
58
+ return false, SolarTerm.new if solar_term.empty?
59
+
60
+ # 合致した上で、二十四節気が移動元(削除対象)の場合
61
+ # 合致した上で、二十四節気が移動先(追加対象)の場合
62
+ [true, solar_term]
63
+ end
64
+
65
+ #
66
+ # 二十四節気の移動元/移動先を生成する
67
+ #
68
+ # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
69
+ #
70
+ def create_directions
71
+ directions = {}
72
+
73
+ years.each do |year|
74
+ OperatedSolarTerms.create_directions_with_months(
75
+ directions: directions, months: year.months
76
+ )
77
+ end
78
+
79
+ directions
80
+ end
81
+
82
+ # :reek:TooManyStatements { max_statements: 6 }
83
+
84
+ #
85
+ # 年内の全ての月の移動方向を作成する
86
+ #
87
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
88
+ # @param [Array<Month>] months 年内の全ての月
89
+ #
90
+ def self.create_directions_with_months(directions: {}, months: [])
91
+ months.each do |month|
92
+ history = Operation.specify_history(western_date: month.western_date)
93
+
94
+ next if history.invalid?
95
+
96
+ direction = history.diffs.solar_term
97
+
98
+ next if direction.invalid?
99
+
100
+ OperatedSolarTerms.create_directions_each_month(
101
+ directions: directions, direction: direction, month: month
102
+ )
103
+ end
104
+ end
105
+
106
+ #
107
+ # 月毎の移動方向を作成する
108
+ #
109
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
110
+ # @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
111
+ # @param [Month] 月
112
+ #
113
+ def self.create_directions_each_month(directions: {},
114
+ direction: Operation::SolarTerm::Diretion.new,
115
+ month: Month.new)
116
+
117
+ month.solar_terms.each do |solar_term|
118
+ OperatedSolarTerms.push_source(directions: directions, direction: direction,
119
+ solar_term: solar_term)
120
+ end
121
+ OperatedSolarTerms.push_destination(directions: directions,
122
+ destination: direction.destination)
123
+ end
124
+
125
+ #
126
+ # 移動先に有効な二十四節気(差し替える二十四節気)を指定する
127
+ #
128
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
129
+ # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
130
+ # @param [SolarTerm] solar_term 二十四節気(計算値)
131
+ #
132
+ def self.push_source(directions: {}, direction: Operation::SolarTerm::Direction.new,
133
+ solar_term: SolarTerm.new)
134
+ source = direction.source
135
+
136
+ return if source.invalid?
137
+
138
+ return unless source.index == solar_term.index
139
+
140
+ # 移動先に移動元の二十四節気を指定する
141
+ directions[source.to.format] = OperatedSolarTerms.created_source(
142
+ direction: direction, solar_term: solar_term
143
+ )
144
+ end
145
+
146
+ #
147
+ # 移動先に有効な二十四節気(差し替える二十四節気)を生成する
148
+ #
149
+ # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
150
+ # @param [SolarTerm] solar_term 二十四節気(計算値)
151
+ #
152
+ # @return [SolarTerm] 二十四節気(運用値)
153
+ #
154
+ def self.created_source(direction: Operation::SolarTerm::Direction.new,
155
+ solar_term: SolarTerm.new)
156
+ operated_solar_term = solar_term.clone
157
+
158
+ unless direction.invalid_days?
159
+ # 二十四節気の大余をずらす
160
+ operated_solar_term.remainder.add!(
161
+ Remainder.new(day: direction.days, minute: 0, second: 0)
162
+ )
163
+ end
164
+
165
+ operated_solar_term
166
+ end
167
+
168
+ #
169
+ # 移動元に無効な二十四節気(連番のみ指定)を指定する
170
+ #
171
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
172
+ # @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
173
+ #
174
+ def self.push_destination(directions: {}, destination: Operation::SolarTerm::Destination.new)
175
+ return if destination.invalid?
176
+
177
+ directions[destination.from.format] = SolarTerm.new(index: destination.index)
178
+ end
179
+ end
180
+ end
181
+ end
@@ -3,7 +3,7 @@
3
3
  require 'date'
4
4
  require_relative '../abstract_version'
5
5
  require_relative '../../era/western'
6
- require_relative 'summary/gengou_data'
6
+ require_relative 'summary/single'
7
7
 
8
8
  # :nodoc:
9
9
  module Zakuro
@@ -27,7 +27,7 @@ module Zakuro
27
27
  #
28
28
  def self.to_japan_date(western_date:)
29
29
  date = Western::Calendar.create(date: western_date)
30
- GengouData.get_ancient_date(date: date)
30
+ Single.get(date: date)
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../era/western'
4
+ require_relative '../range/full_range'
5
+ require_relative '../base/multi_gengou_roller'
6
+ require_relative '../base/year'
7
+ require_relative '../../../output/response'
8
+ require_relative '../../../output/logger'
9
+
10
+ # :nodoc:
11
+ module Zakuro
12
+ # :nodoc:
13
+ module Senmyou
14
+ #
15
+ # SingleDaySpecifier 一日検索
16
+ #
17
+ module SingleDaySpecifier
18
+ # @return [Logger] ロガー
19
+ LOGGER = Logger.new(location: 'specifier')
20
+
21
+ #
22
+ # 取得する
23
+ #
24
+ # @param [Array<Year>] yeas 範囲
25
+ # @param [Western::Calendar] date 西暦日
26
+ #
27
+ # @return [Result::Data::SingleDay] 和暦日
28
+ #
29
+ def self.get(years: [], date: Western::Calendar.new)
30
+ year = specify_year(years: years, date: date)
31
+
32
+ year = transfer(year: year, date: date)
33
+
34
+ month = specify_month(year: year, date: date)
35
+ first_date = month.western_date
36
+
37
+ Response::SingleDay.save_single_day(
38
+ param: Response::SingleDay::Param.new(
39
+ year: year, month: month,
40
+ date: date, days: date - first_date
41
+ )
42
+ )
43
+ end
44
+
45
+ #
46
+ # 年を特定する
47
+ #
48
+ # @param [Array<Year>] years 範囲
49
+ # @param [Western::Calendar] date 西暦日
50
+ #
51
+ # @return [Year] 対象年
52
+ #
53
+ def self.specify_year(years:, date:)
54
+ years.reverse_each do |year|
55
+ return year if date >= year.new_year_date
56
+ end
57
+
58
+ raise ArgumentError, "invalid year range. date: #{date.format}"
59
+ end
60
+ private_class_method :specify_year
61
+
62
+ #
63
+ # 改元する
64
+ #
65
+ # @param [Year] year 年
66
+ # @param [Western::Calendar] date 西暦日
67
+ #
68
+ # @return [Year] 改元後の年
69
+ #
70
+ def self.transfer(year:, date:)
71
+ multi_gengou = MultiGengouRoller.transfer(multi_gengou: year.multi_gengou, date: date)
72
+ Year.new(multi_gengou: multi_gengou, new_year_date: year.new_year_date,
73
+ months: year.months, total_days: year.total_days)
74
+ end
75
+ private_class_method :transfer
76
+
77
+ # :reek:TooManyStatements { max_statements: 7 }
78
+
79
+ #
80
+ # 月を特定する
81
+ #
82
+ # @param [Year] year 年
83
+ # @param [Western::Calendar] date 西暦日
84
+ #
85
+ # @return [Month] 対象月
86
+ #
87
+ def self.specify_month(year:, date:)
88
+ months = year.months
89
+
90
+ current_month = months[0]
91
+ months.each do |month|
92
+ return current_month if month.western_date > date
93
+
94
+ current_month = month
95
+ end
96
+
97
+ current_month
98
+ end
99
+ private_class_method :specify_month
100
+ end
101
+ end
102
+ end
@@ -193,7 +193,7 @@ module Zakuro
193
193
  { |key, _| key.match(/^#{prefix}_#{format('%<day>02d', day: day)}_.*/) }
194
194
 
195
195
  targets.each do |key, value|
196
- # NOTE 境界値は上から順に引き当てた方を返す(7日の境界値7465は上のキーで返す)
196
+ # NOTE: 境界値は上から順に引き当てた方を返す(7日の境界値7465は上のキーで返す)
197
197
  matched, diff = \
198
198
  extract_data_from_moon_adjustment_key(key, minute)
199
199
  # 小余の下げ幅
@@ -17,11 +17,11 @@ module Zakuro
17
17
  # 冬至から数えた1年データの月ごとに二十四節気を割り当てる
18
18
  #
19
19
  # @param [Integer] western_year 西暦年
20
- # @param [Array<Month>] annual_data 1年データ
20
+ # @param [Array<Month>] annual_range 1年データ
21
21
  #
22
22
  # @return [Array<Month>] 1年データ
23
23
  #
24
- def self.set_solar_terms_into_annual_data(western_year:, annual_data:)
24
+ def self.set_solar_terms_into_annual_range(western_year:, annual_range:)
25
25
  # 天正冬至
26
26
  winter_solstice = WinterSolstice.calc(western_year: western_year)
27
27
 
@@ -30,17 +30,17 @@ module Zakuro
30
30
  winter_solstice: winter_solstice
31
31
  )
32
32
 
33
- apply_solar_terms_from_last_winter_solstice(annual_data: annual_data,
33
+ apply_solar_terms_from_last_winter_solstice(annual_range: annual_range,
34
34
  solar_terms: solar_terms)
35
35
 
36
36
  # 前後の二十四節気
37
37
  rest_solar_terms = \
38
38
  collect_solar_terms_before_and_after(solar_terms: solar_terms)
39
39
 
40
- apply_solar_terms_before_and_after(annual_data: annual_data,
40
+ apply_solar_terms_before_and_after(annual_range: annual_range,
41
41
  rest_solar_terms: rest_solar_terms)
42
42
 
43
- annual_data
43
+ annual_range
44
44
  end
45
45
 
46
46
  # :reek:TooManyStatements { max_statements: 6 }
@@ -69,30 +69,56 @@ module Zakuro
69
69
  #
70
70
  # 各月の二十四節気を設定する
71
71
  #
72
- # @param [Array<Month>] annual_data 1年データ
72
+ # @param [Array<Month>] annual_range 1年データ
73
73
  # @param [Array<Remainder>] solar_terms 1年データ内の全二十四節気
74
74
  #
75
- def self.apply_solar_terms_from_last_winter_solstice(annual_data:,
76
- solar_terms:)
77
- c_idx = 0
78
- st_idx = 0
79
- while c_idx < annual_data.size && st_idx < solar_terms.size
80
- current_month = annual_data[c_idx]
81
- next_month = annual_data[c_idx + 1]
82
- solar_term = solar_terms[st_idx]
83
-
84
- if in_range_solar_term?(target: solar_term, min: current_month.remainder,
85
- max: next_month.remainder)
86
- set_solar_term(month: current_month,
87
- solar_term: solar_term, solar_term_index: st_idx)
88
- st_idx += 1
75
+ def self.apply_solar_terms_from_last_winter_solstice(annual_range:, solar_terms:)
76
+ month_index = 0
77
+ solar_term_index = 0
78
+ month_size = annual_range.size
79
+
80
+ while month_index < month_size && solar_term_index < solar_terms.size
81
+ raise StandardError, "month is over. idx: #{month_index}" if month_index >= month_size
82
+
83
+ if set_solar_term_on_current_month(current_month: annual_range[month_index],
84
+ next_month: annual_range[month_index + 1],
85
+ solar_term: solar_terms[solar_term_index],
86
+ solar_term_index: solar_term_index)
87
+ solar_term_index += 1
89
88
  next
90
89
  end
91
- c_idx += 1
90
+
91
+ month_index += 1
92
92
  end
93
93
  end
94
94
  private_class_method :apply_solar_terms_from_last_winter_solstice
95
95
 
96
+ #
97
+ # 当月に二十四節気を設定する
98
+ #
99
+ # @param [Remainder] current_month 当月
100
+ # @param [Month] next_month 次月
101
+ # @param [Month] solar_term 二十四節気
102
+ # @param [Integer] solar_term_index 二十四節気位置
103
+ #
104
+ # @return [True] 設定済
105
+ # @return [False] 未設定
106
+ #
107
+ def self.set_solar_term_on_current_month(current_month:,
108
+ next_month:, solar_term:, solar_term_index:)
109
+ if in_range_solar_term?(target: solar_term, min: current_month.remainder,
110
+ max: next_month.remainder)
111
+ set_solar_term(month: current_month,
112
+ solar_term: solar_term, solar_term_index: solar_term_index)
113
+ return true
114
+ end
115
+
116
+ # 一度も割り当てがない場合は設定済みとして次の二十四節気を進める
117
+ return true if current_month.empty_solar_term?
118
+
119
+ false
120
+ end
121
+
96
122
  #
97
123
  # 1年データ内の二十四節気の前後を収集する
98
124
  #
@@ -120,18 +146,18 @@ module Zakuro
120
146
  #
121
147
  # 1年データ前後の二十四節気を適用する
122
148
  #
123
- # @param [Array<Month>] annual_data 1年データ
149
+ # @param [Array<Month>] annual_range 1年データ
124
150
  # @param [Hash<Integer, Hash<Symbol, Integer>>, Hash<Integer, Hash<Symbol, Remainder>>]
125
151
  # rest_solar_terms 前後
126
152
  #
127
- def self.apply_solar_terms_before_and_after(annual_data:, rest_solar_terms:)
153
+ def self.apply_solar_terms_before_and_after(annual_range:, rest_solar_terms:)
128
154
  rest_solar_terms.each do |key, value|
129
155
  index = value[:index]
130
156
  solar_term = value[:solar_term]
131
- data = annual_data[index]
157
+ data = annual_range[index]
132
158
  next unless in_range_solar_term?(
133
159
  target: solar_term,
134
- min: data.remainder, max: annual_data[index + 1].remainder
160
+ min: data.remainder, max: annual_range[index + 1].remainder
135
161
  )
136
162
 
137
163
  set_solar_term(month: data,
@@ -176,13 +202,9 @@ module Zakuro
176
202
  #
177
203
  def self.set_solar_term(month:, solar_term:, solar_term_index:)
178
204
  term = SolarTerm.new(remainder: solar_term, index: solar_term_index)
179
- if solar_term_index.even?
180
- # 中気
181
- month.even_term = term
182
- else
183
- # 節気
184
- month.odd_term = term
185
- end
205
+
206
+ # 設定する
207
+ month.add_term(term: term)
186
208
 
187
209
  nil
188
210
  end