zakuro 0.0.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/README.md +102 -42
  4. data/doc/operation.md +25 -0
  5. data/doc/operation/csv/month.csv +202 -0
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/doc/operation/transfer.rb +77 -0
  8. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  9. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  10. data/lib/zakuro/calculation/base/year.rb +107 -0
  11. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +459 -0
  12. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +151 -0
  13. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  14. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  15. data/lib/zakuro/calculation/monthly/initialized_month.rb +120 -0
  16. data/lib/zakuro/calculation/monthly/month.rb +184 -0
  17. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  18. data/lib/zakuro/calculation/monthly/operated_month.rb +201 -0
  19. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  20. data/lib/zakuro/calculation/range/operated_range.rb +134 -0
  21. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  22. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +76 -0
  23. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +142 -0
  24. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  25. data/lib/zakuro/calculation/summary/single.rb +129 -0
  26. data/lib/zakuro/condition.rb +17 -13
  27. data/lib/zakuro/era/japan/gengou.rb +106 -0
  28. data/lib/zakuro/era/japan/gengou/parser.rb +167 -0
  29. data/lib/zakuro/era/japan/gengou/type.rb +178 -0
  30. data/lib/zakuro/era/japan/gengou/validator.rb +236 -0
  31. data/lib/zakuro/era/japan/reki.rb +91 -0
  32. data/lib/zakuro/era/{gengou → japan/yaml}/set-001-until-south.yaml +0 -0
  33. data/lib/zakuro/era/{gengou → japan/yaml}/set-002-from-north.yaml +0 -0
  34. data/lib/zakuro/era/{gengou → japan/yaml}/set-003-modern.yaml +1 -1
  35. data/lib/zakuro/era/western.rb +1 -1
  36. data/lib/zakuro/merchant.rb +2 -2
  37. data/lib/zakuro/operation/month/parser.rb +373 -0
  38. data/lib/zakuro/operation/month/type.rb +453 -0
  39. data/lib/zakuro/operation/month/validator.rb +802 -0
  40. data/lib/zakuro/operation/operation.rb +66 -0
  41. data/lib/zakuro/operation/yaml/month.yaml +6452 -0
  42. data/lib/zakuro/output/error.rb +7 -4
  43. data/lib/zakuro/output/logger.rb +50 -47
  44. data/lib/zakuro/output/response.rb +146 -143
  45. data/lib/zakuro/result/core.rb +52 -0
  46. data/lib/zakuro/result/data.rb +187 -0
  47. data/lib/zakuro/result/operation.rb +114 -0
  48. data/lib/zakuro/result/result.rb +37 -0
  49. data/lib/zakuro/{output → tools}/stringifier.rb +16 -9
  50. data/lib/zakuro/tools/typeof.rb +33 -0
  51. data/lib/zakuro/version.rb +1 -1
  52. data/lib/zakuro/version/abstract_version.rb +1 -1
  53. data/lib/zakuro/version/context.rb +23 -0
  54. data/lib/zakuro/version/senmyou/cycle/remainder.rb +63 -0
  55. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
  56. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +186 -182
  57. data/lib/zakuro/version/senmyou/range/annual_range.rb +164 -0
  58. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  59. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +7 -7
  60. data/lib/zakuro/version/senmyou/stella/solar_average.rb +103 -138
  61. data/lib/zakuro/version/senmyou/stella/solar_location.rb +213 -0
  62. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +6 -191
  63. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +4 -4
  64. data/lib/zakuro/version/version_class_resolver.rb +62 -0
  65. data/lib/zakuro/version_factory.rb +3 -3
  66. metadata +49 -20
  67. data/lib/zakuro/cycle/abstract_remainder.rb +0 -457
  68. data/lib/zakuro/cycle/zodiac.rb +0 -103
  69. data/lib/zakuro/era/japan.rb +0 -660
  70. data/lib/zakuro/output/result.rb +0 -219
  71. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  72. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  73. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -205
  74. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  75. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -66
  76. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  77. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -122
  78. data/lib/zakuro/version/senmyou/summary/annual_range.rb +0 -186
  79. data/lib/zakuro/version/senmyou/summary/full_range.rb +0 -216
  80. data/lib/zakuro/version/senmyou/summary/specifier.rb +0 -100
@@ -17,7 +17,7 @@ module Zakuro
17
17
  #
