zakuro 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +6 -4
  4. data/VERSION +1 -1
  5. data/doc/operation/transfer.rb +8 -8
  6. data/lib/zakuro/calculation/base/gengou.rb +46 -0
  7. data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +6 -8
  8. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  9. data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +37 -51
  10. data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +17 -17
  11. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +2 -3
  17. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  18. data/lib/zakuro/calculation/monthly/month.rb +39 -0
  19. data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
  20. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +5 -4
  21. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +9 -11
  22. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  23. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  24. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  25. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  26. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -2
  27. data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +1 -1
  28. data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
  29. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  30. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -0
  31. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  32. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  33. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +169 -0
  34. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
  35. data/lib/zakuro/condition.rb +1 -2
  36. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +89 -74
  37. data/lib/zakuro/era/japan/gengou/alignment/division.rb +125 -122
  38. data/lib/zakuro/era/japan/gengou/alignment/line.rb +141 -122
  39. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +171 -168
  40. data/lib/zakuro/era/japan/gengou/alignment.rb +38 -25
  41. data/lib/zakuro/era/japan/gengou/resource/parser.rb +183 -182
  42. data/lib/zakuro/era/japan/gengou/resource/type.rb +233 -232
  43. data/lib/zakuro/era/japan/gengou/resource/validator.rb +255 -254
  44. data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
  45. data/lib/zakuro/era/japan/gengou.rb +5 -20
  46. data/lib/zakuro/era/western/calendar.rb +9 -9
  47. data/lib/zakuro/exception/case/pattern.rb +35 -0
  48. data/lib/zakuro/exception/case/preset.rb +51 -0
  49. data/lib/zakuro/exception/case/template.rb +48 -0
  50. data/lib/zakuro/exception/cause.rb +28 -0
  51. data/lib/zakuro/exception/exception.rb +37 -0
  52. data/lib/zakuro/exception/zakuro_error.rb +28 -0
  53. data/lib/zakuro/gateway/locale/date.rb +127 -0
  54. data/lib/zakuro/gateway/locale/range.rb +67 -0
  55. data/lib/zakuro/gateway/range.rb +99 -0
  56. data/lib/zakuro/gateway/single.rb +70 -0
  57. data/lib/zakuro/merchant.rb +8 -44
  58. data/lib/zakuro/operation/month/parser.rb +9 -9
  59. data/lib/zakuro/operation/month/type.rb +31 -31
  60. data/lib/zakuro/operation/month/validator.rb +49 -49
  61. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  62. data/lib/zakuro/output/logger.rb +17 -3
  63. data/lib/zakuro/result/data/day.rb +43 -0
  64. data/lib/zakuro/result/data/gengou.rb +35 -0
  65. data/lib/zakuro/result/data/month.rb +63 -0
  66. data/lib/zakuro/result/data/single_day.rb +48 -0
  67. data/lib/zakuro/result/data/solar_term.rb +35 -0
  68. data/lib/zakuro/result/data/year.rb +45 -0
  69. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  70. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  71. data/lib/zakuro/result/operation/month/history.rb +54 -0
  72. data/lib/zakuro/result/operation/operation.rb +44 -0
  73. data/lib/zakuro/result/result.rb +4 -2
  74. metadata +46 -14
  75. data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
  76. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  77. data/lib/zakuro/calculation/summary/range.rb +0 -120
  78. data/lib/zakuro/calculation/summary/single.rb +0 -110
  79. data/lib/zakuro/result/data.rb +0 -187
  80. data/lib/zakuro/result/operation.rb +0 -114
@@ -7,236 +7,237 @@ require 'yaml'
7
7
 
8
8
  # :nodoc:
9
9
  module Zakuro
10
- #
11
- # Japan 和暦
12
- #
10
+ # :nodoc:
13
11
  module Japan
14
- #
15
- # Resource yaml解析結果
16
- #
17
- module Resource
18
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
19
-
12
+ # :nodoc:
13
+ module Gengou
20
14
  #
21
- # Parser yaml解析
15
+ # Resource yaml解析結果
22
16
  #
