zakuro 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -12
  3. data/doc/operation/csv/month.csv +202 -202
  4. data/doc/operation/operation.xlsx +0 -0
  5. data/doc/operation/transfer.rb +6 -2
  6. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  7. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  8. data/lib/zakuro/calculation/base/year.rb +107 -0
  9. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +471 -0
  10. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  11. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  12. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  13. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  14. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  15. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  16. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  17. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  18. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  19. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  20. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  21. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  22. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  23. data/lib/zakuro/calculation/summary/single.rb +129 -0
  24. data/lib/zakuro/condition.rb +16 -13
  25. data/lib/zakuro/era/japan/gengou/parser.rb +1 -3
  26. data/lib/zakuro/era/japan/gengou/type.rb +3 -3
  27. data/lib/zakuro/era/japan/gengou/validator.rb +15 -13
  28. data/lib/zakuro/merchant.rb +2 -2
  29. data/lib/zakuro/operation/month/parser.rb +132 -36
  30. data/lib/zakuro/operation/month/type.rb +11 -10
  31. data/lib/zakuro/operation/month/validator.rb +332 -28
  32. data/lib/zakuro/operation/operation.rb +21 -0
  33. data/lib/zakuro/operation/yaml/month.yaml +1 -1
  34. data/lib/zakuro/output/error.rb +7 -6
  35. data/lib/zakuro/output/logger.rb +50 -49
  36. data/lib/zakuro/output/response.rb +145 -144
  37. data/lib/zakuro/result/operation.rb +64 -36
  38. data/lib/zakuro/tools/stringifier.rb +2 -2
  39. data/lib/zakuro/tools/typeof.rb +2 -2
  40. data/lib/zakuro/version.rb +1 -1
  41. data/lib/zakuro/version/abstract_version.rb +1 -1
  42. data/lib/zakuro/version/context.rb +23 -0
  43. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  44. data/lib/zakuro/version/senmyou/const/remainder.rb +43 -0
  45. data/lib/zakuro/version/senmyou/cycle/remainder.rb +61 -0
  46. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
  47. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +166 -181
  48. data/lib/zakuro/version/senmyou/range/annual_range.rb +86 -159
  49. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  50. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  51. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +45 -0
  52. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +108 -0
  53. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +89 -0
  54. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  55. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  56. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  57. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  58. data/lib/zakuro/version/senmyou/stella/solar/average.rb +175 -0
  59. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  60. data/lib/zakuro/version/senmyou/stella/solar/location.rb +164 -0
  61. data/lib/zakuro/version/senmyou/stella/solar/value.rb +138 -0
  62. data/lib/zakuro/version/version_class_resolver.rb +62 -0
  63. data/lib/zakuro/version_factory.rb +2 -2
  64. metadata +38 -24
  65. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  66. data/lib/zakuro/cycle/zodiac.rb +0 -103
  67. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  68. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  69. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  70. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  71. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -76
  72. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  73. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  74. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -48
  75. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  76. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  77. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -167
  78. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -324
  79. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -105
  80. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -163
  81. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -99
  82. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  83. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -214
  84. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -394
  85. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  86. data/lib/zakuro/version/senmyou/summary/single.rb +0 -71
Binary file
@@ -5,12 +5,16 @@ require 'yaml'
5
5
 
6
6
  table = CSV.read('csv/month.csv', headers: true)
7
7
 
8
+ # :reek:UtilityFunction
9
+
8
10
  def month_str_to_number(str)
9
11
  return str if str == '-'
10
12
 
11
13
  str.match('([0-9]{1,2})')[0]
12
14
  end
13
15
 
16
+ # :reek:UtilityFunction
17
+
14
18
  def month_str_to_leaped(str)
15
19
  return str if str == '-'
16
20
 
@@ -23,8 +27,8 @@ result = []
23
27
  table.each do |row|
