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
@@ -6,36 +6,51 @@ require_relative './resource'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
9
- #
10
- # Japan 和暦
11
- #
9
+ # :nodoc:
12
10
  module Japan
13
- #
14
- # Alignment 整列
15
- #
16
- module Alignment
17
- # @return [Integer] 1行目元号
18
- FIRST_LINE = Aligner::FIRST_LINE
11
+ # :nodoc:
12
+ module Gengou
13
+ #
14
+ # Alignment 整列
15
+ #
16
+ module Alignment
17
+ # @return [Integer] 1行目元号
18
+ FIRST_LINE = Aligner::FIRST_LINE
19
19
 
20
- # @return [Integer] 2行目元号
21
- SECOND_LINE = Aligner::SECOND_LINE
20
+ # @return [Integer] 2行目元号
21
+ SECOND_LINE = Aligner::SECOND_LINE
22
22
 
23
- # @return [Aligner] 整列結果
24
- SUMMARY = Aligner.new(resources: Resource::LIST)
23
+ # @return [Aligner] 整列結果
24
+ SUMMARY = Aligner.new(resources: Resource::LIST)
25
25
 
26
- #
27
- # 指定した範囲内の元号を取得する
28
- #
29
- # @param [Integer] line 行
30
- # @param [Western::Calendar] start_date 開始日
31
- # @param [Western::Calendar] last_date 終了日
32
- #
33
- # @return [Array<LinearGengou>] 元号
34
- #
35
- def self.get(line: FIRST_LINE,
36
- start_date: Western::Calendar.new, last_date: Western::Calendar.new)
26
+ class << self
27
+ #
28
+ # 指定した範囲内の元号を取得する
29
+ #
30
+ # @param [Integer] line
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] last_date 終了日
33
+ #
34
+ # @return [Array<LinearGengou>] 元号
35
+ #
36
+ def get(line: FIRST_LINE,
37
+ start_date: Western::Calendar.new, last_date: Western::Calendar.new)
38
+
39
+ SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
40
+ end
37
41
 
38
- SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
42
+ #
43
+ # 指定した範囲内の元号を取得する(元号名)
44
+ #
45
+ # @param [Integer] line 行
46
+ # @param [String] name 元号名
47
+ #
48
+ # @return [Array<LinearGengou>] 元号
49
+ #
50
+ def get_by_name(line: FIRST_LINE, name:)
51
+ SUMMARY.get_by_name(line: line, name: name)
52
+ end
53
+ end
39
54
  end
40
55
  end
41
56
  end
@@ -7,236 +7,254 @@ 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
-
92
- #
93
- # 元号セット情報を生成する
23
+ module Parser
94
24
  #
95
- # @return [Set] 元号セット情報
25
+ # GengouParser 元号情報の検証/展開を行う
96
26
  #
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
104
-
105
- # :reek:TooManyStatements { max_statements: 7 }
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
106
36
 
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
+ start_year = Both::YearParser.new(hash: both_start_year).create
57
+ 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: start_year,
60
+ both_start_date: 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
98
+ 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: last_date, list: list
102
+ )
103
+ end
104
+
105
+ # :reek:TooManyStatements { max_statements: 7 }
184
106
 
185
- Japan::Resource::Both::Year.new(japan: japan, western: western)
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)
120
+ end
121
+
122
+ result
186
123
  end
187
- end
188
124
 
189
- #
190
- # DateParser 日
191
- #
192
- class DateParser
193
- # @return [Japan::Calendar] 和暦日
194
- attr_reader :japan
195
- # @return [Western::Calendar] 西暦日
196
- attr_reader :western
125
+ #
126
+ # 次の元号の開始日から、元号の終了日に変換する
127
+ #
128
+ # @param [Integer] next_index 次の元号の要素位置
129
+ # @param [GengouParser] gengou 元号
130
+ #
131
+ # @return [Gengou] 元号情報
132
+ #
133
+ def calc_last_date_on_gengou_data(next_index:, gengou:)
134
+ if next_index >= list.size
135
+ last_gengou_data(gengou: gengou)
136
+ return gengou
137
+ end
138
+ next_item = list[next_index]
139
+ gengou.convert_next_start_year_to_last_year(
140
+ next_start_year: next_item['start_year']['western']
141
+ )
142
+ gengou.convert_next_start_date_to_last_date(
143
+ next_start_date: next_item['start_date']['western']
144
+ )
145
+ gengou
146
+ end
147
+
148
+ private
197
149
 