18
18
  # @param [Date] western_date 西暦日
19
19
  #
20
- # @return [Result::SingleDay] 和暦日
20
+ # @return [Result::Single] 和暦日
21
21
  #
22
22
  # @raise [NotImplementedError] オーバーライドなし
23
23
  #
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './version_class_resolver'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Context 暦コンテキスト
9
+ #
10
+ class Context
11
+ attr_reader :version_name
12
+ attr_reader :resolver
13
+
14
+ VERSION_NAMES = %w[Genka Gihou Taien Senmyou Joukyou Kansei Tenpou Gregorio].freeze
15
+
16
+ def initialize(version_name:)
17
+ raise ArgumentError.new, 'invalid version' unless VERSION_NAMES.include?(version_name)
18
+
19
+ @version_name = version_name
20
+ @resolver = VersionClassResolver.new(version_name: version_name)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/cycle/abstract_remainder'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Senmyou
9
+ # :nodoc:
10
+ module Cycle
11
+ #
12
+ # Remainder 宣明暦の時刻情報(大余小余)
13
+ #
14
+ # * 「15日1835分5秒」のような形式で表される
15
+ # * 分は8400で一日に繰り上げる
16
+ # * 秒は基本的に1/8分で、8秒で1分に繰り上げる。ただし、月補正値は1分に100秒とするなど基数の変更がありえる
17
+ # * 十干十二支(60日)を上限とした「日時分秒」の情報で、日付(date)/時刻(time)と部分的に重なる概念
18
+ #
19
+ class Remainder < Calculation::Cycle::AbstractRemainder
20
+ # @return [Integer] 統法(1日=8400分)
21
+ DAY = 8400
22
+ # @return [Integer] 分(1分=8秒)
23
+ MINUTE = 8
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [Integer] day 大余("日"に相当)
29
+ # @param [Integer] minute 小余("分"に相当)
30
+ # @param [Integer] second 秒
31
+ # @param [Integer] total 繰り上げなしの小余
32
+ #
33
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
34
+ super(base_day: DAY, base_mitune: MINUTE,
35
+ day: day, minute: minute, second: second, total: total)
36
+ end
37
+ end
38
+
39
+ #
40
+ # LunarRemainder 月の位相計算向け時刻情報(大余小余)
41
+ #
42
+ class LunarRemainder < Calculation::Cycle::AbstractRemainder
43
+ # @return [Integer] 統法(1日=8400分)
44
+ DAY = 8400
45
+ # @return [Integer] 分(1分=100秒)
46
+ MINUTE = 100
47
+
48
+ #
49
+ # 初期化
50
+ #
51
+ # @param [Integer] day 大余("日"に相当)
52
+ # @param [Integer] minute 小余("分"に相当)
53
+ # @param [Integer] second 秒
54
+ # @param [Integer] total 繰り上げなしの小余
55
+ #
56
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
57
+ super(base_day: DAY, base_mitune: MINUTE,
58
+ day: day, minute: minute, second: second, total: total)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/cycle/abstract_solar_term'
4
+ require_relative './remainder'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Senmyou
10
+ # :nodoc:
11
+ module Cycle
12
+ #
13
+ # SolarTerm 二十四節気
14
+ #
15
+ class SolarTerm < Calculation::Cycle::AbstractSolarTerm
16
+ # @return [Remainder] 気策(24分の1年)
17
+ SOLAR_TERM_AVERAGE = Remainder.new(day: 15, minute: 1835, second: 5)
18
+
19
+ #
20
+ # 初期化
21
+ #
22
+ # @param [Integer] index 連番
23
+ # @param [Remainder] remainder 時刻情報(大余小余)
24
+ #
25
+ def initialize(index: -1, remainder: Remainder.new)
26
+ super(index: index, remainder: remainder, average: SOLAR_TERM_AVERAGE)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -8,212 +8,216 @@ require_relative '../stella/winter_solstice'
8
8
  module Zakuro
9
9
  # :nodoc:
10
10
  module Senmyou
