zakuro 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  3. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  4. data/lib/zakuro/calculation/base/year.rb +107 -0
  5. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +471 -0
  6. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  7. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  10. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  11. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  12. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  13. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  14. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  15. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  16. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  17. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  18. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  19. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  20. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  21. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +76 -0
  22. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +52 -0
  23. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  24. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  25. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  26. data/lib/zakuro/calculation/summary/single.rb +129 -0
  27. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  28. data/lib/zakuro/merchant.rb +2 -2
  29. data/lib/zakuro/operation/month/parser.rb +1 -1
  30. data/lib/zakuro/operation/month/type.rb +5 -10
  31. data/lib/zakuro/output/error.rb +7 -6
  32. data/lib/zakuro/output/logger.rb +50 -49
  33. data/lib/zakuro/output/response.rb +145 -144
  34. data/lib/zakuro/tools/typeof.rb +2 -2
  35. data/lib/zakuro/version.rb +1 -1
  36. data/lib/zakuro/version/abstract_version.rb +1 -1
  37. data/lib/zakuro/version/context.rb +23 -0
  38. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  39. data/lib/zakuro/version/gihou/const/remainder.rb +56 -0
  40. data/lib/zakuro/version/gihou/cycle/remainder.rb +61 -0
  41. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  42. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  43. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  44. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  45. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  46. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  47. data/lib/zakuro/version/gihou/stella/lunar/location.rb +86 -0
  48. data/lib/zakuro/version/gihou/stella/lunar/value.rb +74 -0
  49. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  50. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  51. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  52. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  53. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  54. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  55. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  56. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  57. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  58. data/lib/zakuro/version/senmyou/const/remainder.rb +49 -0
  59. data/lib/zakuro/version/senmyou/cycle/remainder.rb +61 -0
  60. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +34 -0
  61. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +80 -195
  62. data/lib/zakuro/version/senmyou/range/annual_range.rb +25 -170
  63. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  64. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  65. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  66. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +93 -0
  67. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -0
  68. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  69. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  70. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  71. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  72. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  73. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  74. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  75. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  76. data/lib/zakuro/version/version_class_resolver.rb +66 -0
  77. data/lib/zakuro/version_factory.rb +2 -2
  78. metadata +64 -24
  79. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  80. data/lib/zakuro/cycle/zodiac.rb +0 -103
  81. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  82. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  83. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  84. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  85. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -86
  86. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  87. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  88. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -48
  89. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  90. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  91. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -167
  92. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -324
  93. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  94. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  95. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  96. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  97. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -214
  98. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -394
  99. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  100. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './abstract_remainder'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Cycle
