zakuro 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -13
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/csv/month.csv +100 -79
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/gengou.rb +5 -5
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +26 -24
- data/lib/zakuro/calculation/base/year.rb +7 -7
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
- data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
- data/lib/zakuro/calculation/era/version/version.rb +12 -10
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
- data/lib/zakuro/calculation/monthly/const.rb +18 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
- data/lib/zakuro/calculation/monthly/month.rb +17 -17
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
- data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
- data/lib/zakuro/calculation/range/abstract_full_range.rb +40 -25
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +111 -109
- data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
- data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
- data/lib/zakuro/calculation/summary/internal/month.rb +32 -11
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +145 -118
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +57 -50
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +95 -92
- data/lib/zakuro/calculation/summary/western/single.rb +78 -76
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -119
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +63 -56
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +142 -92
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +119 -0
- data/lib/zakuro/context/version_class_resolver.rb +112 -0
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +8 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
- data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -34
- data/lib/zakuro/era/japan/gengou/resource/type.rb +45 -37
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
- data/lib/zakuro/era/japan/gengou.rb +28 -26
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +104 -88
- data/lib/zakuro/exception/case/pattern.rb +39 -3
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +17 -15
- data/lib/zakuro/exception/zakuro_error.rb +19 -1
- data/lib/zakuro/gateway/locale/date.rb +2 -2
- data/lib/zakuro/gateway/locale/range.rb +3 -3
- data/lib/zakuro/gateway/range.rb +3 -3
- data/lib/zakuro/gateway/single.rb +14 -3
- data/lib/zakuro/merchant.rb +79 -9
- data/lib/zakuro/operation/month/parser.rb +252 -249
- data/lib/zakuro/operation/month/type.rb +17 -8
- data/lib/zakuro/operation/month/validator.rb +148 -144
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/operation/yaml/month.yaml +955 -281
- data/lib/zakuro/output/response.rb +107 -141
- data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
- data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
- data/lib/zakuro/result/data/single_day.rb +9 -1
- data/lib/zakuro/result/operation/month/annotation.rb +2 -2
- data/lib/zakuro/result/operation/month/history.rb +2 -2
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +39 -0
- data/lib/zakuro/result/result.rb +3 -3
- data/lib/zakuro/tools/stringifier.rb +67 -42
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
- data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
- data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/senmyou/const/remainder.rb +7 -1
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
- metadata +27 -7
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
- data/lib/zakuro/result/operation/operation.rb +0 -44
- data/lib/zakuro/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
data/lib/zakuro/merchant.rb
CHANGED
@@ -6,7 +6,9 @@ require_relative './gateway/range'
|
|
6
6
|
|
7
7
|
require_relative './condition'
|
8
8
|
|
9
|
-
require_relative './
|
9
|
+
require_relative './exception/exception'
|
10
|
+
|
11
|
+
require_relative './calculation/type/optional'
|
10
12
|
|
11
13
|
# :nodoc:
|
12
14
|
module Zakuro
|
@@ -15,6 +17,8 @@ module Zakuro
|
|
15
17
|
# 東西の暦を取引する、素敵な笑顔の持ち主
|
16
18
|
#
|
17
19
|
class Merchant
|
20
|
+
# @return [Output::Logger] ロガー
|
21
|
+
LOGGER = Output::Logger.new(location: Merchant)
|
18
22
|
# @return [Hash<Symbol, Object>] 条件
|
19
23
|
attr_reader :condition
|
20
24
|
|
@@ -23,11 +27,17 @@ module Zakuro
|
|
23
27
|
#
|
24
28
|
# @param [Hash<Symbol, Object>] condition 条件
|
25
29
|
#
|
30
|
+
# @raise [Exception::ZakuroError] ライブラリ内エラー
|
31
|
+
#
|
26
32
|
def initialize(condition: {})
|
27
33
|
failed = Condition.validate(hash: condition)
|
28
|
-
raise
|
34
|
+
raise Exception.get(presets: failed) unless failed.empty?
|
29
35
|
|
30
36
|
@condition = Condition.new(hash: condition)
|
37
|
+
rescue Exception::ZakuroError => e
|
38
|
+
raise e
|
39
|
+
rescue StandardError => e
|
40
|
+
make_internal_error(error: e)
|
31
41
|
end
|
32
42
|
|
33
43
|
#
|
@@ -37,13 +47,19 @@ module Zakuro
|
|
37
47
|
#
|
38
48
|
# @return [Merchant] 自インスタンス
|
39
49
|
#
|
50
|
+
# @raise [Exception::ZakuroError] ライブラリ内エラー
|
51
|
+
#
|
40
52
|
def offer(condition: {})
|
41
53
|
failed = Condition.validate(hash: condition)
|
42
|
-
raise
|
54
|
+
raise Exception.get(presets: failed) unless failed.empty?
|
43
55
|
|
44
|
-
|
56
|
+
condition.rewrite(hash: condition)
|
45
57
|
|
46
58
|
self
|
59
|
+
rescue Exception::ZakuroError => e
|
60
|
+
raise e
|
61
|
+
rescue StandardError => e
|
62
|
+
make_internal_error(error: e)
|
47
63
|
end
|
48
64
|
|
49
65
|
#
|
@@ -52,19 +68,73 @@ module Zakuro
|
|
52
68
|
# @return [Result::SingleDay] 和暦日
|
53
69
|
# @return [Result::Range] 和暦日範囲
|
54
70
|
#
|
71
|
+
# @raise [Exception::ZakuroError] ライブラリ内エラー
|
72
|
+
#
|
55
73
|
def commit
|
56
|
-
|
57
|
-
|
74
|
+
context = Context::Context.new(options: condition.options)
|
75
|
+
|
76
|
+
result = get(context: context)
|
77
|
+
|
78
|
+
return result.get unless result.invalid?
|
58
79
|
|
80
|
+
make_uncommitable_error
|
81
|
+
rescue Exception::ZakuroError => e
|
82
|
+
raise e
|
83
|
+
rescue StandardError => e
|
84
|
+
make_internal_error(error: e)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
#
|
90
|
+
# 結果取得する
|
91
|
+
#
|
92
|
+
# @param [Context::Context] context 暦コンテキスト
|
93
|
+
#
|
94
|
+
# @return [Calculation::Type::Optional] 参照
|
95
|
+
#
|
96
|
+
def get(context:)
|
59
97
|
single = Gateway::Single.new(context: context, date: condition.date)
|
60
98
|
|
61
|
-
return single.get unless single.invalid?
|
99
|
+
return Calculation::Type::Optional.new(obj: single.get) unless single.invalid?
|
62
100
|
|
63
101
|
range = Gateway::Range.new(context: context, range: condition.range)
|
64
102
|
|
65
|
-
return range.get unless range.invalid?
|
103
|
+
return Calculation::Type::Optional.new(obj: range.get) unless range.invalid?
|
104
|
+
|
105
|
+
Calculation::Type::Optional.new
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# 内部エラーを生成する
|
110
|
+
#
|
111
|
+
# @param [StandardError] error 内部エラー
|
112
|
+
#
|
113
|
+
# @raise [Exception::ZakuroError] ライブラリ内エラー
|
114
|
+
#
|
115
|
+
def make_internal_error(error:)
|
116
|
+
LOGGER.error(error)
|
117
|
+
presets = [
|
118
|
+
Exception::Case::Preset.new(
|
119
|
+
template: Exception::Case::Pattern::INTERNAL_ERROR
|
120
|
+
)
|
121
|
+
]
|
122
|
+
raise Exception.get(presets: presets)
|
123
|
+
end
|
66
124
|
|
67
|
-
|
125
|
+
#
|
126
|
+
# 内部エラーを生成する
|
127
|
+
#
|
128
|
+
# @raise [Exception::ZakuroError] ライブラリ内エラー
|
129
|
+
#
|
130
|
+
def make_uncommitable_error
|
131
|
+
raise Exception.get(
|
132
|
+
presets: [
|
133
|
+
Exception::Case::Preset.new(
|
134
|
+
template: Exception::Case::Pattern::UNCOMMITTABLE_DATE
|
135
|
+
)
|
136
|
+
]
|
137
|
+
)
|
68
138
|
end
|
69
139
|
end
|
70
140
|
end
|