zakuro 0.6.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +58 -16
  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 +50 -4
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +6 -6
  11. data/lib/zakuro/calculation/base/operated_year.rb +3 -3
  12. data/lib/zakuro/calculation/base/year.rb +4 -4
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +5 -3
  14. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
  15. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  17. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  26. data/lib/zakuro/calculation/{gengou → era/gengou}/internal/reserve.rb +6 -7
  27. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  28. data/lib/zakuro/calculation/{version → era/version}/internal/crawler.rb +7 -7
  29. data/lib/zakuro/calculation/{version → era/version}/internal/range.rb +4 -4
  30. data/lib/zakuro/calculation/{version → era/version}/version.rb +3 -3
  31. data/lib/zakuro/calculation/monthly/initialized_month.rb +1 -1
  32. data/lib/zakuro/calculation/monthly/month.rb +44 -5
  33. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  34. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  35. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  36. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +29 -27
  37. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +11 -14
  38. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  39. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  40. data/lib/zakuro/calculation/range/medieval_annual_range.rb +2 -2
  41. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  42. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  43. data/lib/zakuro/calculation/range/operated_solar_terms.rb +9 -11
  44. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +6 -6
  45. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +2 -0
  46. data/lib/zakuro/calculation/summary/internal/day.rb +40 -0
  47. data/lib/zakuro/calculation/summary/internal/month.rb +92 -0
  48. data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -40
  49. data/lib/zakuro/calculation/summary/internal/option.rb +85 -0
  50. data/lib/zakuro/calculation/summary/japan/range.rb +158 -0
  51. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  52. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +96 -0
  53. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  54. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  55. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +174 -0
  56. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +98 -0
  57. data/lib/zakuro/calculation/type/optional.rb +46 -0
  58. data/lib/zakuro/condition.rb +75 -22
  59. data/lib/zakuro/context/context.rb +44 -0
  60. data/lib/zakuro/context/option.rb +117 -0
  61. data/lib/zakuro/context/version_class_resolver.rb +110 -0
  62. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +125 -0
  63. data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
  64. data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
  65. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
  66. data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
  67. data/lib/zakuro/era/japan/gengou/resource/parser.rb +245 -0
  68. data/lib/zakuro/era/japan/gengou/resource/type.rb +299 -0
  69. data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
  70. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-001-until-south.yaml +2 -2
  71. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-002-from-north.yaml +2 -2
  72. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-003-modern.yaml +2 -2
  73. data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
  74. data/lib/zakuro/era/japan/gengou.rb +25 -79
  75. data/lib/zakuro/era/japan/version.rb +18 -18
  76. data/lib/zakuro/era/western/calendar.rb +13 -9
  77. data/lib/zakuro/exception/case/pattern.rb +71 -0
  78. data/lib/zakuro/exception/case/preset.rb +51 -0
  79. data/lib/zakuro/exception/case/template.rb +48 -0
  80. data/lib/zakuro/exception/cause.rb +28 -0
  81. data/lib/zakuro/exception/exception.rb +37 -0
  82. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  83. data/lib/zakuro/gateway/locale/date.rb +127 -0
  84. data/lib/zakuro/gateway/locale/range.rb +67 -0
  85. data/lib/zakuro/gateway/range.rb +99 -0
  86. data/lib/zakuro/gateway/single.rb +70 -0
  87. data/lib/zakuro/merchant.rb +84 -12
  88. data/lib/zakuro/operation/month/parser.rb +11 -9
  89. data/lib/zakuro/operation/month/type.rb +31 -31
  90. data/lib/zakuro/operation/month/validator.rb +50 -50
  91. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  92. data/lib/zakuro/output/logger.rb +17 -3
  93. data/lib/zakuro/output/response.rb +24 -57
  94. data/lib/zakuro/result/data/day.rb +43 -0
  95. data/lib/zakuro/result/data/gengou.rb +35 -0
  96. data/lib/zakuro/result/data/month.rb +63 -0
  97. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  98. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  99. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  100. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  101. data/lib/zakuro/result/data/single_day.rb +56 -0
  102. data/lib/zakuro/result/data/solar_term.rb +35 -0
  103. data/lib/zakuro/result/data/year.rb +45 -0
  104. data/lib/zakuro/result/operation/bundle.rb +44 -0
  105. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  106. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  107. data/lib/zakuro/result/operation/month/history.rb +54 -0
  108. data/lib/zakuro/result/result.rb +21 -2
  109. data/lib/zakuro/tools/stringifier.rb +26 -3
  110. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  111. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  112. data/lib/zakuro/version/daien/range/annual_range.rb +1 -1
  113. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +2 -0
  114. data/lib/zakuro/version/daien/stella/lunar/value.rb +2 -0
  115. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  116. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  117. data/lib/zakuro/version/genka/range/annual_range.rb +1 -1
  118. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  119. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  120. data/lib/zakuro/version/gihou/range/annual_range.rb +1 -1
  121. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +2 -0
  122. data/lib/zakuro/version/gihou/stella/lunar/value.rb +2 -0
  123. data/lib/zakuro/version/senmyou/README.md +11 -7
  124. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  125. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  126. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  127. data/lib/zakuro/version/senmyou/range/annual_range.rb +1 -1
  128. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +2 -0
  129. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +2 -0
  130. metadata +85 -24
  131. data/lib/zakuro/calculation/gengou/internal/counter.rb +0 -129
  132. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +0 -183
  133. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +0 -382
  134. data/lib/zakuro/calculation/gengou/scroll.rb +0 -262
  135. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  136. data/lib/zakuro/era/japan/gengou/parser.rb +0 -237
  137. data/lib/zakuro/era/japan/gengou/type.rb +0 -285
  138. data/lib/zakuro/era/japan/gengou/validator.rb +0 -341
  139. data/lib/zakuro/result/data.rb +0 -187
  140. data/lib/zakuro/result/operation.rb +0 -114
  141. data/lib/zakuro/version/context.rb +0 -44
  142. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../range/dated_operation_range'
