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,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../era/western'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Monthly
11
+ #
12
+ # FirstDay 月初日(朔日)
13
+ #
14
+ class FirstDay
15
+ # @return [Western::Calendar] 西暦日
16
+ attr_reader :western_date
17
+ # @return [Remainder] 大余小余
18
+ attr_reader :remainder
19
+
20
+ #
21
+ # 初期化
22
+ #
23
+ # @param [Remainder] remainder 西暦日
24
+ # @param [Western::Calendar] western_date 大余小余
25
+ #
26
+ def initialize(western_date: Western::Calendar.new, remainder: Remainder.new)
27
+ # 西暦日
28
+ @western_date = western_date
29
+ # 大余小余
30
+ @remainder = remainder
31
+ end
32
+
33
+ #
34
+ # ディープコピー
35
+ #
36
+ # @param [FirstDay] obj 自身
37
+ #
38
+ def initialize_copy(obj)
39
+ @western_date = obj.western_date.clone
40
+ @remainder = obj.remainder.clone
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './month'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Monthly
11
+ #
12
+ # InitializedMonth 初期月情報
13
+ #
14
+ class InitializedMonth < Month
15
+ # @return [True] 昨年の月
16
+ # @return [False] 今年の月
17
+ # @note 冬至基準で1年データを作成するため昨年の11月-12月である可能性がある
18
+ attr_reader :is_last_year
19
+ # @return [Integer] 月齢(朔月、上弦、望月、下弦)
20
+ attr_reader :phase_index
21
+
22
+ # :reek:BooleanParameter And :reek:LongParameterList {max_params: 6}
23
+ # rubocop:disable Metrics/ParameterLists
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [Context] context 暦コンテキスト
29
+ # @param [MonthLabel] month_label 月表示名
30
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
31
+ # @param [FirstDay] first_day 月初日(朔日)
32
+ # @param [True, False] is_last_year 昨年の月/今年の月
33
+ # @param [Integer] phase_index 月齢(朔月、上弦、望月、下弦)
34
+ #
35
+ def initialize(context:, month_label: MonthLabel.new, solar_terms: [],
36
+ first_day: FirstDay.new, is_last_year: false, phase_index: -1)
37
+ super(context: context, month_label: month_label, solar_terms: solar_terms,
38
+ first_day: first_day)
39
+ @is_last_year = is_last_year
40
+ @phase_index = phase_index
41
+ end
42
+
43
+ # rubocop:enable Metrics/ParameterLists
44
+
45
+ # :reek:TooManyStatements { max_statements: 6 }
46
+
47
+ #
48
+ # 現在の二十四節気に合わせて月表示情報を書き換える
49
+ #
50
+ def rename_month_label_by_solar_term
51
+ return ArgumentError.new, 'solar term must not be empty.' if empty_solar_term?
52
+
53
+ even = even_term
54
+
55
+ is_many_days = month_label.is_many_days
56
+ if even.invalid?
57
+ @month_label = MonthLabel.new(
58
+ number: InitializedMonth.month_number_by_odd_term_index(odd_term.index),
59
+ leaped: true, is_many_days: is_many_days
60
+ )
61
+ return
62
+ end
63
+
64
+ @month_label = MonthLabel.new(
65
+ number: InitializedMonth.month_number_by_even_term_index(even.index),
66
+ leaped: false, is_many_days: is_many_days
67
+ )
68
+ end
69
+
70
+ #
71
+ # 中気の連番に合わせて月を返す
72
+ #
73
+ # @example
74
+ # 20: 9月
75
+ # 22: 10月
76
+ # 0: 11月
77
+ # 2: 12月
78
+ # 4: 1月
79
+ #
80
+ # @param [Integer] index 中気番号
81
+ #
82
+ # @return [Integer] 月
83
+ #
84
+ def self.month_number_by_even_term_index(index)
85
+ half_index = index / 2
86
+
87
+ # 11月、12月
88
+ return half_index + 11 if half_index < 2
89
+
90
+ # 1月~10月
91
+ half_index - 1
92
+ end
93
+
94
+ #
95
+ # 節気の連番に合わせて月を返す
96
+ #
97
+ # @param [Integer] index 節気番号
98
+ #
99
+ # @return [Integer] 月
100
+ #
101
+ def self.month_number_by_odd_term_index(index)
102
+ even_index = index - 1
103
+
104
+ month_number_by_even_term_index(even_index)
105
+ end
106
+
107
+ #
108
+ # 一ヶ月戻す
109
+ #
110
+ def back_to_last_month
111
+ @is_last_year = true if month_label.back_to_last_month
112
+ end
113
+
114
+ #
115
+ # 二十四節気の数を返す
116
+ #
117
+ # @return [Integer] 二十四節気の数
118
+ #
119
+ def solar_term_size
120
+ solar_terms.size
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,187 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './first_day'
4
+ require_relative './month_label'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Monthly
12
+ #
13
+ # Month 月情報
14
+ #
15
+ class Month
16
+ # @return [Context] 暦コンテキスト
17
+ attr_reader :context
18
+ # @return [MonthLabel] 月表示名
19
+ attr_reader :month_label
20
+ # @return [FirstDay] 月初日(朔日)
21
+ attr_reader :first_day
22
+ # @return [Array<SolarTerm>] 二十四節気
23
+ attr_reader :solar_terms
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [Context] context 暦コンテキスト
29
+ # @param [MonthLabel] month_label 月表示名
30
+ # @param [FirstDay] first_day 月初日(朔日)
31
+ # @param [Array<SolarTerm>] solar_terms 二十四節気
32
+ #
33
+ def initialize(context:, month_label: MonthLabel.new, first_day: FirstDay.new,
34
+ solar_terms: [])
35
+ @context = context
36
+ @month_label = month_label
37
+ @first_day = first_day
38
+ @solar_terms = solar_terms
39
+ end
40
+
41
+ #
42
+ # 中気なしは閏月とする
43
+ #
44
+ def eval_leaped
45
+ leaped = even_term.invalid?
46
+
47
+ @month_label = MonthLabel.new(number: number, is_many_days: many_days?, leaped: leaped)
48
+ end
49
+
50
+ #
51
+ # 月初日の西暦日を返す
52
+ #
53
+ # @return [Western::Calendar] 西暦日
54
+ #
55
+ def western_date
56
+ @first_day.western_date
57
+ end
58
+
59
+ #
60
+ # 月初日の大余小余を返す
61
+ #
62
+ # @return [Remainder] 大余小余
63
+ #
64
+ def remainder
65
+ @first_day.remainder
66
+ end
67
+
68
+ #
69
+ # 月の大小を返す
70
+ #
71
+ # @return [True] 大の月(30日)
72
+ # @return [False] 小の月(29日)
73
+ #
74
+ def many_days?
75
+ @month_label.is_many_days
76
+ end
77
+
78
+ #
79
+ # 月の日数を返す
80
+ #
81
+ # @return [Integer] 日数
82
+ #
83
+ def days
84
+ @month_label.days
85
+ end
86
+
87
+ #
88
+ # 月の名前(大小)を返す
89
+ #
90
+ # @return [String] 月の名前(大小)
91
+ #
92
+ def days_name
93
+ @month_label.days_name
94
+ end
95
+
96
+ #
97
+ # 月を返す
98
+ #
99
+ # @return [Integer] 月(xx月のxx)
100
+ #
101
+ def number
102
+ @month_label.number
103
+ end
104
+
105
+ #
106
+ # 閏を返す
107
+ #
108
+ # @return [True] 閏月
109
+ # @return [False] 平月
110
+ #
111
+ def leaped?
112
+ @month_label.leaped
113
+ end
114
+
115
+ #
116
+ # 次月の大余から月の日数を定める
117
+ #
118
+ # @param [Integer] next_month_day 次月の大余
119
+ #
120
+ def eval_many_days(next_month_day:)
121
+ is_many_days = remainder.same_remainder_divided_by_ten?(other: next_month_day)
122
+
123
+ @month_label = MonthLabel.new(
124
+ number: number, is_many_days: is_many_days, leaped: leaped?
125
+ )
126
+ end
127
+
128
+ #
129
+ # 二十四節気が未設定かどうかを検証する
130
+ #
131
+ # @return [True] 設定なし
132
+ # @return [False] 設定あり
133
+ #
134
+ def empty_solar_term?
135
+ @solar_terms.empty?
136
+ end
137
+
138
+ #
139
+ # 中気を返す
140
+ #
141
+ # @return [SolarTerm] 中気
142
+ #
143
+ def even_term
144
+ @solar_terms.each do |term|
145
+ return term if term.index.even?
146
+ end
147
+
148
+ context.resolver.solar_term.new
149
+ end
150
+
151
+ #
152
+ # 節気を返す
153
+ #
154
+ # @return [SolarTerm] 節気
155
+ #
156
+ def odd_term
157
+ @solar_terms.each do |term|
158
+ return term if term.index.odd?
159
+ end
160
+
161
+ context.resolver.solar_term.new
162
+ end
163
+
164
+ #
165
+ # 二十四節気を追加する
166
+ #
167
+ # @param [SolarTerm] term 二十四節気
168
+ #
169
+ def add_term(term:)
170
+ @solar_terms.push(term)
171
+ end
172
+
173
+ #
174
+ # 同一の月情報かを検証する
175
+ #
176
+ # @param [Month] other 他の月情報
177
+ #
178
+ # @return [True] 同一の月
179
+ # @return [False] 異なる月
180
+ #
181
+ def same?(other:)
182
+ number == other.number && leaped? == other.leaped?
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Monthly
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
88
+ end