zakuro 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +46 -17
  4. data/VERSION +1 -1
  5. data/doc/dropped_date.md +93 -0
  6. data/doc/error.md +45 -0
  7. data/doc/operation/transfer.rb +8 -8
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +49 -3
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  11. data/lib/zakuro/calculation/base/operated_year.rb +26 -24
  12. data/lib/zakuro/calculation/base/year.rb +7 -7
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
  14. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  15. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  16. data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +44 -37
  17. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  19. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  20. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +156 -0
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  27. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +73 -0
  28. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
  29. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  30. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  31. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  32. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  33. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  34. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  35. data/lib/zakuro/calculation/monthly/month.rb +55 -16
  36. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  37. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  38. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  39. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  40. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  41. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +45 -29
  42. data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
  43. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  44. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  45. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  46. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  47. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  48. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  49. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  50. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  51. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  52. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  53. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  54. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  55. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  56. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  57. data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
  58. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  59. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  60. data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
  61. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  62. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
  63. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  64. data/lib/zakuro/calculation/summary/western/range.rb +127 -0
  65. data/lib/zakuro/calculation/summary/western/single.rb +115 -0
  66. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
  67. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
  68. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  69. data/lib/zakuro/calculation/type/optional.rb +46 -0
  70. data/lib/zakuro/condition.rb +143 -94
  71. data/lib/zakuro/context/context.rb +44 -0
  72. data/lib/zakuro/context/option.rb +119 -0
  73. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  74. data/lib/zakuro/era/japan/calendar.rb +35 -33
  75. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
  76. data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
  77. data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
  78. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
  79. data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
  80. data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
  81. data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
  82. data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
  83. data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
  84. data/lib/zakuro/era/japan/gengou.rb +28 -41
  85. data/lib/zakuro/era/japan/version.rb +18 -16
  86. data/lib/zakuro/era/western/calendar.rb +104 -88
  87. data/lib/zakuro/exception/case/pattern.rb +71 -0
  88. data/lib/zakuro/exception/case/preset.rb +51 -0
  89. data/lib/zakuro/exception/case/template.rb +48 -0
  90. data/lib/zakuro/exception/cause.rb +28 -0
  91. data/lib/zakuro/exception/exception.rb +39 -0
  92. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  93. data/lib/zakuro/gateway/locale/date.rb +127 -0
  94. data/lib/zakuro/gateway/locale/range.rb +67 -0
  95. data/lib/zakuro/gateway/range.rb +99 -0
  96. data/lib/zakuro/gateway/single.rb +81 -0
  97. data/lib/zakuro/merchant.rb +67 -33
  98. data/lib/zakuro/operation/month/parser.rb +252 -249
  99. data/lib/zakuro/operation/month/type.rb +44 -35
  100. data/lib/zakuro/operation/month/validator.rb +182 -178
  101. data/lib/zakuro/operation/operation.rb +38 -36
  102. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  103. data/lib/zakuro/output/logger.rb +17 -3
  104. data/lib/zakuro/output/response.rb +107 -141
  105. data/lib/zakuro/result/data/day.rb +43 -0
  106. data/lib/zakuro/result/data/gengou.rb +35 -0
  107. data/lib/zakuro/result/data/month.rb +63 -0
  108. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  109. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  110. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  111. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  112. data/lib/zakuro/result/data/single_day.rb +56 -0
  113. data/lib/zakuro/result/data/solar_term.rb +35 -0
  114. data/lib/zakuro/result/data/year.rb +45 -0
  115. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  116. data/lib/zakuro/result/operation/month/history.rb +54 -0
  117. data/lib/zakuro/result/operation/month.rb +31 -0
  118. data/lib/zakuro/result/operation.rb +22 -97
  119. data/lib/zakuro/result/result.rb +6 -4
  120. data/lib/zakuro/tools/stringifier.rb +67 -42
  121. data/lib/zakuro/tools/typeconv.rb +17 -15
  122. data/lib/zakuro/tools/typeof.rb +15 -13
  123. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  124. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  125. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  126. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  127. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  128. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  129. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  130. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  131. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  132. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  133. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  134. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  135. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  136. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  137. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  138. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  139. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  140. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  141. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  142. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  143. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  144. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  145. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  146. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  147. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  148. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  149. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  150. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  151. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  152. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  153. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  154. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  155. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  156. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  157. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  158. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  159. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  160. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  161. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  162. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  163. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  164. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  165. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  166. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  167. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  168. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  169. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  170. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  171. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  172. metadata +68 -16
  173. data/lib/zakuro/calculation/range/operated_range.rb +0 -193
  174. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
  175. data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
  176. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  177. data/lib/zakuro/calculation/summary/range.rb +0 -120
  178. data/lib/zakuro/calculation/summary/single.rb +0 -110
  179. data/lib/zakuro/result/data.rb +0 -187
  180. data/lib/zakuro/version/context.rb +0 -44
  181. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -15,199 +15,203 @@ module Zakuro