23
- module Parser
24
- #
25
- # GengouParser 元号情報の検証/展開を行う
26
- #
27
- class GengouParser
28
- # @return [Integer] 要素位置
29
- attr_reader :index
30
- # @return [String] 元号名
31
- attr_reader :name
32
- # @return [Hash<String, String>] 開始年
33
- attr_reader :both_start_year
34
- # @return [Hash<String, String>] 開始日
35
- attr_reader :both_start_date
36
-
37
- #
38
- # 初期化
39
- #
40
- # @param [Hash<String, Strin>] hash 元号情報
41
- # @param [Integer] index (元号セット内での)元号の要素位置
42
- #
43
- def initialize(hash:, index:)
44
- @index = index
45
- @name = hash['name']
46
- @both_start_year = hash['start_year']
47
- @both_start_date = hash['start_date']
48
- end
49
-
50
- #
51
- # 元号情報を生成する
52
- #
53
- # @return [Gengou] 元号情報
54
- #
55
- def create
56
- both_start_year = Both::YearParser.new(hash: @both_start_year).create
57
- both_start_date = Both::DateParser.new(hash: @both_start_date).create
58
-
59
- Gengou.new(name: @name, both_start_year: both_start_year,
60
- both_start_date: both_start_date)
61
- end
62
- end
17
+ module Resource
18
+ # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
63
19
 
64
20
  #
65
- # SetParser 元号セット情報の検証/展開
21
+ # Parser yaml解析
66
22
  #
67
- class SetParser
68
- # @return [String] 元号セットID
69
- attr_reader :id
70
- # @return [String] 元号セット名
71
- attr_reader :name
72
- # @return [Hash<String, String>] 終了年
73
- attr_reader :both_last_year
74
- # @return [Hash<String, String>] 終了日
75
- attr_reader :both_last_date
76
- # @return [Array<Hash<String, String>>] 元号情報
77
- attr_reader :list
78
-
79
- #
80
- # 初期化
81
- #
82
- # @param [Hash<String, Object>] hash 元号セット情報
83
- #
84
- def initialize(hash:)
85
- @id = hash['id']
86
- @name = hash['name']
87
- @both_last_year = hash['last_year']
88
- @both_last_date = hash['last_date']
89
- @list = hash['list']
90
- end
91
-
23
+ module Parser
92
24
  #
93
- # 元号セット情報を生成する
25
+ # GengouParser 元号情報の検証/展開を行う
94
26
  #
95
- # @return [Set] 元号セット情報
96
- #
97
- def create
98
- both_last_date = Both::DateParser.new(hash: @both_last_date).create
99
- list = create_list
100
- Set.new(
101
- id: @id, name: @name, both_last_date: both_last_date, list: list
102
- )
103
- end
27
+ class GengouParser
28
+ # @return [Integer] 要素位置
29
+ attr_reader :index
30
+ # @return [String] 元号名
31
+ attr_reader :name
32
+ # @return [Hash<String, String>] 開始年
33
+ attr_reader :both_start_year
34
+ # @return [Hash<String, String>] 開始日
35
+ attr_reader :both_start_date
104
36
 
105
- # :reek:TooManyStatements { max_statements: 7 }
106
-
107
- #
108
- # 元号情報を生成する
109
- #
110
- # @return [Array<Gengou>] 元号情報
111
- #
112
- def create_list
113
- result = []
114
- @list.each_with_index do |li, index|
115
- gengou = GengouParser.new(hash: li, index: index).create
116
- next_index = index + 1
117
- gengou = calc_last_date_on_gengou_data(next_index: next_index,
118
- gengou: gengou)
119
- result.push(gengou)
37
+ #
38
+ # 初期化
39
+ #
40
+ # @param [Hash<String, Strin>] hash 元号情報
41
+ # @param [Integer] index (元号セット内での)元号の要素位置
42
+ #
43
+ def initialize(hash:, index:)
44
+ @index = index
45
+ @name = hash['name']
46
+ @both_start_year = hash['start_year']
47
+ @both_start_date = hash['start_date']
120
48
  end
121
49
 
122
- result
123
- end
124
-
125
- # :reek:TooManyStatements { max_statements: 6 }
50
+ #
51
+ # 元号情報を生成する
52
+ #
53
+ # @return [Gengou] 元号情報
54
+ #
55
+ def create
56
+ both_start_year = Both::YearParser.new(hash: @both_start_year).create
57
+ both_start_date = Both::DateParser.new(hash: @both_start_date).create
126
58
 
