zakuro 0.1.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) 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 +484 -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 +78 -0
  22. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +71 -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/era/japan/reki.rb +1 -1
  29. data/lib/zakuro/merchant.rb +2 -2
  30. data/lib/zakuro/output/error.rb +7 -6
  31. data/lib/zakuro/output/logger.rb +50 -49
  32. data/lib/zakuro/output/response.rb +145 -144
  33. data/lib/zakuro/tools/typeof.rb +2 -2
  34. data/lib/zakuro/version.rb +1 -1
  35. data/lib/zakuro/version/abstract_version.rb +1 -1
  36. data/lib/zakuro/version/context.rb +23 -0
  37. data/lib/zakuro/version/daien/const/number.rb +55 -0
  38. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  39. data/lib/zakuro/version/daien/cycle/remainder.rb +59 -0
  40. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  41. data/lib/zakuro/version/daien/daien.rb +36 -0
  42. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  43. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  44. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  45. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  46. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  47. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  48. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  49. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  50. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  51. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  52. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  53. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  54. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  55. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  56. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  57. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  58. data/lib/zakuro/version/gihou/cycle/remainder.rb +56 -0
  59. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  60. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  61. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  62. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  63. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  64. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  65. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  66. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  67. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  68. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  69. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  70. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  71. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  72. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  73. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  74. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  75. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  76. data/lib/zakuro/version/senmyou/const/remainder.rb +47 -0
  77. data/lib/zakuro/version/senmyou/cycle/remainder.rb +56 -0
  78. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +34 -0
  79. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +80 -195
  80. data/lib/zakuro/version/senmyou/range/annual_range.rb +25 -145
  81. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  82. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  83. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  84. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +87 -0
  85. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +67 -0
  86. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  87. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  88. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  89. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  90. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  91. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  92. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  93. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  94. data/lib/zakuro/version/version_class_resolver.rb +70 -0
  95. data/lib/zakuro/version_factory.rb +3 -3
  96. metadata +83 -28
  97. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  98. data/lib/zakuro/cycle/zodiac.rb +0 -103
  99. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  100. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  101. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  102. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  103. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -148
  104. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  105. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  106. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -119
  107. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  108. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  109. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -196
  110. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -194
  111. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  112. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  113. data/lib/zakuro/version/senmyou/range/western_date_allocation.rb +0 -68
  114. data/lib/zakuro/version/senmyou/range/year_boundary.rb +0 -138
  115. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  116. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  117. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  118. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  119. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  120. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  121. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
  122. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -1,181 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './first_day'