15
15
  # TypeParser 型ごと変換
16
16
  #
17
17
  module TypeParser
18
- #
19
- # 無効値かを判定する
20
- #
21
- # @param [String] str 文字列
22
- #
23
- # @return [True] 無効値
24
- # @return [False] 有効値
25
- #
26
- def self.invalid?(str:)
27
- str == '-'
28
- end
29
-
30
- def self.text(str:)
31
- return '' if invalid?(str: str)
32
-
33
- str
34
- end
18
+ class << self
19
+ #
20
+ # 無効値かを判定する
21
+ #
22
+ # @param [String] str 文字列
23
+ #
24
+ # @return [True] 無効値
25
+ # @return [False] 有効値
26
+ #
27
+ def invalid?(str:)
28
+ str == '-'
29
+ end
35
30
 
36
- #
37
- # 有効行を変換する
38
- #
39
- # @param [String] str 文字列
40
- #
41
- # @return [True] 有効
42
- # @return [False] 無効
43
- #
44
- def self.modified?(str:)
45
- str == 'true'
46
- end
31
+ def text(str:)
32
+ return '' if invalid?(str: str)
47
33
 
48
- #
49
- # 月を変換する
50
- #
51
- # @param [String] str 文字列
52
- #
53
- # @return [Integer] 月
54
- #
55
- def self.month_number(str:)
56
- return -1 if invalid?(str: str)
57
-
58
- str.to_i
59
- end
34
+ str
35
+ end
60
36
 
61
- #
62
- # 閏有無を変換する
63
- #
64
- # @param [String] str 文字列
65
- #
66
- # @return [True] 閏あり
67
- # @return [True] 閏なし/閏設定なし
68
- #
69
- def self.month_leaped(str:)
70
- str == 'true'
71
- end
37
+ #
38
+ # 有効行を変換する
39
+ #
40
+ # @param [String] str 文字列
41
+ #
42
+ # @return [True] 有効
43
+ # @return [False] 無効
44
+ #
45
+ def modified?(str:)
46
+ str == 'true'
47
+ end
72
48
 
73
- #
74
- # 西暦日を変換する
75
- #
76
- # @param [String] str 文字列
77
- #
78
- # @return [Western::Calendar] 西暦日
79
- #
80
- def self.western_date(str:)
81
- return Western::Calendar.new if invalid?(str: str)
49
+ #
50
+ # 月を変換する
51
+ #
52
+ # @param [String] str 文字列
53
+ #
54
+ # @return [Integer]
55
+ #
56
+ def month_number(str:)
57
+ return -1 if invalid?(str: str)
58
+
59
+ str.to_i
60
+ end
82
61
 
83
- Western::Calendar.parse(str: str)
84
- end
62
+ #
63
+ # 閏有無を変換する
64
+ #
65
+ # @param [String] str 文字列
66
+ #
67
+ # @return [True] 閏あり
68
+ # @return [True] 閏なし/閏設定なし
69
+ #
70
+ def month_leaped(str:)
71
+ str == 'true'
72
+ end
85
73
 
