zakuro 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d08bb0a2c54dc9063ff82a701ea1f37cc9df43a8a4b4fad26d8dd9245ddde625
4
- data.tar.gz: 566e821086421324a1ad61752c7e743a0a15d52d06cd3b83c60fb366f8424cbe
3
+ metadata.gz: fd8b402a7084ab57e0424c65d9851cc72f759b81f6f9b4c7f1e71afcda27d561
4
+ data.tar.gz: f204f25a8a6addad96556cb9376b406d6c1285375e79c693169d3095b6f5b387
5
5
  SHA512:
6
- metadata.gz: 759f9d80603988387f6f896fc0d0fcc0800e75879055350aee6ce2c2e862e9f81b4e0e59aacf5b1a84bcf8244ce68db8576eb4562148189fe9d5ce3d6c525d49
7
- data.tar.gz: 56e35d9ec9f2445fd063500032d4eec965faed3165d6d04882491a73ccb9b7419a14b5b1e54e801bd8cf6a0130cc1bbd1a7de1ff674f87be9ddd8e271624153c
6
+ metadata.gz: a7c7c8b0fef50d3da9f45701883ec271f3c000676a4a70e1d0c73ae4b15249e6a2cd57be47bd01a9ad6109da9b6593745ccc348c83d32743a09442bf7a922343
7
+ data.tar.gz: c5e6aa6ef4b4cc21814859753bf8bfd02be637173011bc6a2eb3dd28f4cfe1505d9faeb6544759f3f92543a8ee35820c73d54811a48d9d47ab645d38a995ed16
@@ -340,7 +340,7 @@ module Zakuro
340
340
  Month.new(
341
341
  number: create_month_number(yaml_hash: yaml_hash['number']),
342
342
  leaped: create_month_leaped(yaml_hash: yaml_hash['leaped']),
343
- days: create_month_day(yaml_hash: yaml_hash['days'])
343
+ is_many_days: create_month_day(yaml_hash: yaml_hash['days'])
344
344
  )
345
345
  end
346
346
  private_class_method :create_month
@@ -186,7 +186,7 @@ module Zakuro
186
186
  # @return [Leaped] 閏有無
187
187
  attr_reader :leaped
188
188
  # @return [Days] 月の大小
189
- attr_reader :days
189
+ attr_reader :is_many_days
190
190
 
191
191
  # :reek:BooleanParameter
192
192
 
@@ -197,10 +197,10 @@ module Zakuro
197
197
  # @param [Leaped] leaped 閏有無
198
198
  # @param [Days] days 月の大小
199
199
  #
200
- def initialize(number: Number.new, leaped: Leaped.new, days: Days.new)
200
+ def initialize(number: Number.new, leaped: Leaped.new, is_many_days: Days.new)
201
201
  @number = number
202
202
  @leaped = leaped
203
- @days = days
203
+ @is_many_days = is_many_days
204
204
  end
205
205
 
206
206
  #
@@ -408,11 +408,6 @@ module Zakuro
408
408
  # @return [String] 30日
409
409
  BIG = '大'
410
410
 
411
- # @return [String] 計算
412
- attr_reader :calc
413
- # @return [String] 運用
414
- attr_reader :actual
415
-
416
411
  #
417
412
  # 初期化
418
413
  #
@@ -430,7 +425,7 @@ module Zakuro
430
425
  # @return [True] 大
431
426
  # @return [False] 小
432
427
  #
433
- def many_days_calc?
428
+ def calc
434
429
  @calc == BIG
435
430
  end
436
431
 
@@ -440,7 +435,7 @@ module Zakuro
440
435
  # @return [True] 大
441
436
  # @return [False] 小
442
437
  #
443
- def many_days_actual?
438
+ def actual
444
439
  @actual == BIG
445
440
  end
446
441
 
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Zakuro
5
5
  # @return [String] library version
6
- VERSION = '0.1.1'
6
+ VERSION = '0.1.2'
7
7
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+
4
+ require_relative './remainder'
5
+
3
6
  # :nodoc:
4
7
  module Zakuro
5
8
  # :nodoc:
@@ -13,6 +16,9 @@ module Zakuro
13
16
  # @return [Remainder] 時刻情報(大余小余)