11
+ #
12
+ # AbstractSolarTerm 二十四節気
13
+ #
14
+ class AbstractSolarTerm
15
+ # @return [Integer] 連番
16
+ attr_reader :index
17
+ # @return [AbstractRemainder] 時刻情報(大余小余)
18
+ attr_reader :remainder
19
+ # @return [AbstractRemainder] 気策(24分の1年)
20
+ attr_reader :average
21
+
22
+ # @return [Hash<Integer, Symbol>] 順序
23
+ ORDER = {
24
+ 0 => :touji,
25
+ 1 => :shoukan,
26
+ 2 => :daikan,
27
+ 3 => :risshun,
28
+ 4 => :usui,
29
+ 5 => :keichitsu,
30
+ 6 => :shunbun,
31
+ 7 => :seimei,
32
+ 8 => :kokuu,
33
+ 9 => :rikka,
34
+ 10 => :shouman,
35
+ 11 => :boushu,
36
+ 12 => :geshi,
37
+ 13 => :shousho,
38
+ 14 => :taisho,
39
+ 15 => :risshuu,
40
+ 16 => :shosho,
41
+ 17 => :hakuro,
42
+ 18 => :shuubun,
43
+ 19 => :kanro,
44
+ 20 => :soukou,
45
+ 21 => :rittou,
46
+ 22 => :shousetsu,
47
+ 23 => :taisetsu
48
+ }.freeze
49
+
50
+ #
51
+ # 初期化
52
+ #
53
+ # @param [Integer] index 連番
54
+ # @param [AbstractRemainder] remainder 時刻情報(大余小余)
55
+ #
56
+ def initialize(index: -1, remainder: AbstractRemainder.new,
57
+ average: AbstractRemainder.new)
58
+ @index = index
59
+ @remainder = remainder
60
+ @average = average
61
+ end
62
+
63
+ #
64
+ # 不正かどうか検証する
65
+ #
66
+ # @return [True] 正しくない
67
+ # @return [False] 正しい
68
+ #
69
+ def invalid?
70
+ (@index == -1 || @remainder.invalid?)
71
+ end
72
+
73
+ #
74
+ # データなしかを検証する
75
+ #
76
+ # @return [True] データなし
77
+ # @return [False] データあり
78
+ #
79
+ def empty?
80
+ (@index == -1 && @remainder.invalid?)
81
+ end
82
+
83
+ #
84
+ # 有効な二十四節気番号か
85
+ #
86
+ # @param [Integer] index 連番
87
+ #
88
+ # @return [True] 有効
89
+ # @return [False] 無効
90
+ #
91
+ def self.index?(index)
92
+ result = ORDER.fetch(index, -1)
93
+
94
+ result != -1
95
+ end
96
+
97
+ #
98
+ # 次の二十四節気に進める
99
+ #
100
+ def next_term!
101
+ @remainder = next_term
102
+ end
103
+
104
+ #
105
+ # 次の二十四節気に進める
106
+ #
107
+ def next_term
108
+ @index += 1
109
+ @index = 0 if @index >= ORDER.size
110
+
111
+ @remainder.add(@average)
112
+ end
113
+
114
+ #
115
+ # 指定した連番の二十四節気まで進める
116
+ #
117
+ # @param [Integer] index 連番
118
+ #
119
+ def next_by_index(index)
120
+ return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index)
121
+
122
+ loop do
123
+ return if @index == index
124
+
125
+ next!
126
+ end
127
+ end
128
+
129
+ #
130
+ # 指定した連番の二十四節気まで戻す
131
+ #
132
+ # @param [Integer] index 連番
133
+ #
134
+ def prev_by_index(index)
135
+ return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index)
136
+
137
+ loop do
138
+ return if @index == index
139
+
140
+ prev_term!
141
+ end
142
+ end
143
+
144
+ #
145
+ # 前の二十四節気に戻る
146
+ #
147
+ def prev_term!
148
+ @remainder = prev_term
149
+ end
150
+
151
+ #
152
+ # 前の二十四節気に戻る
153
+ #
154
+ def prev_term
155
+ @index -= 1
156
+ @index = 23 if @index.negative?
157
+
158
+ @remainder.sub(@average)
159
+ end
160
+
161
+ #
162
+ # ディープコピー
163
+ #
164
+ # @param [SolarTerm] obj 自身
165
+ #
166
+ def initialize_copy(obj)
167
+ @index = obj.index.clone
168
+ @remainder = obj.remainder.clone
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Cycle
9
+ #
10
+ # Zodiac 十干十二支
11
+ #
12
+ module Zodiac
13
+ # @return [Hash<Integer, String>] 十干十二支
14
+ ZODIAC_NAME_PATTERNS = {
15
+ 0 => '甲子', # きのえね
16
+ 1 => '乙丑', # きのとうし
17
+ 2 => '丙寅', # ひのえとら
18
+ 3 => '丁卯', # ひのとう
19
+ 4 => '戊辰', # つちのえたつ
20
+ 5 => '己巳', # つちのとみ
21
+ 6 => '庚午', # かのえうま
22
+ 7 => '辛未', # かのとひつじ
23
+ 8 => '壬申', # みずのえさる
24
+ 9 => '癸酉', # みずのととり
25
+ 10 => '甲戌', # きのえいぬ
26
+ 11 => '乙亥', # きのとい
27
+ 12 => '丙子', # ひのえね
28
+ 13 => '丁丑', # ひのとうし
29
+ 14 => '戊寅', # つちのえとら
30
+ 15 => '己卯', # つちのとう
31
+ 16 => '庚辰', # かのえたつ
32
+ 17 => '辛巳', # かのとみ
33
+ 18 => '壬午', # みずのえうま
34
+ 19 => '癸未', # みずのとひつじ
35
+ 20 => '甲申', # きのえさる
36
+ 21 => '乙酉', # きのととり
37
+ 22 => '丙戌', # ひのえいぬ
38
+ 23 => '丁亥', # ひのとい
39
+ 24 => '戊子', # つちのえね
40
+ 25 => '己丑', # つちのとうし
41
+ 26 => '庚寅', # かのえとら
42
+ 27 => '辛卯', # かのとう
43
+ 28 => '壬辰', # みずのえたつ
44
+ 29 => '癸巳', # みずのとみ
45
+ 30 => '甲午', # きのえうま
46
+ 31 => '乙未', # きのとひつじ
47
+ 32 => '丙申', # ひのえさる
48
+ 33 => '丁酉', # ひのととり
49
+ 34 => '戊戌', # つちのえいぬ
50
+ 35 => '己亥', # つちのとい
51
+ 36 => '庚子', # かのえね
52
+ 37 => '辛丑', # かのとうし
53
+ 38 => '壬寅', # みずのえとら
54
+ 39 => '癸卯', # みずのとう
55
+ 40 => '甲辰', # きのえたつ
56
+ 41 => '乙巳', # きのとみ
57
+ 42 => '丙午', # ひのえうま
58
+ 43 => '丁未', # ひのとひつじ
59
+ 44 => '戊申', # つちのえさる
60
+ 45 => '己酉', # つちのととり
61
+ 46 => '庚戌', # かのえいぬ
62
+ 47 => '辛亥', # かのとい
63
+ 48 => '壬子', # みずのえね
64
+ 49 => '癸丑', # みずのとうし
65
+ 50 => '甲寅', # きのえとら
66
+ 51 => '乙卯', # きのとう
67
+ 52 => '丙辰', # ひのえたつ
68
+ 53 => '丁巳', # ひのとみ
69
+ 54 => '戊午', # つちのえうま
70
+ 55 => '己未', # つちのとひつじ
71
+ 56 => '庚申', # かのえさる
72
+ 57 => '辛酉', # かのととり
73
+ 58 => '壬戌', # みずのえいぬ
74
+ 59 => '癸亥' # みずのとい
75
+ }.freeze
76
+
77
+ # @return [Integer] 組み合わせ数
78
+ LENGTH = ZODIAC_NAME_PATTERNS.length
79
+
80
+ #
81
+ # 大余を十干十二支に変換する
82
+ #
83
+ # @param [Integer] day 大余
84
+ #
85
+ # @return [String] 十干十二支
86
+ #
87
+ def self.day_name(day:)
88
+ index = day % LENGTH
89
+
90
+ ZODIAC_NAME_PATTERNS[index]
91
+ end
92
+
93
+ #
94
+ # 西暦年を十干十二支に変換する
95
+ #
96
+ # @param [Integer] western_year 西暦年
97
+ #
98
+ # @return [String] 十干十二支
99
+ #
100
+ def self.year_name(western_year: 0)
101
+ ZODIAC_NAME_PATTERNS[(western_year - 4) % LENGTH]
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../output/logger'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Monthly
11
+ #
12
+ # AbstractLunarPhase 月の位相
13
+ #
14
+ class AbstractLunarPhase
15
+ # @return [Output::Logger] ロガー
16
+ LOGGER = Output::Logger.new(location: 'lunar_phase')
17
+
18
+ # @return [Array<String>] 月内の弦
19
+ PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
20
+
21
+ # @return [Cycle::AbstractRemainder] 経
22
+ attr_reader :average_remainder
23
+ # @return [Solar::AbstractLocation] 入定気
24
+ attr_reader :solar_location
25
+ # @return [Lunar::AbstractLocation] 入暦
26
+ attr_reader :lunar_location
27
+ # @return [Integer] 弦の位置
28
+ attr_reader :index
29
+
30
+ #
31
+ # 初期化
32
+ #
33
+ # @param [Cycle::AbstractRemainder] quater 弦
34
+ # @param [Solar::AbstractLocation] average_remainder 経
35
+ # @param [Solar::AbstractLocation] solar_location 入定気
36
+ # @param [Lunar::AbstractLocation] lunar_location 入暦
37
+ #
38
+ def initialize(quater:, average_remainder:, solar_location:, lunar_location:)
39
+ # 弦
40
+ @quarter = quater
41
+ # 経
42
+ @average_remainder = average_remainder
43
+ # 入定気
44
+ @solar_location = solar_location
45
+ # 入暦
46
+ @lunar_location = lunar_location
47
+
48
+ # 弦の位置
49
+ @index = 0
50
+ end
51
+
52
+ #
53
+ # 次の弦に進める
54
+ #
55
+ # @return [Remainder] 定朔
56
+ #
57
+ def next_phase
58
+ adjusted = current_remainder
59
+
60
+ add_quarter_moon_size
61
+
62
+ adjusted
63
+ end
64
+
65
+ #
66
+ # 次の月に進める
67
+ # @note 進めた後の月の定朔ではなく、当月のものを返却する
68
+ #
69
+ # @return [Remainder] 当月初の定朔
70
+ #
71
+ def next_month
72
+ result = nil
73
+ PHASE_INDEXES.each_with_index do |_phase, index|
74
+ adjust = next_phase
75
+ result = adjust if index.zero?
76
+ end
77
+
78
+ result
79
+ end
80
+
81
+ private
82
+
83
+ #
84
+ # 次の弦に進める
85
+ #
86
+ # @return [Integer] 弦
87
+ #
88
+ def next_index
89
+ @index += 1
90
+ @index = 0 if @index >= PHASE_INDEXES.size
91
+ @index
92
+ end
93
+
94
+ #
95
+ # 朔月(月初)であるか
96
+ #
97
+ # @return [True] 朔月である
98
+ # @return [False] 朔月ではない
99
+ #
100
+ def first_phase?
101
+ @index.zero?
102
+ end
103
+
104
+ #
105
+ # 朔月のみログ出力する
106
+ #
107
+ # @param [String] messages メッセージ(可変長)
108
+ #
109
+ def debug(*messages)
110
+ # 全ての弦を対象にするためコメントアウトする
111
+ # return unless first_phase?
112
+
113
+ LOGGER.debug(*messages)
114
+ end
115
+
116
+ #
117
+ # 現在の定朔を取得する
118
+ #
119
+ # @return [Remainder] 定朔
120
+ #
121
+ def current_remainder
122
+ # abstract
123
+ end
124
+
125
+ #
126
+ # 補正値を得る
127
+ #
128
+ # @return [Integer] 補正値
129
+ #
130
+ def correction_value
131
+ sun = correction_solar_value
132
+ moon = correction_moon_value
133
+
134
+ sum = sun + moon
135
+
136
+ debug("sun: #{sun}", "moon: #{moon}", "sun + moon : #{sum}")
137
+
138
+ sum
139
+ end
140
+
141
+ #
142
+ # 太陽運動の補正値を得る
143
+ #
144
+ # @return [Integer] 太陽運動の補正値
145
+ #
146
+ def correction_solar_value
147
+ # abstract
148
+ end
149
+
150
+ #
151
+ # 月運動の補正値を得る
152
+ #
153
+ # @return [Integer] 月運動の補正値
154
+ #
155
+ def correction_moon_value
156
+ # abstract
157
+ end
158
+
159
+ def add_quarter_moon_size
160
+ @average_remainder.add!(@quarter)
161
+ @solar_location.add_quarter
162
+ @lunar_location.add_quarter
163
+
164
+ next_index
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end