4
+
5
+ require_relative '../../range/dated_full_range'
6
+
7
+ require_relative './specifier/single_day'
8
+
9
+ require_relative '../internal/operation'
10
+
11
+ # :nodoc:
12
+ module Zakuro
13
+ # :nodoc:
14
+ module Calculation
15
+ # :nodoc:
16
+ module Summary
17
+ # :nodoc:
18
+ module Western
19
+ #
20
+ # Single 一日
21
+ #
22
+ module Single
23
+ #
24
+ # 生成する
25
+ #
26
+ # @param [Context::Context] context 暦コンテキスト
27
+ # @param [Western::Calendar] date 西暦日
28
+ #
29
+ # @return [Result::Single] 一日検索結果(和暦日)
30
+ #
31
+ def self.get(context:, date: Western::Calendar.new)
32
+ years = get_full_range_years(context: context, date: date)
33
+
34
+ data = get_data(context: context, years: years, date: date)
35
+
36
+ operation = get_operation(years: years, date: date)
37
+
38
+ Result::Single.new(
39
+ data: data,
40
+ operation: operation
41
+ )
42
+ end
43
+
44
+ #
45
+ # 完全範囲を取得する
46
+ #
47
+ # @param [Context::Context] context 暦コンテキスト
48
+ # @param [Western::Calendar] date 西暦日
49
+ #
50
+ # @return [Array<Calculation::Base::Year>] 完全範囲
51
+ #
52
+ def self.get_full_range_years(context:, date: Western::Calendar.new)
53
+ full_range = Calculation::Range::DatedFullRange.new(context: context, start_date: date)
54
+ full_range.get
55
+ end
56
+ private_class_method :get_full_range_years
57
+
58
+ #
59
+ # 運用結果範囲を取得する
60
+ #
61
+ # @param [Context::Context] context 暦コンテキスト
62
+ # @param [Array<Calculation::Base::Year>] years 完全範囲
63
+ # @param [Western::Calendar] date 西暦日
64
+ #
65
+ # @return [Array<Base::OperatedYear>] 運用結果範囲
66
+ #
67
+ def self.get_operation_range_years(context:, years:, date: Western::Calendar.new)
68
+ operation_range = Calculation::Range::DatedOperationRange.new(
69
+ context: context, start_date: date, years: years
70
+ )
71
+ operation_range.get
72
+ end
73
+ private_class_method :get_operation_range_years
74
+
75
+ #
76
+ # 1日を取得する
77
+ #
78
+ # @param [Context::Context] context 暦コンテキスト
79
+ # @param [Array<Calculation::Base::Year>] years 完全範囲
80
+ # @param [Western::Calendar] date 西暦日
81
+ #
82
+ # @return [Data::SingleDay] 1日
83
+ #
84
+ def self.get_data(context:, years:, date: Western::Calendar.new)
85
+ operated_years = get_operation_range_years(context: context, years: years, date: date)
86
+
87
+ Specifier::SingleDay.get(
88
+ years: operated_years, date: date
89
+ )
90
+ end
91
+ private_class_method :get_data
92
+
93
+ #
94
+ # 完全範囲を取得する
95
+ #
96
+ # @param [Array<Calculation::Base::Year>] years 完全範囲
97
+ # @param [Western::Calendar] date 西暦日
98
+ #
99
+ # @return [Array<Calculation::Base::Year>] 完全範囲
100
+ #
101
+ def self.get_operation(years:, date: Western::Calendar.new)
102
+ calc_date = Specifier::SingleDay.get(
103
+ years: years, date: date
104
+ )
105
+
106
+ Operation.create(calc_date: calc_date)
107
+ end
108
+ private_class_method :get_operation
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../era/western/calendar'
4
+ require_relative '../../../../output/response'
5
+ require_relative '../../../../output/logger'
6
+
7
+ require_relative '../../../base/year'
8
+
9
+ require_relative '../../internal/month'
10
+
11
+ # :nodoc:
12
+ module Zakuro
13
+ # :nodoc:
14
+ module Calculation
15
+ # :nodoc:
16
+ module Summary
17
+ # :nodoc:
18
+ module Western
19
+ # :nodoc:
20
+ module Specifier
21
+ #
22
+ # MultipleDay 複数日検索
23
+ #
24
+ module MultipleDay
25
+ # @return [Output::Logger] ロガー
26
+ LOGGER = Output::Logger.new(location: 'specifier')
27
+
28
+ #
29
+ # 取得する
30
+ #
31
+ # @param [Context::Context] context 暦コンテキスト
32
+ # @param [Array<Calculation::Base::Year>] years 範囲
33
+ # @param [Western::Calendar] start_date 西暦開始日
34
+ # @param [Western::Calendar] last_date 西暦終了日
35
+ #
36
+ # @return [Array<Result::Data::SingleDay>] 期間検索結果(和暦日)
37
+ #
38
+ def self.get(context:, years: [], start_date: Western::Calendar.new,
39
+ last_date: Western::Calendar.new)
40
+ months = specify(
41
+ context: context, years: years, start_date: start_date, last_date: last_date
42
+ )
43
+
44
+ result = []
45
+ months.each do |month|
46
+ result |= month.get
47
+ end
48
+
49
+ result
50
+ end
51
+
52
+ #
53
+ # 年を特定する
54
+ #
55
+ # @param [Context::Context] context 暦コンテキスト
56
+ # @param [Array<Calculation::Base::Year>] years 範囲
57
+ # @param [Western::Calendar] start_date 西暦開始日
58
+ # @param [Western::Calendar] last_date 西暦終了日
59
+ #
60
+ # @return [Array<Month>] 特定月
61
+ #
62
+ def self.specify(context:, years: [], start_date: Western::Calendar.new,
63
+ last_date: Western::Calendar.new)
64
+ result = []
65
+ years.each do |year|
66
+ result |= specify_month(
67
+ context: context, year: year, start_date: start_date, last_date: last_date
68
+ )
69
+ end
70
+
71
+ result
72
+ end
73
+ private_class_method :specify
74
+
75
+ # :reek:TooManyStatements { max_statements: 7 }
76
+
77
+ #
78
+ # 月を特定する
79
+ #
80
+ # @param [Context::Context] context 暦コンテキスト
81
+ # @param [Calculation::Base::Year] year 年
82
+ # @param [Western::Calendar] start_date 西暦開始日
83
+ # @param [Western::Calendar] last_date 西暦終了日
84
+ #
85
+ # @return [Month] 対象月
86
+ #
87
+ def self.specify_month(context:, year:, start_date: Western::Calendar.new,
88
+ last_date: Western::Calendar.new)
89
+ months = year.months
90
+
91
+ specify_months = []
92
+ months.each do |month|
93
+ next unless include?(month: month, start_date: start_date, last_date: last_date)
94
+
95
+ monthly_start_date = month.western_date.clone
96
+ monthly_last_date = month.last_date.clone
97
+
98
+ monthly_start_date = start_date.clone if start_date > monthly_start_date
99
+
100
+ monthly_last_date = last_date.clone if last_date < monthly_last_date
101
+
102
+ specify_months.push(
103
+ Month.new(context: context, year: year, month: month,
104
+ start_date: monthly_start_date, last_date: monthly_last_date)
105
+ )
106
+ end
107
+
108
+ specify_months
109
+ end
110
+ private_class_method :specify_month
111
+
112
+ #
113
+ # 月が範囲に含まれるか
114
+ #
115
+ # @param [Calculation::Monthly::Month] month 月
116
+ # @param [Western::Calendar] start_date 西暦開始日
117
+ # @param [Western::Calendar] last_date 西暦終了日
118
+ #
119
+ # @return [True] 含む
120
+ # @return [False] 含まない
121
+ #
122
+ def self.include?(month:, start_date:, last_date:)
123
+ monthly_start_date = month.western_date.clone
124
+ monthly_last_date = month.last_date.clone
125
+
126
+ return false if monthly_start_date.invalid?
127
+
128
+ return false if monthly_last_date.invalid?
129
+
130
+ return false if under(monthly_start_date: monthly_start_date,
131
+ start_date: start_date, last_date: last_date)
132
+
133
+ return false if over(monthly_last_date: monthly_last_date,
134
+ start_date: start_date, last_date: last_date)
135
+
136
+ true
137
+ end
138
+ private_class_method :include?
139
+
140
+ #
141
+ # 範囲が月より前にあるか
142
+ #
143
+ # @param [Western::Calendar] monthly_start_date 月初日
144
+ # @param [Western::Calendar] start_date 西暦開始日
145
+ # @param [Western::Calendar] last_date 西暦終了日
146
+ #
147
+ # @return [True] 前にある
148
+ # @return [False] 前にない
149
+ #
150
+ def self.under(monthly_start_date:, start_date:, last_date:)
151
+ start_date < monthly_start_date && last_date < monthly_start_date
152
+ end
153
+ private_class_method :under
154
+
155
+ #
156
+ # 範囲が月より後にあるか
157
+ #
158
+ # @param [Western::Calendar] monthly_start_date 月末日
159
+ # @param [Western::Calendar] start_date 西暦開始日
160
+ # @param [Western::Calendar] last_date 西暦終了日
161
+ #
162
+ # @return [True] 後にある
163
+ # @return [False] 後にない
164
+ #
165
+ def self.over(monthly_last_date:, start_date:, last_date:)
166
+ start_date > monthly_last_date && last_date > monthly_last_date
167
+ end
168
+ private_class_method :over
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../era/western/calendar'
4
+ require_relative '../../../../output/response'
5
+ require_relative '../../../../output/logger'
6
+
7
+ require_relative '../../../base/year'
8
+
9
+ require_relative '../../internal/day'
10
+ require_relative '../../internal/option'
11
+
12
+ # :nodoc:
13
+ module Zakuro
14
+ # :nodoc:
15
+ module Calculation
16
+ # :nodoc:
17
+ module Summary
18
+ # :nodoc:
19
+ module Western
20
+ # :nodoc:
21
+ module Specifier
22
+ #
23
+ # SingleDay 一日検索
24
+ #
25
+ module SingleDay
26
+ # @return [Output::Logger] ロガー
27
+ LOGGER = Output::Logger.new(location: 'specifier')
28
+
29
+ #
30
+ # 取得する
31
+ #
32
+ # @param [Array<Calculation::Base::Year>] years 範囲
33
+ # @param [Western::Calendar] date 西暦日
34
+ #
35
+ # @return [Result::Data::SingleDay] 和暦日
36
+ #
37
+ def self.get(years: [], date: Western::Calendar.new)
38
+ year, month = specify(years: years, date: date)
39
+
40
+ day = Day.get(month: month, date: date)
41
+
42
+ options = Option.create(month: month, day: day)
43
+
44
+ Output::Response::SingleDay.create(
45
+ year: year, month: month, day: day, options: options
46
+ )
47
+ end
48
+
49
+ #
50
+ # 年を特定する
51
+ #
52
+ # @param [Array<Year>] years 範囲
53
+ # @param [Western::Calendar] date 西暦日
54
+ #
55
+ # @return [Base::Year] 対象年
56
+ # @return [Monthly::Month] 対象月
57
+ #
58
+ # @raise [ArgumentError] 引数エラー
59
+ #
60
+ def self.specify(years:, date:)
61
+ years.each do |year|
62
+ month = specify_month(year: year, date: date)
63
+ return year, month unless month.invalid?
64
+ end
65
+
66
+ raise ArgumentError, "invalid year range. date: #{date.format}"
67
+ end
68
+ private_class_method :specify
69
+
70
+ # :reek:TooManyStatements { max_statements: 7 }
71
+
72
+ #
73
+ # 月を特定する
74
+ #
75
+ # @param [Base::Year] year 年
76
+ # @param [Western::Calendar] date 西暦日
77
+ #
78
+ # @return [Monthly::Month] 対象月
79
+ #
80
+ def self.specify_month(year:, date:)
81
+ months = year.months
82
+
83
+ months.each do |month|
84
+ western_date = month.western_date
85
+ next if western_date.invalid?
86
+
87
+ return month if month.include?(date: date)
88
+ end
89
+
90
+ Monthly::Month.new
91
+ end
92
+ private_class_method :specify_month
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Type
9
+ #
10
+ # Optional 参照管理
11
+ #
12
+ # * インスタンスのnil操作を避ける
13
+ # * safe navigation operator を使用しない
14
+ #
15
+ class Optional
16
+ #
17
+ # 初期化
18
+ #
19
+ # @param [Object] obj インスタンス
20
+ #
21
+ def initialize(obj: nil)
22
+ @obj = obj
23
+ end
24
+
25
+ #
26
+ # インスタンスを取得する
27
+ #
28
+ # @return [Object] インスタンス
29
+ #
30
+ def get
31
+ @obj
32
+ end
33
+
34
+ #
35
+ # 不正か
36
+ #
37
+ # @return [True] 不正
38
+ # @return [False] 不正なし
39
+ #
40
+ def invalid?
41
+ @obj.nil?
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './exception/exception'
4
+
3
5
  require 'date'