198
150
  #
199
- # 初期化
151
+ # 最後の元号の終了日を設定する
200
152
  #
201
- # @param [Hash<String, Object>] hash 日情報
153
+ # @param [GengouParser] gengou 元号
202
154
  #
203
- def initialize(hash:)
204
- @japan = hash['japan']
205
- @western = hash['western']
155
+ def last_gengou_data(gengou:)
156
+ gengou.write_last_year(last_year: both_last_year['western'])
157
+ last_date = Western::Calendar.parse(text: both_last_date['western'])
158
+ gengou.write_last_date(last_date: last_date)
206
159
  end
160
+ end
207
161
 
162
+ #
163
+ # 和暦/西暦
164
+ #
165
+ module Both
208
166
  #
209
- # 日情報を生成する
167
+ # YearParser 年
210
168
  #
211
- # @return [Both::Date] 日情報
169
+ class YearParser
170
+ # @return [Integer] 和暦元号年
171
+ attr_reader :japan
172
+ # @return [Integer] 西暦年
173
+ attr_reader :western
174
+
175
+ #
176
+ # 初期化
177
+ #
178
+ # @param [Hash<String, Object>] hash 年情報
179
+ #
180
+ def initialize(hash:)
181
+ @japan = hash['japan']
182
+ @western = hash['western']
183
+ end
184
+
185
+ #
186
+ # 年情報を生成する
187
+ #
188
+ # @return [Both::Year] 年情報
189
+ #
190
+ def create
191
+ japan_year = japan.to_i
192
+ western_year = western.to_i
193
+
194
+ Japan::Gengou::Resource::Both::Year.new(
195
+ japan: japan_year, western: western_year
196
+ )
197
+ end
198
+ end
199
+
212
200
  #
213
- def create
214
- japan = Japan::Calendar.parse(text: @japan)
215
- western = Western::Calendar.parse(str: @western)
201
+ # DateParser 日
202
+ #
203
+ class DateParser
204
+ # @return [Japan::Calendar] 和暦日
205
+ attr_reader :japan
206
+ # @return [Western::Calendar] 西暦日
207
+ attr_reader :western
208
+
209
+ #
210
+ # 初期化
211
+ #
212
+ # @param [Hash<String, Object>] hash 日情報
213
+ #
214
+ def initialize(hash:)
215
+ @japan = hash['japan']
216
+ @western = hash['western']
217
+ end
218
+
219
+ #
220
+ # 日情報を生成する
221
+ #
222
+ # @return [Both::Date] 日情報
223
+ #
224
+ def create
225
+ japan_date = Japan::Calendar.parse(text: japan)
226
+ western_date = Western::Calendar.parse(text: western)
216
227
 
217
- Japan::Resource::Both::Date.new(japan: japan, western: western)
228
+ Japan::Gengou::Resource::Both::Date.new(
229
+ japan: japan_date, western: western_date
230
+ )
231
+ end
218
232
  end
219
233
  end
220
- end
221
234
 
222
- #
223
- # 解析/展開する
224
- #
225
- # @param [String] filepath 元号セットファイルパス
226
- #
227
- # @return [Set] 元号セット情報
228
- #
229
- def self.run(filepath: '')
230
- yaml = YAML.load_file(filepath)
235
+ class << self
236
+ #
237
+ # 解析/展開する
238
+ #
239
+ # @param [String] filepath 元号セットファイルパス
240
+ #
241
+ # @return [Set] 元号セット情報
242
+ #
243
+ # @raise [ArgumentError] 引数エラー
244
+ #
245
+ def run(filepath: '')
246
+ yaml = YAML.load_file(filepath)
231
247
 
232
- failed = Validator.run(yaml_hash: yaml)
248
+ failed = Validator.run(yaml_hash: yaml)
233
249
 
234
- raise ArgumentError, failed.join("\n") unless failed.empty?
250
+ raise ArgumentError, failed.join("\n") unless failed.empty?
235
251
 
236
- parser = SetParser.new(hash: yaml)
237
- parser.create
252
+ parser = SetParser.new(hash: yaml)
253
+ parser.create
254
+ end
255
+ end
238
256
  end
239
257
  end
258
+ end
240
259
  end
241
260
  end
242
- end