86
- #
87
- # 日(差分)を変換する
88
- #
89
- # @param [String] str 文字列
90
- #
91
- # @return [Integer] 日(差分)
92
- #
93
- def self.days(str:)
94
- return INVALID_DAY_VALUE if invalid?(str: str)
74
+ #
75
+ # 西暦日を変換する
76
+ #
77
+ # @param [String] str 文字列
78
+ #
79
+ # @return [Western::Calendar] 西暦日
80
+ #
81
+ def western_date(str:)
82
+ return Western::Calendar.new if invalid?(str: str)
83
+
84
+ Western::Calendar.parse(text: str)
85
+ end
95
86
 
96
- str.to_i
97
- end
87
+ #
88
+ # 日(差分)を変換する
89
+ #
90
+ # @param [String] str 文字列
91
+ #
92
+ # @return [Integer] 日(差分)
93
+ #
94
+ def days(str:)
95
+ return INVALID_DAY_VALUE if invalid?(str: str)
96
+
97
+ str.to_i
98
+ end
98
99
 
99
- def self.solar_term_index(str:)
100
- return -1 if invalid?(str: str)
100
+ def solar_term_index(str:)
101
+ return -1 if invalid?(str: str)
101
102
 
102
- str.to_i
103
- end
103
+ str.to_i
104
+ end
105
+ end
104
106
  end
105
107
 
106
108
  #
107
109
  # MonthParser 月情報解析(yaml)
108
110
  #
109
111
  module MonthParser
110
- #
111
- # 実行する
112
- #
113
- # @return [Array<MonthHistory>] 変更履歴
114
- #
115
- def self.run(filepath:)
116
- hash = YAML.load_file(filepath)
117
-
118
- failed = Validator.run(yaml_hash: hash)
119
-
120
- raise ArgumentError, failed.join("\n") unless failed.empty?
121
-
122
- load(yaml_hash: hash)
123
- end
112
+ class << self
113
+ #
114
+ # 実行する
115
+ #
116
+ # @return [Array<MonthHistory>] 変更履歴
117
+ #
118
+ # @raise [ArgumentError] 引数エラー
119
+ #
120
+ def run(filepath:)
121
+ hash = YAML.load_file(filepath)
122
+
123
+ failed = Validator.run(yaml_hash: hash)
124
+
125
+ raise ArgumentError, failed.join("\n") unless failed.empty?
126
+
127
+ load(yaml_hash: hash)
128
+ end
124
129
 
125
- #
126
- # 設定ファイルを読み込む
127
- #
128
- # @param [Hash] yaml_hash 設定ファイルテキスト
129
- #
130
- # @return [Array<MonthHistory>] 変更履歴
131
- #
132
- def self.load(yaml_hash: {})
133
- histories = create_histories(yaml_hash: yaml_hash)
130
+ #
131
+ # 設定ファイルを読み込む
132
+ #
133
+ # @param [Hash] yaml_hash 設定ファイルテキスト
134
+ #
135
+ # @return [Array<MonthHistory>] 変更履歴
136
+ #
137
+ def load(yaml_hash: {})
138
+ histories = create_histories(yaml_hash: yaml_hash)
134
139
 
135
- annotation_parser = AnnotationParser.new(yaml_hash: yaml_hash)
136
- annotation_parser.create
140
+ annotation_parser = AnnotationParser.new(yaml_hash: yaml_hash)
141
+ annotation_parser.create
137
142
 
138
- add_annotations(histories: histories, annotation_parser: annotation_parser)
139
- end
143
+ add_annotations(histories: histories, annotation_parser: annotation_parser)
144
+ end
140
145
 
141
- #
142
- # 変更履歴を読み込む
143
- #
144
- # @param [Hash] yaml_hash 設定ファイルテキスト
145
- #
146
- # @return [Array<MonthHistory>] 変更履歴
147
- #
148
- def self.create_histories(yaml_hash: {})
149
- result = []
150
- yaml_hash.each do |month|
151
- next unless Operation::TypeParser.modified?(str: month['modified'])
146
+ private
147
+
148
+ #
149
+ # 変更履歴を読み込む
150
+ #
151
+ # @param [Hash] yaml_hash 設定ファイルテキスト
152
+ #
153
+ # @return [Array<MonthHistory>] 変更履歴
154
+ #
155
+ def create_histories(yaml_hash: {})
156
+ result = []
157
+ yaml_hash.each do |month|
158
+ next unless Operation::TypeParser.modified?(str: month['modified'])
159
+
160
+ result.push(
161
+ create_history(yaml_hash: month)
162
+ )
163
+ end
164
+ result
165
+ end
152
166
 