4
- require_relative './month_label'
5
-
6
- # TODO: moduleでMonthly とする(全暦むけに共通化したあと)
7
-
8
- # :nodoc:
9
- module Zakuro
10
- # :nodoc:
11
- module Senmyou
12
- #
13
- # Month 月情報
14
- #
15
- class Month
16
- # @return [MonthLabel] 月表示名
17
- attr_reader :month_label
18
- # @return [FirstDay] 月初日(朔日)
19
- attr_reader :first_day
20
- # @return [Array<SolarTerm>] 二十四節気
21
- attr_reader :solar_terms
22
-
23
- #
24
- # 初期化
25
- #
26
- # @param [MonthLabel] month_label 月表示名
27
- # @param [FirstDay] first_day 月初日(朔日)
28
- # @param [Array<SolarTerm>] solar_terms 二十四節気
29
- #
30
- def initialize(month_label: MonthLabel.new, first_day: FirstDay.new, solar_terms: [])
31
- @month_label = month_label
32
- @first_day = first_day
33
- @solar_terms = solar_terms
34
- end
35
-
36
- #
37
- # 中気なしは閏月とする
38
- #
39
- def eval_leaped
40
- leaped = even_term.invalid?
41
-
42
- @month_label = MonthLabel.new(number: number, is_many_days: many_days?, leaped: leaped)
43
- end
44
-
45
- #
46
- # 月初日の西暦日を返す
47
- #
48
- # @return [Western::Calendar] 西暦日
49
- #
50
- def western_date
51
- @first_day.western_date
52
- end
53
-
54
- #
55
- # 月初日の大余小余を返す
56
- #
57
- # @return [Remainder] 大余小余
58
- #
59
- def remainder
60
- @first_day.remainder
61
- end
62
-
63
- #
64
- # 月の大小を返す
65
- #
66
- # @return [True] 大の月(30日)
67
- # @return [False] 小の月(29日)
68
- #
69
- def many_days?
70
- @month_label.is_many_days
71
- end
72
-
73
- #
74
- # 月の日数を返す
75
- #
76
- # @return [Integer] 日数
77
- #
78
- def days
79
- @month_label.days
80
- end
81
-
82
- #
83
- # 月の名前(大小)を返す
84
- #
85
- # @return [String] 月の名前(大小)
86
- #
87
- def days_name
88
- @month_label.days_name
89
- end
90
-
91
- #
92
- # 月を返す
93
- #
94
- # @return [Integer] 月(xx月のxx)
95
- #
96
- def number
97
- @month_label.number
98
- end
99
-
100
- #
101
- # 閏を返す
102
- #
103
- # @return [True] 閏月
104
- # @return [False] 平月
105
- #
106
- def leaped?
107
- @month_label.leaped
108
- end
109
-
110
- #
111
- # 次月の大余から月の日数を定める
112
- #
113
- # @param [Integer] next_month_day 次月の大余
114
- #
115
- def eval_many_days(next_month_day:)
116
- is_many_days = remainder.same_remainder_divided_by_ten?(other: next_month_day)
117
-
118
- @month_label = MonthLabel.new(
119
- number: number, is_many_days: is_many_days, leaped: leaped?
120
- )
121
- end
122
-
123
- #
124
- # 二十四節気が未設定かどうかを検証する
125
- #
126
- # @return [True] 設定なし
127
- # @return [False] 設定あり
128
- #
129
- def empty_solar_term?
130
- @solar_terms.empty?
131
- end
132
-
133
- #
134
- # 中気を返す
135
- #
136
- # @return [SolarTerm] 中気
137
- #
138
- def even_term
139
- @solar_terms.each do |term|
140
- return term if term.index.even?
141
- end
142
-
143
- SolarTerm.new
144
- end
145
-
146
- #
147
- # 節気を返す
148
- #
149
- # @return [SolarTerm] 節気
150
- #
151
- def odd_term
152
- @solar_terms.each do |term|
153
- return term if term.index.odd?
154
- end
155
-
156
- SolarTerm.new
157
- end
158
-
159
- #
160
- # 二十四節気を追加する
161
- #
162
- # @param [SolarTerm] term 二十四節気
163
- #
164
- def add_term(term:)
165
- @solar_terms.push(term)
166
- end
167
-
168
- #
169
- # 同一の月情報かを検証する
170
- #
171
- # @param [Month] other 他の月情報
172
- #
173
- # @return [True] 同一の月
174
- # @return [False] 異なる月
175
- #
176
- def same?(other:)
177
- number == other.number && leaped? == other.leaped?
178
- end
179
- end
180
- end
181
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # TODO: moduleでMonthly とする(全暦むけに共通化したあと)
4
-
5
- # :nodoc:
6
- module Zakuro
7
- # :nodoc:
8
- module Senmyou
9
- #
10
- # MonthLabel 月表示情報
11
- #
12
- class MonthLabel
13
- # @return [True] 大の月(30日)
14
- # @return [False] 小の月(29日)
15
- attr_reader :is_many_days
16
- # @return [Integer] 月(xx月のxx)
17
- attr_reader :number
18
- # @return [True] 閏月
19
- # @return [False] 平月
20
- attr_reader :leaped
21
-
22
- # :reek:ControlParameter and :reek:BooleanParameter
23
-
24
- #
25
- # 初期化
26
- #
27
- # @param [Integer] number 月(xx月のxx)
28
- # @param [True, False] is_many_days 月の大小
29
- # @param [True, False] leaped 閏月/平月
30
- #
31
- def initialize(number: -1, is_many_days: false, leaped: false)
32
- # 月の大小
33
- @is_many_days = is_many_days
34
- # 月
35
- @number = number
36
- # 閏
37
- @leaped = leaped
38
- end
39
-
40
- #
41
- # 月の日数を返す
42
- #
43
- # @return [Integer] 日数
44
- #
45
- def days
46
- @is_many_days ? 30 : 29
47
- end
48
-
49
- #
50
- # 月の名前(大小)を返す
51
- #
52
- # @return [String] 月の名前(大小)
53
- #
54
- def days_name
55
- @is_many_days ? '大' : '小'
56
- end
57
-
58
- #
59
- # 一ヶ月戻す
60
- #
61
- # @return [True] 昨年
62
- # @return [False] 今年
63
- #
64
- def back_to_last_month
65
- @number -= 1
66
-
67
- return false if @number.positive?
68
-
69
- @number = 12
70
-
71
- true
72
- end
73
-
74
- #
75
- # 同一の月情報かを検証する
76
- #
77
- # @param [Month] other 他の月情報
78
- #
79
- # @return [True] 同一の月
80
- # @return [False] 異なる月
81
- #
82
- def same?(other:)
83
- @number == other.number && @leaped == other.leaped
84
- end
85
- end
86
- end
87
- end
@@ -1,196 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './month'
4
- require_relative '../../../operation/operation'
5
-
6
- # :nodoc:
7
- module Zakuro
8
- # :nodoc:
9
- module Senmyou
10
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
11
-
12
- #
13
- # OperatedMonth 月情報(運用)
14
- #
15
- class OperatedMonth < Month
16
- # @return [Operation::MonthHistory] 変更履歴(月)
17
- attr_reader :history
18
- # @return [OperatedSolarTerms] 運用時二十四節気
19
- attr_reader :operated_solar_terms
20
-
21
- #
22
- # 初期化
23
- #
24
- # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
25
- # @param [MonthLabel] month_label 月表示名
26
- # @param [FirstDay] first_day 月初日(朔日)
27
- # @param [Array<SolarTerm>] solar_terms 二十四節気
28
- # @param [Operation::MonthHistory] history 変更履歴(月)
29
- #
30
- def initialize(operated_solar_terms:, month_label: MonthLabel.new, first_day: FirstDay.new,
31
- solar_terms: [], history: Operation::MonthHistory.new)
32
- super(month_label: month_label, first_day: first_day, solar_terms: solar_terms)
33
- @history = history
34
- @operated_solar_terms = operated_solar_terms
35
- end
36
-
37
- #
38
- # 書き換える
39
- #
40
- def rewrite
41
- rewrite_month
42
- rewrite_solar_terms
43
- rewrite_first_day
44
- end
45
-
46
- #
47
- # 月ごとの差分で書き換える
48
- #
49
- def rewrite_month
50
- diff = history.diffs.month
51
-
52
- @month_label = MonthLabel.new(
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
- )
62
- )
63
- end
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
-
75
- #
76
- # 二十四節気ごとの差分で書き換える
77
- #
78
- def rewrite_solar_terms
79
- matched, operated_solar_term = @operated_solar_terms.get(
80
- western_date: first_day.western_date
81
- )
82
-
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
- )
89
- end
90
-
91
- #
92
- # <Description>
93
- #
94
- # @param [<Type>] operated_solar_term <description>
95
- # @param [Array<SolarTerm>] solar_terms 二十四節気
96
- #
97
- # @return [Array<SolarTerm>] 二十四節気
98
- #
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)
104
-
105
- return result if used_solar_term?(index: index, solar_terms: solar_terms)
106
-
107
- result.push(operated_solar_term)
108
-
109
- result
110
- end
111
-
112
- # :reek:ControlParameter
113
-
114
- #
115
- # 二十四節気が使用されているか
116
- #
117
- # @param [Integer] index 二十四節気番号
118
- # @param [Array<SolarTerm>] solar_terms 二十四節気
119
- #
120
- # @return [True] 使用
121
- # @return [False] 未使用
122
- #
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
127
-
128
- false
129
- end
130
-
131
- # :reek:ControlParameter
132
-
133
- #
134
- # 対象の二十四節気を除外する
135
- #
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
145
-
146
- result.push(solar_term)
147
- end
148
-
149
- result
150
- end
151
-
152
- #
153
- # 月初日ごとの差分で書き換える
154
- #
155
- def rewrite_first_day
156
- diffs = @history.diffs
157
- return if diffs.invalid_days?
158
-
159
- days = diffs.days
160
-
161
- @first_day = FirstDay.new(
162
- western_date: rewrite_western_date(days: days),
163
- remainder: rewrite_remainder(days: days)
164
- )
165
- end
166
-
167
- #
168
- # 月初日の大余小余を日差分で書き換える
169
- #
170
- # @param [Integer] days 日差分
171
- #
172
- # @return [Remainder] 月初日の大余小余
173
- #
174
- def rewrite_remainder(days:)
175
- remainder = first_day.remainder.clone
176
- remainder.add!(Remainder.new(day: days, minute: 0, second: 0))
177
-
178
- remainder
179
- end
180
-
181
- #
182
- # 月初日の西暦日を日差分で書き換える
183
- #
184
- # @param [Integer] days 日差分
185
- #
186
- # @return [Western::Calendar] 月初日の西暦日
187
- #
188
- def rewrite_western_date(days:)
189
- western_date = first_day.western_date.clone
190
- western_date += days
191
-
192
- western_date
193
- end
194
- end
195
- end
196
- end