4
6
 
5
7
  # :nodoc:
@@ -18,10 +20,9 @@ module Zakuro
18
20
  #
19
21
  # 初期化
20
22
  #
21
- # @param [Date] date 西暦日
23
+ # @param [Date, String] date 西暦日/和暦日
22
24
  #
23
25
  def initialize(date:)
24
- # TODO: 和暦日(String)から西暦日(Date)への変換
25
26
  @date = date
26
27
  end
27
28
 
@@ -30,7 +31,7 @@ module Zakuro
30
31
  #
31
32
  # @param [Date] date 日付
32
33
  #
33
- # @return [Array<String>] エラーメッセージ
34
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
34
35
  #
35
36
  def self.validate(date:)
36
37
  failed = []
@@ -38,7 +39,12 @@ module Zakuro
38
39
 
39
40
  return failed if date.is_a?(Date) || date.is_a?(String)
40
41
 
41
- failed.push("invalid date: #{date}")
42
+ failed.push(
43
+ Exception::Case::Preset.new(
44
+ date.class,
45
+ template: Exception::Case::Pattern::INVALID_DATE_TYPE
46
+ )
47
+ )
42
48
  failed
43
49
  end
44
50
  end
@@ -55,7 +61,7 @@ module Zakuro
55
61
  #
56
62
  # 初期化