153
- result.push(
154
- create_history(yaml_hash: month)
155
- )
167
+ def create_history(yaml_hash: {})
168
+ diffs = MonthDiffsParser.create(yaml_hash: yaml_hash['diffs'])
169
+
170
+ western_date = Operation::TypeParser.western_date(str: yaml_hash['western_date'])
171
+ reference = Reference.new(page: yaml_hash['page'].to_i, number: yaml_hash['number'].to_i,
172
+ japan_date: yaml_hash['japan_date'])
173
+ MonthHistory.new(id: yaml_hash['id'],
174
+ parent_id: Operation::TypeParser.text(str: yaml_hash['parent_id']),
175
+ reference: reference,
176
+ western_date: western_date,
177
+ diffs: diffs)
156
178
  end
157
- result
158
- end
159
- private_class_method :create_histories
160
-
161
- def self.create_history(yaml_hash: {})
162
- diffs = MonthDiffsParser.create(yaml_hash: yaml_hash['diffs'])
163
-
164
- western_date = Operation::TypeParser.western_date(str: yaml_hash['western_date'])
165
- reference = Reference.new(page: yaml_hash['page'].to_i, number: yaml_hash['number'].to_i,
166
- japan_date: yaml_hash['japan_date'])
167
- MonthHistory.new(id: yaml_hash['id'],
168
- parent_id: Operation::TypeParser.text(str: yaml_hash['parent_id']),
169
- reference: reference,
170
- western_date: western_date,
171
- diffs: diffs)
172
- end
173
- private_class_method :create_history
174
-
175
- def self.add_annotations(annotation_parser:, histories: [])
176
- result = []
177
- histories.each do |history|
178
- id = history.id
179
- result.push(
180
- MonthHistory.new(
181
- id: id, parent_id: history.parent_id, reference: history.reference,
182
- western_date: history.western_date,
183
- annotations: annotation_parser.specify(id: id),
184
- diffs: history.diffs
179
+
180
+ def add_annotations(annotation_parser:, histories: [])
181
+ result = []
182
+ histories.each do |history|
183
+ id = history.id
184
+ result.push(
185
+ MonthHistory.new(
186
+ id: id, parent_id: history.parent_id, reference: history.reference,
187
+ western_date: history.western_date,
188
+ annotations: annotation_parser.specify(id: id),
189
+ diffs: history.diffs
190
+ )
185
191
  )
186
- )
187
- end
192
+ end
188
193
 
189
- result
190
- end
191
- private_class_method :add_annotations
192
-
193
- def self.create_history_annnotations(history:, annotations: {}, relations: {})
194
- history_id = history.id
195
- history_annotations = []
196
- [history_id, relations.fetch(history_id, '')].each do |id|
197
- add_annotation(history_annotations: history_annotations,
198
- annotations: annotations, id: id)
194
+ result
199
195
  end
200
196
 
201
- history_annotations
202
- end
197
+ def create_history_annnotations(history:, annotations: {}, relations: {})
198
+ history_id = history.id
199
+ history_annotations = []
200
+ [history_id, relations.fetch(history_id, '')].each do |id|
201
+ add_annotation(history_annotations: history_annotations,
202
+ annotations: annotations, id: id)
203
+ end
203
204
 
204
- def self.add_annotation(history_annotations: [], annotations: {}, id: '')
205
- annotation = annotations.fetch(id, Annotation.new)
206
- return if annotation.invalid?
205
+ history_annotations
206
+ end
207
207
 
208
- history_annotations.push(annotation)
208
+ def add_annotation(history_annotations: [], annotations: {}, id: '')
209
+ annotation = annotations.fetch(id, Annotation.new)
210
+ return if annotation.invalid?
211
+
212
+ history_annotations.push(annotation)
213
+ end
209
214
  end
210
- private_class_method :add_annotation
211
215
  end
212
216
 
213
217
  #
@@ -236,31 +240,33 @@ module Zakuro
236
240
  def create
237
241
  @yaml_hash.each do |month|
238
242
  AnnotationParser.resolve_history(
239
- hash: month, annotations: @annotations, relations: @relations
243
+ hash: month, annotations: annotations, relations: relations
240
244
  )
241
245
  end
242
246
  end
243
247
 
244
- #
245
- # 月別履歴情報から注釈情報を取り出す
246
- #
247
- # @param [<Type>] hash 月別履歴情報yaml
248
- # @param [Hash<String, Annotation>] annotations 注釈
249
- # @param [Hash<String, String>] relations 関連注釈の対応関係
250
- #
251
- def self.resolve_history(hash: {}, annotations: {}, relations: {})
252
- id = hash['id']
253
- annotations[id] = Annotation.new(
254
- id: id,
255
- description: Operation::TypeParser.text(str: hash['description']),
256
- note: Operation::TypeParser.text(str: hash['note'])
257
- )
258
- relation_id = hash['relation_id']
259
-
260
- return if Operation::TypeParser.invalid?(str: relation_id)
261
-
262
- relations[id] = relation_id
263
- end
248
+ class << self
249
+ #
250
+ # 月別履歴情報から注釈情報を取り出す
251
+ #
252
+ # @param [<Type>] hash 月別履歴情報yaml
253
+ # @param [Hash<String, Annotation>] annotations 注釈
254
+ # @param [Hash<String, String>] relations 関連注釈の対応関係
255
+ #
256
+ def resolve_history(hash: {}, annotations: {}, relations: {})
257
+ id = hash['id']
258
+ annotations[id] = Annotation.new(
259
+ id: id,
260
+ description: Operation::TypeParser.text(str: hash['description']),
261
+ note: Operation::TypeParser.text(str: hash['note'])
262
+ )
263
+ relation_id = hash['relation_id']
264
+
265
+ return if Operation::TypeParser.invalid?(str: relation_id)
266
+
267
+ relations[id] = relation_id
268
+ end
269
+ end
264
270
 
265
271
  #
266
272
  # 注釈を特定する
@@ -293,7 +299,7 @@ module Zakuro
293
299
  end
294
300
 
295
301
  def annotation(id: '')
296
- @annotations.fetch(id, Annotation.new)
302
+ annotations.fetch(id, Annotation.new)
297
303
  end
298
304
  end
299
305
 
@@ -301,73 +307,70 @@ module Zakuro
301
307
  # MonthDiffsParser 月情報(差分)解析
302
308
  #
303
309
  module MonthDiffsParser
304
- def self.create(yaml_hash: {})
305
- Diffs.new(
306
- month: create_month(yaml_hash: yaml_hash['month']),
307
- solar_term: create_solar_term(yaml_hash: yaml_hash['solar_term']),
308
- days: Operation::TypeParser.days(str: yaml_hash['days'])
309
- )
310
- end
310
+ class << self
311
+ def create(yaml_hash: {})
312
+ Diffs.new(
313
+ month: create_month(yaml_hash: yaml_hash['month']),
314
+ solar_term: create_solar_term(yaml_hash: yaml_hash['solar_term']),
315
+ days: Operation::TypeParser.days(str: yaml_hash['days'])
316
+ )
317
+ end
311
318
 
312
- def self.create_solar_term(yaml_hash: {})
313
- SolarTerm::Direction.new(
314
- source: create_source_solar_term(yaml_hash: yaml_hash['calc']),
315
- destination: create_destination_solar_term(yaml_hash: yaml_hash['actual']),
316
- days: Operation::TypeParser.days(str: yaml_hash['days'])
317
- )
318
- end
319
- private_class_method :create_solar_term
320
-
321
- def self.create_source_solar_term(yaml_hash: {})
322
- SolarTerm::Source.new(
323
- index: Operation::TypeParser.solar_term_index(str: yaml_hash['index']),
324
- to: Operation::TypeParser.western_date(str: yaml_hash['to']),
325
- zodiac_name: Operation::TypeParser.text(str: yaml_hash['zodiac_name'])
326
- )
327
- end
328
- private_class_method :create_source_solar_term
329
-
330
- def self.create_destination_solar_term(yaml_hash: {})
331
- SolarTerm::Destination.new(
332
- index: Operation::TypeParser.solar_term_index(str: yaml_hash['index']),
333
- from: Operation::TypeParser.western_date(str: yaml_hash['from']),
334
- zodiac_name: Operation::TypeParser.text(str: yaml_hash['zodiac_name'])
335
- )
336
- end
337
- private_class_method :create_destination_solar_term
338
-
339
- def self.create_month(yaml_hash: {})
340
- Month.new(
341
- number: create_month_number(yaml_hash: yaml_hash['number']),
342
- leaped: create_month_leaped(yaml_hash: yaml_hash['leaped']),
343
- is_many_days: create_month_day(yaml_hash: yaml_hash['days'])
344
- )
345
- end
346
- private_class_method :create_month
319
+ private
347
320
 
348
- def self.create_month_number(yaml_hash: {})
349
- Number.new(
350
- calc: Operation::TypeParser.month_number(str: yaml_hash['calc']),
351
- actual: Operation::TypeParser.month_number(str: yaml_hash['actual'])
352
- )
353
- end
354
- private_class_method :create_month_number
321
+ def create_solar_term(yaml_hash: {})
322
+ SolarTerm::Direction.new(
323
+ source: create_source_solar_term(yaml_hash: yaml_hash['src']),
324
+ destination: create_destination_solar_term(yaml_hash: yaml_hash['dest']),
325
+ days: Operation::TypeParser.days(str: yaml_hash['days'])
326
+ )
327
+ end
355
328
 
356
- def self.create_month_leaped(yaml_hash: {})
357
- Leaped.new(
358
- calc: Operation::TypeParser.month_leaped(str: yaml_hash['calc']),
359
- actual: Operation::TypeParser.month_leaped(str: yaml_hash['actual'])
360
- )
361
- end
362
- private_class_method :create_month_leaped
329
+ def create_source_solar_term(yaml_hash: {})
330
+ SolarTerm::Source.new(
331
+ index: Operation::TypeParser.solar_term_index(str: yaml_hash['index']),
332
+ to: Operation::TypeParser.western_date(str: yaml_hash['to']),
333
+ zodiac_name: Operation::TypeParser.text(str: yaml_hash['zodiac_name'])
334
+ )
335
+ end
363
336
 
364
- def self.create_month_day(yaml_hash: {})
365
- Days.new(
366
- calc: yaml_hash['calc'],
367
- actual: yaml_hash['actual']
368
- )
337
+ def create_destination_solar_term(yaml_hash: {})
338
+ SolarTerm::Destination.new(
339
+ index: Operation::TypeParser.solar_term_index(str: yaml_hash['index']),
340
+ from: Operation::TypeParser.western_date(str: yaml_hash['from']),
341
+ zodiac_name: Operation::TypeParser.text(str: yaml_hash['zodiac_name'])
342
+ )
343
+ end
344
+
345
+ def create_month(yaml_hash: {})
346
+ Month.new(
347
+ number: create_month_number(yaml_hash: yaml_hash['number']),
348
+ leaped: create_month_leaped(yaml_hash: yaml_hash['leaped']),
349
+ is_many_days: create_month_day(yaml_hash: yaml_hash['days'])
350
+ )
351
+ end
352
+
353
+ def create_month_number(yaml_hash: {})
354
+ Number.new(
355
+ src: Operation::TypeParser.month_number(str: yaml_hash['src']),
356
+ dest: Operation::TypeParser.month_number(str: yaml_hash['dest'])
357
+ )
358
+ end
359
+
360
+ def create_month_leaped(yaml_hash: {})
361
+ Leaped.new(
362
+ src: Operation::TypeParser.month_leaped(str: yaml_hash['src']),
363
+ dest: Operation::TypeParser.month_leaped(str: yaml_hash['dest'])
364
+ )
365
+ end
366
+
367
+ def create_month_day(yaml_hash: {})
368
+ Days.new(
369
+ src: yaml_hash['src'],
370
+ dest: yaml_hash['dest']
371
+ )
372
+ end
369
373
  end
370
- private_class_method :create_month_day
371
374
  end
372
375
  end
373
376
  end