24
28
  hash = {
25
29
  'id' => row['ID'],
26
- 'relation_id' => row['関連内容ID'],
27
- 'parent_id' => row['ID'],
30
+ 'relation_id' => row['関連注釈ID'],
31
+ 'parent_id' => row['親注釈ID'],
28
32
  'page' => row['頁数'],
29
33
  'number' => row['注番'],
30
34
  'japan_date' => row['和暦'],
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../era/japan/gengou'
4
+ require_relative '../../era/western'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Base
12
+ #
13
+ # MultiGengou 複数元号
14
+ #
15
+ class MultiGengou
16
+ # @return [Japan::Gengou] 元号(1行目)
17
+ attr_reader :first_line
18
+ # @return [Japan::Gengou] 元号(2行目)
19
+ attr_reader :second_line
20
+ # @return [Western::Calendar] 元旦
21
+ attr_reader :new_year_date
22
+
23
+ def initialize(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new,
24
+ new_year_date: Western::Calendar.new)
25
+ @first_line = first_line
26
+ @second_line = second_line
27
+ @new_year_date = new_year_date
28
+ end
29
+
30
+ # :reek:TooManyStatements { max_statements: 7 }
31
+
32
+ #
33
+ # 改元する
34
+ #
35
+ # @param [Japan::Gengou] first_line 元号(1行目)
36
+ # @param [Japan::Gengou] second_line 元号(2行目)
37
+ #
38
+ # @return [MultiGengou] 自身
39
+ #
40
+ def transfer(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new)
41
+ cloned_first_line = first_line.clone
42
+ cloned_second_line = second_line.clone
43
+
44
+ if integrated?(first_line: cloned_first_line, second_line: cloned_second_line)
45
+ @first_line = @second_line.clone
46
+ @second_line = cloned_second_line
47
+ end
48
+
49
+ @first_line = cloned_first_line if @first_line.name != first_line.name
50
+ @second_line = cloned_second_line if @second_line.name != second_line.name
51
+
52
+ self
53
+ end
54
+
55
+ #
56
+ # 次年にする
57
+ #
58
+ # @param [Japan::Gengou] first_line 元号(1行目)
59
+ # @param [Japan::Gengou] second_line 元号(2行目)
60
+ #
61
+ # @return [MultiGengou] 自身
62
+ #
63
+ def next_year
64
+ @first_line.next_year
65
+ @second_line.next_year
66
+
67
+ self
68
+ end
69
+
70
+ #
71
+ # ディープコピー
72
+ #
73
+ # @param [MultiGengou] obj 自身
74
+ #
75
+ def initialize_copy(obj)
76
+ @first_line = obj.first_line.clone
77
+ @second_line = obj.second_line.clone
78
+ end
79
+
80
+ private
81
+
82
+ #
83
+ # 複数元号を統一するかどうか
84
+ #
85
+ # @param [Japan::Gengou] first_line 元号(1行目)
86
+ # @param [Japan::Gengou] second_line 元号(2行目)
87
+ #
88
+ # @return [True] 統一する
89
+ # @return [False] 統一しない
90
+ #
91
+ def integrated?(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new)
92
+ return false if @second_line.name != first_line.name
93
+
94
+ return false unless second_line.invalid?
95
+
96
+ true
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './multi_gengou'
4
+
5
+ require_relative '../../era/japan/gengou'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Calculation
11
+ # :nodoc:
12
+ module Base
13
+ #
14
+ # MultiGengouRoller 改元処理
15
+ #
16
+ class MultiGengouRoller
17
+ # @return [MultiGengou] 複数元号
18
+ attr_reader :multi_gengou
19
+ # @return [Western::Calendar] 元旦(元号が2つある場合は再過去の日付になる)
20
+ attr_reader :oldest_date
21
+ # @return [Western::Calendar] 元号内での最未来日(元号が2つある場合は再未来の日付になる)
22
+ attr_reader :newest_date
23
+ # @return [Western::Calendar] 現在日
24
+ attr_reader :current_date
25
+
26
+ def initialize(start_date: Western::Calendar.new, end_date: Western::Calendar.new)
27
+ end_date = start_date if end_date.invalid?
28
+
29
+ @oldest_date = MultiGengouRoller.choise_oldest_gengou_date(
30
+ first_line: MultiGengouRoller.first_line(date: start_date),
31
+ second_line: MultiGengouRoller.second_line(date: start_date)
32
+ )
33
+ @current_date = @oldest_date.clone
34
+ @newest_date = MultiGengouRoller.choise_newest_gengou_date(
35
+ first_line: MultiGengouRoller.first_line(date: end_date),
36
+ second_line: MultiGengouRoller.second_line(date: end_date)
37
+ )
38
+
39
+ @multi_gengou = MultiGengou.new(
40
+ first_line: current_first_line,
41
+ second_line: current_second_line,
42
+ new_year_date: @oldest_date
43
+ )
44
+ end
45
+
46
+ #
47
+ # 現在日付を未来に進める
48
+ #
49
+ # @param [<Type>] days <description>
50
+ #
51
+ # @return [<Type>] <description>
52
+ #
53
+ def next(days: 0)
54
+ @current_date += days
55
+ end
56
+
57
+ #
58
+ # 現在日から元号(1行目)を取得する
59
+ #
60
+ # @return [Japan::Gengou] 元号(1行目)
61
+ #
62
+ def current_first_line
63
+ MultiGengouRoller.first_line(date: @current_date)
64
+ end
65
+
66
+ #
67
+ # 現在日から元号(2行目)を取得する
68
+ #
69
+ # @return [Japan::Gengou] 元号(2行目)
70
+ #
71
+ def current_second_line
72
+ MultiGengouRoller.second_line(date: @current_date)
73
+ end
74
+
75
+ #
76
+ # 改元する
77
+ #
78
+ # @return [MultiGengou] 複数元号
79
+ #
80
+ def transfer
81
+ MultiGengouRoller.transfer(multi_gengou: @multi_gengou, date: @current_date)
82
+ end
83
+
84
+ #
85
+ # 次年にする
86
+ #
87
+ # @return [MultiGengou] 複数元号
88
+ #
89
+ def next_year
90
+ @multi_gengou.next_year
91
+ end
92
+
93
+ #
94
+ # 元号(1行目)を取得する
95
+ #
96
+ # @return [Japan::Gengou] 元号(1行目)
97
+ #
98
+ def self.first_line(date: Western::Calender.new)
99
+ Japan::GengouResource.first_line(date: date)
100
+ end
101
+
102
+ #
103
+ # 元号(2行目)を取得する
104
+ #
105
+ # @return [Japan::Gengou] 元号(2行目)
106
+ #
107
+ def self.second_line(date: Western::Calender.new)
108
+ Japan::GengouResource.second_line(date: date)
109
+ end
110
+
111
+ #
112
+ # 改元する
113
+ #
114
+ # @param [MultiGengou] multi_gengou 複数元号
115
+ # @param [Western::Calendar] date 対象日
116
+ #
117
+ # @return [MultiGengou] 改元済み複数元号
118
+ #
119
+ def self.transfer(multi_gengou:, date:)
120
+ multi_gengou.transfer(
121
+ first_line: first_line(date: date),
122
+ second_line: second_line(date: date)
123
+ )
124
+
125
+ multi_gengou
126
+ end
127
+
128
+ #
129
+ # 現在日からみて直近の未来に対する元号の切替前日を求める
130
+ # @note 2つの元号が重複した場合はより過去の日となる
131
+ #
132
+ # @param [Japan::Gengou] first_line 元号(1行目)
133
+ # @param [Japan::Gengou] second_line 元号(2行目)
134
+ #
135
+ # @return [Western::Calendar] 元号の切替前日
136
+ #
137
+ def choise_nearest_end_date
138
+ condition = lambda do |first_date, second_date|
139
+ first_date < second_date ? first_date : second_date
140
+ end
141
+
142
+ second_line = current_second_line
143
+
144
+ MultiGengouRoller.choise_date(condition: condition, second_line: second_line,
145
+ first_date: current_first_line.end_date.clone,
146
+ second_date: second_line.end_date.clone)
147
+ end
148
+
149
+ #
150
+ # 最過去の元旦を求める
151
+ # @note 2つの元号が重複した場合はより過去の日となる
152
+ #
153
+ # @param [Japan::Gengou] first_line 元号(1行目)
154
+ # @param [Japan::Gengou] second_line 元号(2行目)
155
+ #
156
+ # @return [Western::Calendar] 最過去の元旦
157
+ #
158
+ def self.choise_oldest_gengou_date(first_line:, second_line:)
159
+ condition = lambda do |first_date, second_date|
160
+ first_date < second_date ? first_date : second_date
161
+ end
162
+ choise_date(condition: condition, second_line: second_line,
163
+ first_date: first_line.new_year_date.clone,
164
+ second_date: second_line.new_year_date.clone)
165
+ end
166
+
167
+ #
168
+ # 元号内での最未来日を求める
169
+ # @note 2つの元号が重複した場合はより未来の日となる
170
+ #
171
+ # @param [Japan::Gengou] first_line 元号(1行目)
172
+ # @param [Japan::Gengou] second_line 元号(2行目)
173
+ #
174
+ # @return [Western::Calendar] 最未来日
175
+ #
176
+ def self.choise_newest_gengou_date(first_line:, second_line:)
177
+ condition = lambda do |first_date, second_date|
178
+ first_date > second_date ? first_date : second_date
179
+ end
180
+ choise_date(condition: condition, second_line: second_line,
181
+ first_date: first_line.end_date.clone,
182
+ second_date: second_line.end_date.clone)
183
+ end
184
+
185
+ # :reek:LongParameterList {max_params: 4}
186
+
187
+ #
188
+ # 条件を元に日付を求める
189
+ #
190
+ # @param [Proc] condition 比較条件
191
+ # @param [Japan::Gengou] second_line 元号(2行目)
192
+ # @param [Western::Calendar] first_date 比較対象(1行目)
193
+ # @param [Western::Calendar] second_date 比較対象(2行目)
194
+ #
195
+ # @return [Western::Calendar] 比較結果
196
+ #
197
+ def self.choise_date(condition:, second_line:, first_date:, second_date:)
198
+ # first_lineは常に存在する
199
+ return first_date if second_line.invalid?
200
+
201
+ condition.call(first_date, second_date)
202
+ end
203
+
204
+ #
205
+ # ディープコピー
206
+ #
207
+ # @param [MultiGengou] obj 自身
208
+ #
209
+ def initialize_copy(obj)
210
+ @oldest_date = obj.oldest_date.clone
211
+ @current_date = obj.current_date.clone
212
+ @newest_date = obj.newest_date.clone
213
+ @multi_gengou = obj.multi_gengou.clone
214
+ end
215
+ end
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../cycle/zodiac'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Base
11
+ #
12
+ # Year 年
13
+ #
14
+ class Year
15
+ # @return [Gengou] 元号
16
+ attr_reader :multi_gengou
17
+ # @return [Array<Month>] 年内の全ての月
18
+ attr_reader :months
19
+ # @return [Integer] 年の日数
20
+ attr_reader :total_days
21
+ # @return [Western::Calendar] 元旦
22
+ attr_reader :new_year_date
23
+
24
+ #
25
+ # 初期化
26
+ #
27
+ # @param [Gengou] multi_gengou 元号
28
+ #
29
+ def initialize(multi_gengou: MultiGengou.new, new_year_date: Western::Calendar.new,
30
+ months: [], total_days: 0)
31
+ @multi_gengou = multi_gengou
32
+ @months = months
33
+ @new_year_date = new_year_date
34
+ @total_days = total_days
35
+ end
36
+
37
+ #
38
+ # 年の日数を確定する
39
+ #
40
+ def commit
41
+ @total_days = 0
42
+ months.each do |month|
43
+ @total_days += month.days
44
+ end
45
+
46
+ self
47
+ end
48
+
49
+ #
50
+ # 次年にする
51
+ #
52
+ # @param [Japan::Gengou] first_line 元号(1行目)
53
+ # @param [Japan::Gengou] second_line 元号(2行目)
54
+ #
55
+ # @return [MultiGengou] 自身
56
+ #
57
+ def next_year
58
+ @multi_gengou.next_year
59
+
60
+ @new_year_date += @total_days
61
+ @total_days = 0
62
+
63
+ self
64
+ end
65
+
66
+ #
67
+ # 十干十二支を取得する
68
+ #
69
+ # @return [String] 十干十二支
70
+ #
71
+ def zodiac_name
72
+ Cycle::Zodiac.year_name(western_year: @new_year_date.year)
73
+ end
74
+
75
+ #
76
+ # 月を追加する
77
+ #
78
+ # @param [Month] month 月
79
+ #
80
+ def push(month:)
81
+ return if duplicated?(month: month)
82
+
83
+ @months.push(month)
84
+
85
+ nil
86
+ end
87
+
88
+ #
89
+ # すでに登録済みの月と重複しているか判定する
90
+ #
91
+ # @note 昨年11月1日から今年1月1日の前日までで、去年データと重複する場合は登録スキップする
92
+ #
93
+ # @param [Month] month 月
94
+ #
95
+ # @return [True] 重複している
96
+ # @return [True] 重複していない
97
+ #
98
+ def duplicated?(month:)
99
+ @months.each do |existed|
100
+ return true if existed.same?(other: month)
101
+ end
102
+ false
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end