zakuro 0.0.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +102 -42
  3. data/doc/operation.md +25 -0
  4. data/doc/operation/csv/month.csv +202 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/doc/operation/transfer.rb +77 -0
  7. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  8. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  9. data/lib/zakuro/calculation/base/year.rb +107 -0
  10. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +459 -0
  11. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  12. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  13. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  14. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  15. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  16. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  17. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  18. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  19. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  20. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  21. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  22. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  23. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  24. data/lib/zakuro/calculation/summary/single.rb +129 -0
  25. data/lib/zakuro/condition.rb +16 -13
  26. data/lib/zakuro/era/japan/gengou.rb +106 -0
  27. data/lib/zakuro/era/japan/gengou/parser.rb +167 -0
  28. data/lib/zakuro/era/japan/gengou/type.rb +178 -0
  29. data/lib/zakuro/era/japan/gengou/validator.rb +236 -0
  30. data/lib/zakuro/era/japan/reki.rb +91 -0
  31. data/lib/zakuro/era/{gengou → japan/yaml}/set-001-until-south.yaml +0 -0
  32. data/lib/zakuro/era/{gengou → japan/yaml}/set-002-from-north.yaml +0 -0
  33. data/lib/zakuro/era/{gengou → japan/yaml}/set-003-modern.yaml +0 -0
  34. data/lib/zakuro/era/western.rb +1 -1
  35. data/lib/zakuro/merchant.rb +2 -2
  36. data/lib/zakuro/operation/month/parser.rb +373 -0
  37. data/lib/zakuro/operation/month/type.rb +453 -0
  38. data/lib/zakuro/operation/month/validator.rb +802 -0
  39. data/lib/zakuro/operation/operation.rb +66 -0
  40. data/lib/zakuro/operation/yaml/month.yaml +6452 -0
  41. data/lib/zakuro/output/error.rb +7 -4
  42. data/lib/zakuro/output/logger.rb +50 -47
  43. data/lib/zakuro/output/response.rb +146 -143
  44. data/lib/zakuro/result/core.rb +52 -0
  45. data/lib/zakuro/result/data.rb +187 -0
  46. data/lib/zakuro/result/operation.rb +114 -0
  47. data/lib/zakuro/result/result.rb +37 -0
  48. data/lib/zakuro/{output → tools}/stringifier.rb +16 -9
  49. data/lib/zakuro/tools/typeof.rb +33 -0
  50. data/lib/zakuro/version.rb +1 -1
  51. data/lib/zakuro/version/abstract_version.rb +1 -1
  52. data/lib/zakuro/version/context.rb +23 -0
  53. data/lib/zakuro/version/senmyou/cycle/remainder.rb +63 -0
  54. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
  55. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +186 -182
  56. data/lib/zakuro/version/senmyou/range/annual_range.rb +167 -0
  57. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  58. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +6 -6
  59. data/lib/zakuro/version/senmyou/stella/solar_average.rb +103 -152
  60. data/lib/zakuro/version/senmyou/stella/solar_location.rb +213 -0
  61. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +3 -184
  62. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +4 -4
  63. data/lib/zakuro/version/version_class_resolver.rb +62 -0
  64. data/lib/zakuro/version_factory.rb +3 -3
  65. metadata +53 -24
  66. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  67. data/lib/zakuro/cycle/zodiac.rb +0 -103
  68. data/lib/zakuro/era/japan.rb +0 -664
  69. data/lib/zakuro/output/result.rb +0 -225
  70. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  71. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  72. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -205
  73. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  74. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -66
  75. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  76. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -122
  77. data/lib/zakuro/version/senmyou/summary/annual_range.rb +0 -187
  78. data/lib/zakuro/version/senmyou/summary/full_range.rb +0 -224
  79. data/lib/zakuro/version/senmyou/summary/specifier.rb +0 -100
@@ -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,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