11
- # :reek:TooManyStatements { max_statements: 7 }
12
- # :reek:TooManyInstanceVariables { max_instance_variables: 7 }
13
-
14
- #
15
- # LunarPhase 月の位相
16
- #
17
- class LunarPhase
18
- #
19
- # QuarterMoon 弦
20
- #
21
- module QuarterMoon
22
- # @return [Remainder] 弦(1分=8秒)
23
- DEFAULT = Remainder.new(day: 7, minute: 3214, second: 2)
24
- # @return [Remainder] 弦(1分=100秒)
25
- BASE_HUNDRED = LunarRemainder.new(day: 7, minute: 3214, second: 25)
26
- end
27
-
28
- # @return [Logger] ロガー
29
- LOGGER = Logger.new(location: 'lunar_phase')
30
-
31
- # @return [Array<String>] 月内の弦
32
- PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
33
-
34
- # @return [Integer] 西暦年
35
- attr_reader :western_year
36
- # @return [Remainder]] 経
37
- attr_reader :average_remainder
38
- # @return [True] 初回計算
39
- # @return [False] 次回以降計算
40
- attr_reader :first
41
- # @return [SolarTerm] 二十四節気(入定気)
42
- attr_reader :solar_term
43
- # @return [Remainder] 入暦
44
- attr_reader :moon_remainder
45
- # @return [True] 進(遠地点より数える)
46
- # @return [False] 退(近地点より数える)
47
- attr_reader :is_forward
48
- # @return [Integer] 弦
49
- attr_reader :phase_index
11
+ # :nodoc:
12
+ module Monthly
13
+ # :reek:TooManyInstanceVariables { max_instance_variables: 7 }
14
+
15
+ #
16
+ # LunarPhase 月の位相
17
+ #
18
+ class LunarPhase
19
+ #
20
+ # QuarterMoon 弦
21
+ #
22
+ module QuarterMoon
23
+ # @return [Remainder] 弦(1分=8秒)
24
+ DEFAULT = Cycle::Remainder.new(day: 7, minute: 3214, second: 2)
25
+ # @return [Remainder] 弦(1分=100秒)
26
+ BASE_HUNDRED = Cycle::LunarRemainder.new(day: 7, minute: 3214, second: 25)
27
+ end
50
28
 
51
- #
52
- # 初期化
53
- #
54
- # @param [Integer] western_year 西暦年
55
- #
56
- def initialize(western_year:)
57
- @western_year = western_year
58
- #
59
- @average_remainder = WinterSolstice.calc_averaged_last_november_1st(
60
- western_year: @western_year
61
- )
62
- # 天正冬至
63
- winter_solstice_age = \
64
- WinterSolstice.calc_moon_age(western_year: @western_year)
65
- # 入定気
66
- @solar_term = SolarTerm.new(remainder: winter_solstice_age)
67
- # 入暦
68
- @moon_remainder = LunarRemainder.new(total: 0).add!(winter_solstice_age)
69
-
70
- @is_forward = false
71
- @first = true
72
-
73
- # 弦
74
- @phase_index = 0
75
- end
29
+ # @return [Output::Logger] ロガー
30
+ LOGGER = Output::Logger.new(location: 'lunar_phase')
31
+
32
+ # @return [Array<String>] 月内の弦
33
+ PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
34
+
35
+ # @return [Integer] 西暦年
36
+ attr_reader :western_year
37
+ # @return [Remainder]]
38
+ attr_reader :average_remainder
39
+ # @return [True] 初回計算
40
+ # @return [False] 次回以降計算
41
+ attr_reader :first
42
+ # @return [SolarTerm] 二十四節気(入定気)
43
+ attr_reader :solar_term
44
+ # @return [Remainder] 入暦
45
+ attr_reader :moon_remainder
46
+ # @return [True] 進(遠地点より数える)
47
+ # @return [False] 退(近地点より数える)
48
+ attr_reader :is_forward
49
+ # @return [Integer]
50
+ attr_reader :phase_index
51
+
52
+ #
53
+ # 初期化
54
+ #
55
+ # @param [Integer] western_year 西暦年
56
+ #
57
+ def initialize(western_year:)
58
+ @western_year = western_year
59
+ # 経
60
+ @average_remainder = WinterSolstice.calc_averaged_last_november_1st(
61
+ western_year: @western_year
62
+ )
63
+ # 天正閏余
64
+ winter_solstice_age = \
65
+ WinterSolstice.calc_moon_age(western_year: @western_year)
66
+ # 入定気
67
+ @solar_term = Cycle::SolarTerm.new(remainder: winter_solstice_age)
68
+ # 入暦
69
+ @moon_remainder = Cycle::LunarRemainder.new(total: 0).add!(winter_solstice_age)
70
+
71
+ @is_forward = false
72
+ @first = true
73
+
74
+ # 弦
75
+ @phase_index = 0
76
+ end
76
77
 