57
63
  #
58
- # @param [Hash<Symbol>] hash パラメータ
64
+ # @param [Hash<Symbol, Object>] hash パラメータ
59
65
  # @option hash [Symbol] :start 開始日
60
66
  # @option hash [Symbol] :start 終了日
61
67
  #
@@ -69,16 +75,21 @@ module Zakuro
69
75
  #
70
76
  # 検証する
71
77
  #
72
- # @param [Hash<Symbol>] hash パラメータ
78
+ # @param [Hash<Symbol, Object>] hash パラメータ
73
79
  #
74
- # @return [Array<String>] エラーメッセージ
80
+ # @return [Array<Exception::Case::Preset>] エラープリセット
75
81
  #
76
82
  def self.validate(hash:)
77
83
  failed = []
78
84
  return failed unless hash
79
85
 
80
86
  unless hash.is_a?(Hash)
81
- failed.push("invalid range type. #{hash}. should be hash")
87
+ failed.push(
88
+ Exception::Case::Preset.new(
89
+ hash.class,
90
+ template: Exception::Case::Pattern::INVALID_RANGE_TYPE
91
+ )
92
+ )
82
93
  return failed
83
94
  end
84
95
 
@@ -87,6 +98,20 @@ module Zakuro
87
98
 
88
99
  failed