127
- #
128
- # 次の元号の開始日から、元号の終了日に変換する
129
- #
130
- # @param [Integer] next_index 次の元号の要素位置
131
- # @param [String] gengou 次回開始日
132
- #
133
- # @return [Gengou] 元号情報
134
- #
135
- def calc_last_date_on_gengou_data(next_index:, gengou:)
136
- if next_index >= @list.size
137
- gengou.write_last_year(last_year: @both_last_year['western'])
138
- last_date = Western::Calendar.parse(str: @both_last_date['western'])
139
- gengou.write_last_date(last_date: last_date)
140
- return gengou
59
+ Gengou.new(name: @name, both_start_year: both_start_year,
60
+ both_start_date: both_start_date)
141
61
  end
142
- next_item = @list[next_index]
143
- gengou.convert_next_start_year_to_last_year(
144
- next_start_year: next_item['start_year']['western']
145
- )
146
- gengou.convert_next_start_date_to_last_date(
147
- next_start_date: next_item['start_date']['western']
148
- )
149
- gengou
150
62
  end
151
- end
152
63
 
153
- #
154
- # 和暦/西暦
155
- #
156
- module Both
157
64
  #
158
- # YearParser
65
+ # SetParser 元号セット情報の検証/展開
159
66
  #
160
- class YearParser
161
- # @return [Integer] 和暦元号年
162
- attr_reader :japan
163
- # @return [Integer] 西暦年
164
- attr_reader :western
67
+ class SetParser
68
+ # @return [String] 元号セットID
69
+ attr_reader :id
70
+ # @return [String] 元号セット名
71
+ attr_reader :name
72
+ # @return [Hash<String, String>] 終了年
73
+ attr_reader :both_last_year
74
+ # @return [Hash<String, String>] 終了日
75
+ attr_reader :both_last_date
76
+ # @return [Array<Hash<String, String>>] 元号情報
77
+ attr_reader :list
165
78
 
166
79
  #
167
80
  # 初期化
168
81
  #
169
- # @param [Hash<String, Object>] hash 年情報
82
+ # @param [Hash<String, Object>] hash 元号セット情報
170
83
  #
171
84
  def initialize(hash:)
172
- @japan = hash['japan']
173
- @western = hash['western']
85
+ @id = hash['id']
86
+ @name = hash['name']
87
+ @both_last_year = hash['last_year']
88
+ @both_last_date = hash['last_date']
89
+ @list = hash['list']
174
90
  end
175
91
 
176
92
  #
177
- # 年情報を生成する
93
+ # 元号セット情報を生成する
178
94
  #
179
- # @return [Both::Year] 年情報
95
+ # @return [Set] 元号セット情報
180
96
  #
181
97
  def create
182
- japan = @japan.to_i
183
- western = @western.to_i
184
-
185
- Japan::Resource::Both::Year.new(japan: japan, western: western)
98
+ both_last_date = Both::DateParser.new(hash: @both_last_date).create
99
+ list = create_list
100
+ Set.new(
101
+ id: @id, name: @name, both_last_date: both_last_date, list: list
102
+ )
186
103
  end
187
- end
188
104
 
189
- #
190
- # DateParser 日
191
- #
192
- class DateParser
193
- # @return [Japan::Calendar] 和暦日
194
- attr_reader :japan
195
- # @return [Western::Calendar] 西暦日
196
- attr_reader :western
105
+ # :reek:TooManyStatements { max_statements: 7 }
197
106
 
198
107
  #
199
- # 初期化
108
+ # 元号情報を生成する
200
109
  #
201
- # @param [Hash<String, Object>] hash 日情報
110
+ # @return [Array<Gengou>] 元号情報
202
111
  #
203
- def initialize(hash:)
204
- @japan = hash['japan']
205
- @western = hash['western']
112
+ def create_list
113
+ result = []
114
+ @list.each_with_index do |li, index|
115
+ gengou = GengouParser.new(hash: li, index: index).create
116
+ next_index = index + 1
117
+ gengou = calc_last_date_on_gengou_data(next_index: next_index,
118
+ gengou: gengou)
119
+ result.push(gengou)
120
+ end
121
+
122
+ result
206
123
  end
207
124
 
125
+ # :reek:TooManyStatements { max_statements: 6 }
126
+
208
127
  #
209
- # 日情報を生成する
128
+ # 次の元号の開始日から、元号の終了日に変換する
210
129
  #