77
- #
78
- # 次の弦に進める
79
- #
80
- # @return [Remainder] 定朔
81
- #
82
- def next_phase
83
- adjusted = current_remainder
78
+ #
79
+ # 次の弦に進める
80
+ #
81
+ # @return [Remainder] 定朔
82
+ #
83
+ def next_phase
84
+ adjusted = current_remainder
84
85
 
85
- @first = false if @first
86
+ @first = false if @first
86
87
 
87
- add_quarter_moon_size
88
+ add_quarter_moon_size
88
89
 
89
- adjusted
90
- end
90
+ adjusted
91
+ end
91
92
 
92
- #
93
- # 次の月に進める
94
- # @note 進めた後の月の定朔ではなく、当月のものを返却する
95
- #
96
- # @return [Remainder] 当月初の定朔
97
- #
98
- def next_month
99
- result = nil
100
- PHASE_INDEXES.each_with_index do |_phase, index|
101
- adjust = next_phase
102
- result = adjust if index.zero?
93
+ #
94
+ # 次の月に進める
95
+ # @note 進めた後の月の定朔ではなく、当月のものを返却する
96
+ #
97
+ # @return [Remainder] 当月初の定朔
98
+ #
99
+ def next_month
100
+ result = nil
101
+ PHASE_INDEXES.each_with_index do |_phase, index|
102
+ adjust = next_phase
103
+ result = adjust if index.zero?
104
+ end
105
+
106
+ result
103
107
  end
104
108
 
105
- result
106
- end
109
+ private
110
+
111
+ #
112
+ # 次の弦に進める
113
+ #
114
+ # @return [Integer] 弦
115
+ #
116
+ def next_phase_index
117
+ @phase_index += 1
118
+ @phase_index = 0 if @phase_index >= PHASE_INDEXES.size
119
+ @phase_index
120
+ end
107
121
 
108
- private
122
+ #
123
+ # 朔月(月初)かを確認する
124
+ #
125
+ # @return [True] 朔月である
126
+ # @return [False] 朔月ではない
127
+ #
128
+ def first_phase?
129
+ @phase_index.zero?
130
+ end
109
131
 
110
- #
111
- # 次の弦に進める
112
- #
113
- # @return [Integer]
114
- #
115
- def next_phase_index
116
- @phase_index += 1
117
- @phase_index = 0 if @phase_index >= PHASE_INDEXES.size
118
- @phase_index
119
- end
132
+ #
133
+ # 朔月のみログ出力する
134
+ #
135
+ # @param [String] messages メッセージ(可変長)
136
+ #
137
+ def debug(*messages)
138
+ return unless first_phase?
120
139
 
121
- #
122
- # 朔月(月初)かを確認する
123
- #
124
- # @return [True] 朔月である
125
- # @return [False] 朔月ではない
126
- #
127
- def first_phase?
128
- @phase_index.zero?
129
- end
130
-
131
- #
132
- # 朔月のみログ出力する
133
- #
134
- # @param [String] messages メッセージ(可変長)
135
- #
136
- def debug(*messages)
137
- return unless first_phase?
140
+ LOGGER.debug(*messages)
141
+ end
138
142
 
139
- LOGGER.debug(*messages)
140
- end
143
+ # :reek:TooManyStatements { max_statements: 6 }
141
144
 
142
- #
143
- # 現在の定朔を取得する
144
- #
145
- # @return [Remainder] 定朔
146
- #
147
- def current_remainder
148
- debug('@average_remainder.format:' + @average_remainder.format)
145
+ #
146
+ # 現在の定朔を取得する
147
+ #
148
+ # @return [Remainder] 定朔
149
+ #
150
+ def current_remainder
151
+ debug("@average_remainder.format: #{@average_remainder.format}")
149
152
 
150
- sum = correction_value
151
- adjusted = @average_remainder.add(
152
- Remainder.new(day: 0, minute: sum, second: 0)
153
- )
154
- adjusted.up_on_new_moon!
153
+ sum = correction_value
154
+ adjusted = @average_remainder.add(
155
+ Cycle::Remainder.new(day: 0, minute: sum, second: 0)
156
+ )
157
+ adjusted.up_on_new_moon!
155
158
 