89
100
  end
101
+
102
+ #
103
+ # 不正か
104
+ #
105
+ # @return [True] 不正
106
+ # @return [False] 不正なし
107
+ #
108
+ def invalid?
109
+ return true unless @start
110
+
111
+ return true unless @end
112
+
113
+ false
114
+ end
90
115
  end
91
116
 
92
117
  #
@@ -111,7 +136,7 @@ module Zakuro
111
136
  #
112
137
  # @param [Array<String>] columns 列
113
138
  #
114
- # @return [Array<String>] エラーメッセージ
139
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
115
140
  #
116
141
  def self.validate(columns:)
117
142
  # TODO: 列内容のバリデーション
@@ -121,7 +146,12 @@ module Zakuro
121
146
 
122
147
  return failed if columns.is_a?(Array)
123
148
 
124
- failed.push("invalid columns type. #{columns}. should be array")
149
+ failed.push(
150
+ Exception::Case::Preset.new(
151
+ hash.class,
152
+ template: Exception::Case::Pattern::INVALID_COLUMN_TYPE
153
+ )
154
+ )
125
155
 
126
156
  failed
127
157
  end
@@ -131,8 +161,8 @@ module Zakuro
131
161
  # Options オプション
132
162
  # 取得内容を変更する
133
163
  #