211
- # @return [Both::Date] 日情報
130
+ # @param [Integer] next_index 次の元号の要素位置
131
+ # @param [String] gengou 次回開始日
212
132
  #
213
- def create
214
- japan = Japan::Calendar.parse(text: @japan)
215
- western = Western::Calendar.parse(str: @western)
133
+ # @return [Gengou] 元号情報
134
+ #
135
+ def calc_last_date_on_gengou_data(next_index:, gengou:)
136
+ if next_index >= @list.size
137
+ gengou.write_last_year(last_year: @both_last_year['western'])
138
+ last_date = Western::Calendar.parse(text: @both_last_date['western'])
139
+ gengou.write_last_date(last_date: last_date)
140
+ return gengou
141
+ end
142
+ next_item = @list[next_index]
143
+ gengou.convert_next_start_year_to_last_year(
144
+ next_start_year: next_item['start_year']['western']
145
+ )
146
+ gengou.convert_next_start_date_to_last_date(
147
+ next_start_date: next_item['start_date']['western']
148
+ )
149
+ gengou
150
+ end
151
+ end
152
+
153
+ #
154
+ # 和暦/西暦
155
+ #
156
+ module Both
157
+ #
158
+ # YearParser 年
159
+ #
160
+ class YearParser
161
+ # @return [Integer] 和暦元号年
162
+ attr_reader :japan
163
+ # @return [Integer] 西暦年
164
+ attr_reader :western
165
+
166
+ #
167
+ # 初期化
168
+ #
169
+ # @param [Hash<String, Object>] hash 年情報
170
+ #
171
+ def initialize(hash:)
172
+ @japan = hash['japan']
173
+ @western = hash['western']
174
+ end
175
+
176
+ #
177
+ # 年情報を生成する
178
+ #
179
+ # @return [Both::Year] 年情報
180
+ #
181
+ def create
182
+ japan = @japan.to_i
183
+ western = @western.to_i
184
+
185
+ Japan::Gengou::Resource::Both::Year.new(japan: japan, western: western)
186
+ end
187
+ end
216
188
 
217
- Japan::Resource::Both::Date.new(japan: japan, western: western)
189
+ #
190
+ # DateParser 日
191
+ #
192
+ class DateParser
193
+ # @return [Japan::Calendar] 和暦日
194
+ attr_reader :japan
195
+ # @return [Western::Calendar] 西暦日
196
+ attr_reader :western
197
+
198
+ #
199
+ # 初期化
200
+ #
201
+ # @param [Hash<String, Object>] hash 日情報
202
+ #
203
+ def initialize(hash:)
204
+ @japan = hash['japan']
205
+ @western = hash['western']
206
+ end
207
+
208
+ #
209
+ # 日情報を生成する
210
+ #
211
+ # @return [Both::Date] 日情報
212
+ #
213
+ def create
214
+ japan = Japan::Calendar.parse(text: @japan)
215
+ western = Western::Calendar.parse(text: @western)
216
+
217
+ Japan::Gengou::Resource::Both::Date.new(japan: japan, western: western)
218
+ end
218
219
  end
219
220
  end
220
- end
221
221
 
222
- #
223
- # 解析/展開する
224
- #
225
- # @param [String] filepath 元号セットファイルパス
226
- #
227
- # @return [Set] 元号セット情報
228
- #
229
- def self.run(filepath: '')
230
- yaml = YAML.load_file(filepath)
222
+ #
223
+ # 解析/展開する
224
+ #
225
+ # @param [String] filepath 元号セットファイルパス
226
+ #
227
+ # @return [Set] 元号セット情報
228
+ #
229
+ def self.run(filepath: '')
230
+ yaml = YAML.load_file(filepath)
231
231
 
232
- failed = Validator.run(yaml_hash: yaml)
232
+ failed = Validator.run(yaml_hash: yaml)
233
233
 
234
- raise ArgumentError, failed.join("\n") unless failed.empty?
234
+ raise ArgumentError, failed.join("\n") unless failed.empty?
235
235
 
236
- parser = SetParser.new(hash: yaml)
237
- parser.create
236
+ parser = SetParser.new(hash: yaml)
237
+ parser.create
238
+ end
238
239
  end
239
240
  end
241
+ end
240
242
  end
241
243
  end
242
- end