156
- debug("result: #{adjusted.format}")
159
+ debug("result: #{adjusted.format}")
157
160
 
158
- adjusted
159
- end
161
+ adjusted
162
+ end
160
163
 
161
- #
162
- # 補正値を得る
163
- #
164
- # @return [Integer] 補正値
165
- #
166
- def correction_value
167
- sun = correction_solar_value
168
- moon = correction_moon_value
164
+ #
165
+ # 補正値を得る
166
+ #
167
+ # @return [Integer] 補正値
168
+ #
169
+ def correction_value
170
+ sun = correction_solar_value
171
+ moon = correction_moon_value
169
172
 
170
- sum = sun + moon
173
+ sum = sun + moon
171
174
 
172
- debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
175
+ debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
173
176
 
174
- sum
175
- end
177
+ sum
178
+ end
176
179
 
177
- #
178
- # 太陽運動の補正値を得る
179
- #
180
- # @return [Integer] 太陽運動の補正値
181
- #
182
- def correction_solar_value
183
- @solar_term = SolarOrbit.calc_solar_term_by_remainder(
184
- solar_term: @solar_term
185
- )
186
- debug("@solar_term.remainder: #{@solar_term.remainder.format(form: '%d-%d.%d')}")
187
- debug("@solar_term.index: #{@solar_term.index}")
188
-
189
- SolarOrbit.calc_sun_orbit_value(solar_term: @solar_term)
190
- end
180
+ #
181
+ # 太陽運動の補正値を得る
182
+ #
183
+ # @return [Integer] 太陽運動の補正値
184
+ #
185
+ def correction_solar_value
186
+ @solar_term = SolarLocation.get(
187
+ solar_term: @solar_term
188
+ )
189
+ debug("@solar_term.remainder: #{@solar_term.remainder.format(form: '%d-%d.%d')}")
190
+ debug("@solar_term.index: #{@solar_term.index}")
191
+
192
+ SolarOrbit.calc_sun_orbit_value(solar_term: @solar_term)
193
+ end
191
194
 
192
- #
193
- # 月運動の補正値を得る
194
- #
195
- # @return [Integer] 月運動の補正値
196
- #
197
- def correction_moon_value
198
- @moon_remainder, @is_forward = \
199
- LunarOrbit.calc_moon_point(remainder: @moon_remainder,
200
- western_year: @western_year,
201
- is_forward: @is_forward,
202
- first: @first)
203
-
204
- debug("@moon_remainder.format: #{@moon_remainder.format}")
205
- debug("@is_forward: #{@is_forward}")
206
-
207
- LunarOrbit.calc_moon_orbit_value(remainder_month: @moon_remainder,
208
- is_forward: @is_forward)
209
- end
195
+ #
196
+ # 月運動の補正値を得る
197
+ #
198
+ # @return [Integer] 月運動の補正値
199
+ #
200
+ def correction_moon_value
201
+ @moon_remainder, @is_forward = \
202
+ LunarOrbit.calc_moon_point(remainder: @moon_remainder,
203
+ western_year: @western_year,
204
+ is_forward: @is_forward,
205
+ first: @first)
206
+
207
+ debug("@moon_remainder.format: #{@moon_remainder.format}")
208
+ debug("@is_forward: #{@is_forward}")
209
+
210
+ LunarOrbit.calc_moon_orbit_value(remainder_month: @moon_remainder,
211
+ is_forward: @is_forward)
212
+ end
210
213
 
211
- def add_quarter_moon_size
212
- @average_remainder.add!(QuarterMoon::DEFAULT)
213
- @solar_term.remainder.add!(QuarterMoon::DEFAULT)
214
- @moon_remainder.add!(QuarterMoon::BASE_HUNDRED)
214
+ def add_quarter_moon_size
215
+ @average_remainder.add!(QuarterMoon::DEFAULT)
216
+ @solar_term.remainder.add!(QuarterMoon::DEFAULT)
217
+ @moon_remainder.add!(QuarterMoon::BASE_HUNDRED)
215
218
 
216
- next_phase_index
219
+ next_phase_index
220
+ end
217
221
  end
218
222
  end
219
223
  end