134
- # * unit: 年/月/日
135
- # * lost_days: 没日あり
164
+ # * version:
165
+ # * dropped_days: 没日あり
136
166
  # * seasons: 四季あり
137
167
  #
138
168
  class Options
@@ -142,7 +172,7 @@ module Zakuro
142
172
  #
143
173
  # 初期化
144
174
  #
145
- # @param [Array<String>] options オプション
175
+ # @param [Hash<Symbol, Object>] options オプション
146
176
  #
147
177
  def initialize(options: [])
148
178
  @options = options
@@ -153,9 +183,9 @@ module Zakuro
153
183
  #
154
184
  # 検証する
155
185
  #
156
- # @param [Array<String>] options オプション
186
+ # @param [Hash<Symbol, Object>] options オプション
157
187
  #
158
- # @return [Array<String>] エラーメッセージ
188
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
159
189
  #
160
190
  def self.validate(options:)
161
191
  failed = []
@@ -163,8 +193,12 @@ module Zakuro
163
193
 
164
194
  return failed if options.is_a?(Hash)
165
195
 
166
- failed.push("invalid options type. #{options}. should be hash")
167
-
196
+ failed.push(
197
+ Exception::Case::Preset.new(
198
+ hash.class,
199
+ template: Exception::Case::Pattern::INVALID_OPTION_TYPE
200
+ )
201
+ )
168
202
  failed