14
17
  attr_reader :remainder
15
18
 
19
+ # @return [Remainder] 気策(24分の1年)
20
+ SOLAR_TERM_AVERAGE = Remainder.new(day: 15, minute: 1835, second: 5)
21
+
16
22
  # @return [Hash<Integer, Symbol>] 順序
17
23
  ORDER = {
18
24
  0 => :touji,
@@ -72,6 +78,62 @@ module Zakuro
72
78
  (@index == -1 && @remainder.invalid?)
73
79
  end
74
80
 
81
+ def index?(index)
82
+ result = ORDER.fetch(index, -1)
83
+
84
+ result != -1
85
+ end
86
+
87
+ #
88
+ # 次の二十四節気に進める
89
+ #
90
+ def next!
91
+ @index += 1
92
+ @index = 0 if @index >= ORDER.size
93
+
94
+ @remainder.add!(SOLAR_TERM_AVERAGE)
95
+ end
96
+
97
+ #
98
+ # 指定した連番の二十四節気まで進める
99
+ #
100
+ # @param [Integer] index 連番
101
+ #
102
+ def next_by_index(index)
103
+ return ArgumentError.new, 'invalid index' unless index?(index)
104
+
105
+ loop do
106
+ return if @index == index
107
+
108
+ next!
109
+ end
110
+ end
111
+
112
+ #
113
+ # 指定した連番の二十四節気まで戻す
114
+ #
115
+ # @param [Integer] index 連番
116
+ #
117
+ def prev_by_index(index)
118
+ return ArgumentError.new, 'invalid index' unless index?(index)
119
+
120
+ loop do
121
+ return if @index == index
122
+
123
+ prev!
124
+ end
125
+ end
126
+
127
+ #
128
+ # 前の二十四節気に戻る
129
+ #
130
+ def prev!
131
+ @index -= 1
132
+ @index = 23 if @index.negative?
133
+
134
+ @remainder.sub!(SOLAR_TERM_AVERAGE)
135
+ end
136
+
75
137
  #
76
138
  # ディープコピー
77
139
  #
@@ -37,12 +37,83 @@ module Zakuro
37
37
  @phase_index = phase_index
38
38
  end
39
39
 
40
+ # :reek:TooManyStatements { max_statements: 6 }
41
+
42
+ #
43
+ # 現在の二十四節気に合わせて月表示情報を書き換える
44
+ #
45
+ def rename_month_label_by_solar_term
46
+ return ArgumentError.new, 'solar term must not be empty.' if empty_solar_term?
47
+
48
+ even = even_term
49
+
50
+ is_many_days = month_label.is_many_days
51
+ if even.invalid?
52
+ @month_label = MonthLabel.new(
53
+ number: InitializedMonth.month_number_by_odd_term_index(odd_term.index),
54
+ leaped: true, is_many_days: is_many_days
55
+ )
56
+ return
57
+ end
58
+
59
+ @month_label = MonthLabel.new(
60
+ number: InitializedMonth.month_number_by_even_term_index(even.index),
61
+ leaped: false, is_many_days: is_many_days
62
+ )
63
+ end
64
+
65
+ #
66
+ # 中気の連番に合わせて月を返す
67
+ #
68
+ # @example
69
+ # 20: 9月
70
+ # 22: 10月
71
+ # 0: 11月
72
+ # 2: 12月
73
+ # 4: 1月
74
+ #
75
+ # @param [Integer] index 中気番号
76
+ #
77
+ # @return [Integer] 月
78
+ #
79
+ def self.month_number_by_even_term_index(index)
80
+ half_index = index / 2
81
+
82
+ # 11月、12月
83
+ return half_index + 11 if half_index < 2
84
+
85
+ # 1月~10月
86
+ half_index - 1
87
+ end
88
+
89
+ #
90
+ # 節気の連番に合わせて月を返す
91
+ #
92
+ # @param [Integer] index 節気番号
93
+ #
94
+ # @return [Integer] 月
95
+ #
96
+ def self.month_number_by_odd_term_index(index)
97
+ even_index = index - 1
98
+
99
+ month_number_by_even_term_index(even_index)
100
+ end
101
+
40
102
  #
41
103
  # 一ヶ月戻す
42
104
  #
43
105
  def back_to_last_month
44
106
  @is_last_year = true if month_label.back_to_last_month
45
107
  end
108
+
109
+ #
110
+ # 二十四節気の数を返す
111
+ #
112
+ # @return [Integer] 二十四節気の数
113
+ #
114
+ def solar_term_size
115
+ solar_terms.size
116
+ end
46
117
  end
47
118
  end
48
119
  end
@@ -59,7 +59,7 @@ module Zakuro
59
59
  @average_remainder = WinterSolstice.calc_averaged_last_november_1st(
60
60
  western_year: @western_year
61
61
  )
62
- # 天正冬至
62
+ # 天正閏余
63
63
  winter_solstice_age = \
64
64
  WinterSolstice.calc_moon_age(western_year: @western_year)
65
65
  # 入定気
@@ -180,7 +180,7 @@ module Zakuro
180
180
  # @return [Integer] 太陽運動の補正値
181
181
  #
182
182
  def correction_solar_value
183
- @solar_term = SolarOrbit.calc_solar_term_by_remainder(
183
+ @solar_term = SolarLocation.get(
184
184
  solar_term: @solar_term
185
185
  )
186
186
  debug("@solar_term.remainder: #{@solar_term.remainder.format(form: '%d-%d.%d')}")
@@ -7,6 +7,8 @@ require_relative '../../../operation/operation'
7
7
  module Zakuro
8
8
  # :nodoc:
9
9
  module Senmyou
10
+ # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
11
+
10
12
  #
11
13
  # OperatedMonth 月情報(運用)
12
14
  #
@@ -19,13 +21,14 @@ module Zakuro
19
21
  #
20
22
  # 初期化
21
23
  #
24
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
22
25
  # @param [MonthLabel] month_label 月表示名
23
26
  # @param [FirstDay] first_day 月初日(朔日)
24
27
  # @param [Array<SolarTerm>] solar_terms 二十四節気
25
28
  # @param [Operation::MonthHistory] history 変更履歴(月)
26
29
  #
27
- def initialize(operated_solar_terms:, month_label: MonthLabel.new, first_day: FirstDay.new, solar_terms: [],
28
- history: Operation::MonthHistory.new)
30
+ def initialize(operated_solar_terms:, month_label: MonthLabel.new, first_day: FirstDay.new,
31
+ solar_terms: [], history: Operation::MonthHistory.new)
29
32
  super(month_label: month_label, first_day: first_day, solar_terms: solar_terms)
30
33
  @history = history
31
34
  @operated_solar_terms = operated_solar_terms
@@ -47,77 +50,103 @@ module Zakuro
47
50
  diff = history.diffs.month
48
51
 
49
52
  @month_label = MonthLabel.new(
50
- number: rewrite_number(diff: diff.number),
51
- is_many_days: rewrite_many_days(diff: diff.days),
52
- leaped: rewrite_leaped(diff: diff.leaped)
53
+ number: OperatedMonth.rewrite_month_fields(
54
+ month_diff: diff, month_label: month_label, name: 'number'
55
+ ),
56
+ is_many_days: OperatedMonth.rewrite_month_fields(
57
+ month_diff: diff, month_label: month_label, name: 'is_many_days'
58
+ ),
59
+ leaped: OperatedMonth.rewrite_month_fields(
60
+ month_diff: diff, month_label: month_label, name: 'leaped'
61
+ )
53
62
  )
54
63
  end
55
64
 
65
+ def self.rewrite_month_fields(month_diff:, month_label:, name:)
66
+ method_name = name.intern
67
+
68
+ diff = month_diff.send(method_name)
69
+ default = month_label.send(method_name)
70
+ return default if diff.invalid?
71
+
72
+ diff.actual
73
+ end
74
+
56
75
  #
57
- # 月ごとの差分(月)で書き換える
58
- #
59
- # @param [Operation::Number] diff 差分
60
- #
61
- # @return [Integer] 月
76
+ # 二十四節気ごとの差分で書き換える
62
77
  #
63
- def rewrite_number(diff:)
64
- return month_label.number if diff.invalid?
78
+ def rewrite_solar_terms
79
+ matched, operated_solar_term = @operated_solar_terms.get(
80
+ western_date: first_day.western_date
81
+ )
65
82
 
66
- diff.actual
83
+ return unless matched
84
+
85
+ @solar_terms = OperatedMonth.create_operated_solar_terms(
86
+ operated_solar_term: operated_solar_term,
87
+ solar_terms: solar_terms
88
+ )
67
89
  end
68
90
 
69
91
  #
70
- # 月ごとの差分(月の大小)で書き換える
92
+ # <Description>
71
93
  #
72
- # @param [Operation::Days] diff 差分
94
+ # @param [<Type>] operated_solar_term <description>
95
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
73
96
  #
74
- # @return [Integer] 月の大小
97
+ # @return [Array<SolarTerm>] 二十四節気
75
98
  #
76
- def rewrite_many_days(diff:)
77
- return month_label.is_many_days if diff.invalid?
99
+ def self.create_operated_solar_terms(operated_solar_term:, solar_terms:)
100
+ index = operated_solar_term.index
101
+
102
+ # 別の月に移動する二十四節気。割り当てない。
103
+ result = remove_solar_term(index: index, solar_terms: solar_terms)
78
104
 
79
- diff.many_days_actual?
105
+ return result if used_solar_term?(index: index, solar_terms: solar_terms)
106
+
107
+ result.push(operated_solar_term)
108
+
109
+ result
80
110
  end
81
111
 
112
+ # :reek:ControlParameter
113
+
82
114
  #
83
- # 月ごとの差分(閏有無)で書き換える
115
+ # 二十四節気が使用されているか
84
116
  #
85
- # @param [Operation::Days] diff 差分
117
+ # @param [Integer] index 二十四節気番号
118
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
86
119
  #
87
- # @return [True] 閏あり
88
- # @return [False] 閏なし
120
+ # @return [True] 使用
121
+ # @return [False] 未使用
89
122
  #
90
- def rewrite_leaped(diff:)
91
- return month_label.leaped if diff.invalid?
123
+ def self.used_solar_term?(index:, solar_terms:)
124
+ solar_terms.each do |solar_term|
125
+ return true if index == solar_term.index
126
+ end
92
127
 
93
- diff.actual
128
+ false
94
129
  end
95
130
 
131
+ # :reek:ControlParameter
132
+
96
133
  #
97
- # 二十四節気ごとの差分で書き換える
134
+ # 対象の二十四節気を除外する
98
135
  #
99
- def rewrite_solar_terms
100
- # TODO: リファクタリング
101
- operated_solar_terms = []
102
- matched, operated_solar_term = @operated_solar_terms.get(
103
- western_date: @first_day.western_date
104
- )
105
-
106
- return unless matched
107
-
108
- used = false
109
- @solar_terms.each do |solar_term|
110
- if operated_solar_term.index == solar_term.index
111
- used = true
112
- next
113
- end
136
+ # @param [Integer] index 二十四節気番号
137
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
138
+ #
139
+ # @return [Array<SolarTerm>] 二十四節気(対象除外済)
140
+ #
141
+ def self.remove_solar_term(index:, solar_terms:)
142
+ result = []
143
+ solar_terms.each do |solar_term|
144
+ next if index == solar_term.index
114
145
 
115
- operated_solar_terms.push(solar_term)
146
+ result.push(solar_term)
116
147
  end
117
148
 
118
- operated_solar_terms.push(operated_solar_term) unless used
119
-
120
- @solar_terms = operated_solar_terms
149
+ result
121
150
  end
122
151
 
123
152
  #
@@ -143,7 +172,7 @@ module Zakuro
143
172
  # @return [Remainder] 月初日の大余小余
144
173
  #
145
174
  def rewrite_remainder(days:)
146
- remainder = @first_day.remainder.clone
175
+ remainder = first_day.remainder.clone
147
176
  remainder.add!(Remainder.new(day: days, minute: 0, second: 0))
148
177
 
149
178
  remainder
@@ -157,7 +186,7 @@ module Zakuro
157
186
  # @return [Western::Calendar] 月初日の西暦日
158
187
  #
159
188
  def rewrite_western_date(days:)
160
- western_date = @first_day.western_date.clone
189
+ western_date = first_day.western_date.clone
161
190
  western_date += days
162
191
 
163
192
  western_date