169
203
  end
170
204
  end
@@ -180,7 +214,7 @@ module Zakuro
180
214
  attr_reader :range
181
215
  # @return [Array<String>] 列
182
216
  attr_reader :columns
183
- # @return [Array<String>] オプション
217
+ # @return [Hash<String, Object>] オプション
184
218
  attr_reader :options
185
219
 
186
220
  #
@@ -190,13 +224,13 @@ module Zakuro
190
224
  # @option hash [Date] :date 基準日
191
225
  # @option hash [Hash<Symbol, Date>] :range 範囲
192
226
  # @option hash [Array<String>] :columns 列
193
- # @option hash [Array<String>] :options オプション
227
+ # @option hash [Hash<String, Object>] :options オプション
194
228
  #
195
229
  def initialize(hash: {})
196
230
  @date = hash[:date]
197
231
  @range = hash[:range]
198
232
  @columns = hash[:columns]
199
- @options = hash[:options]
233
+ @options = hash[:options] || {}
200
234
  end
201
235
 
202
236
  # :reek:TooManyStatements { max_statements: 8 }
@@ -206,16 +240,35 @@ module Zakuro
206
240
  #
207
241
  # @param [Hash<Symbol, Object>] hash パラメータ
208
242
  #
209
- # @return [Array<String>] エラーメッセージ
243
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
210
244
  #
211
245
  def self.validate(hash:)
212
246
  failed = []
213
247
 
214
248
  unless hash.is_a?(Hash)
215
- failed.push("invalid condition type. #{hash}. should be hash")
249
+ failed.push(
250
+ Exception::Case::Preset.new(
251
+ hash.class,
252
+ template: Exception::Case::Pattern::INVALID_CONDITION_TYPE
253
+ )
254
+ )
216
255
  return failed
217
256
  end
218
257
 
258
+ failed.concat(validate_hash(hash: hash))
259
+
260
+ failed
261
+ end
262
+
263
+ #
264
+ # ハッシュ内を検証する
265
+ #
266
+ # @param [Hash<Symbol, Object>] hash パラメータ
267
+ #
268
+ # @return [Array<Exception::Case::Preset>] エラープリセット配列
269
+ #
270
+ def self.validate_hash(hash:)
271
+ failed = []
219
272
  failed.concat(Catalog::BasisDate.validate(date: hash[:date]))
220
273
  failed.concat(Catalog::Range.validate(hash: hash[:range]))
221
274
  failed.concat(Catalog::Columns.validate(columns: hash[:columns]))
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './option'
4
+
5
+ require_relative './version_class_resolver'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Context
11
+ #
12
+ # Context 暦コンテキスト
13
+ #
14
+ class Context
15
+ # @return [Option] オプション
16
+ attr_reader :option
17
+ # @return [VersionClassResolver] 暦リゾルバー
18
+ attr_reader :resolver
19
+
20
+ #
21
+ # 初期化
22
+ #
23
+ # @param [Hash<String, Object>] options オプション値
24
+ #
25
+ # @raise [ArgumentError] 引数エラー
26
+ #
27
+ def initialize(version: Option::INVALID_VERSION_NAME, options: {})
28
+ @option = Option.new(default_version: version, hash: options)
29
+
30
+ @resolver = VersionClassResolver.new(version_name: option.version)
31
+ end
32
+
33
+ #
34
+ # 不正か
35
+ #
36
+ # @return [True] 不正
37
+ # @return [False] 不正なし
38
+ #
39
+ def invalid?
40
+ !@option.version?
41
+ end
42
+ end
43
+ end
44
+ end