zakuro 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +3 -0
- data/README.md +22 -7
- data/VERSION +1 -0
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/gengou.rb +128 -0
- data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
- data/lib/zakuro/calculation/base/operated_year.rb +5 -15
- data/lib/zakuro/calculation/base/year.rb +26 -14
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +41 -0
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
- data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
- data/lib/zakuro/calculation/era/version/version.rb +24 -0
- data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
- data/lib/zakuro/calculation/monthly/month.rb +88 -2
- data/lib/zakuro/calculation/monthly/operated_month.rb +3 -3
- data/lib/zakuro/calculation/range/abstract_full_range.rb +172 -0
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +17 -15
- data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
- data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
- data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
- data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -19
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
- data/lib/zakuro/calculation/summary/internal/month.rb +84 -0
- data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -37
- data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -0
- data/lib/zakuro/calculation/summary/western/range.rb +124 -0
- data/lib/zakuro/calculation/summary/western/single.rb +113 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +169 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
- data/lib/zakuro/condition.rb +15 -2
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +121 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +243 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +293 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
- data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
- data/lib/zakuro/era/japan/gengou.rb +26 -80
- data/lib/zakuro/era/japan/version.rb +151 -0
- data/lib/zakuro/era/{western.rb → western/calendar.rb} +9 -9
- data/lib/zakuro/exception/case/pattern.rb +35 -0
- data/lib/zakuro/exception/case/preset.rb +51 -0
- data/lib/zakuro/exception/case/template.rb +48 -0
- data/lib/zakuro/exception/cause.rb +28 -0
- data/lib/zakuro/exception/exception.rb +37 -0
- data/lib/zakuro/exception/zakuro_error.rb +28 -0
- data/lib/zakuro/gateway/locale/date.rb +127 -0
- data/lib/zakuro/gateway/locale/range.rb +67 -0
- data/lib/zakuro/gateway/range.rb +99 -0
- data/lib/zakuro/gateway/single.rb +70 -0
- data/lib/zakuro/merchant.rb +15 -4
- data/lib/zakuro/operation/month/parser.rb +10 -10
- data/lib/zakuro/operation/month/type.rb +32 -32
- data/lib/zakuro/operation/month/validator.rb +51 -51
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +5 -5
- data/lib/zakuro/result/data/day.rb +43 -0
- data/lib/zakuro/result/data/gengou.rb +35 -0
- data/lib/zakuro/result/data/month.rb +63 -0
- data/lib/zakuro/result/data/single_day.rb +48 -0
- data/lib/zakuro/result/data/solar_term.rb +35 -0
- data/lib/zakuro/result/data/year.rb +45 -0
- data/lib/zakuro/result/operation/month/annotation.rb +40 -0
- data/lib/zakuro/result/operation/month/bundle.rb +36 -0
- data/lib/zakuro/result/operation/month/history.rb +54 -0
- data/lib/zakuro/result/operation/operation.rb +44 -0
- data/lib/zakuro/result/result.rb +21 -2
- data/lib/zakuro/tools/typeconv.rb +38 -0
- data/lib/zakuro/tools/typeof.rb +4 -1
- data/lib/zakuro/version/context.rb +24 -3
- data/lib/zakuro/version/daien/daien.rb +1 -26
- data/lib/zakuro/version/genka/genka.rb +1 -26
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
- data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
- data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
- data/lib/zakuro/version/kansei/kansei.rb +1 -9
- data/lib/zakuro/version/senmyou/README.md +11 -7
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/zakuro.gemspec +1 -3
- metadata +74 -22
- data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
- data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
- data/lib/zakuro/calculation/range/full_range.rb +0 -210
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -109
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
- data/lib/zakuro/era/japan/gengou/type.rb +0 -178
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
- data/lib/zakuro/era/japan/reki.rb +0 -91
- data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
- data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
- data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/result/operation.rb +0 -114
- data/lib/zakuro/version/abstract_version.rb +0 -29
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
id: 3
|
3
|
+
name: 近代(一世一元)
|
4
|
+
last_year:
|
5
|
+
japan: 7981
|
6
|
+
western: 9999
|
7
|
+
last_date:
|
8
|
+
japan: 令和7981年12月31日
|
9
|
+
western: '9999-12-31'
|
10
|
+
list:
|
11
|
+
- name: 明治
|
12
|
+
start_year:
|
13
|
+
japan: 1
|
14
|
+
western: 1868
|
15
|
+
start_date:
|
16
|
+
japan: 明治01年09月08日
|
17
|
+
western: '1868-10-23'
|
18
|
+
disuse:
|
19
|
+
new_year_date: '1868-1-25'
|
20
|
+
note: ''
|
21
|
+
- name: 大正
|
22
|
+
start_year:
|
23
|
+
japan: 1
|
24
|
+
western: 1912
|
25
|
+
start_date:
|
26
|
+
japan: 大正01年07月30日
|
27
|
+
western: '1912-7-30'
|
28
|
+
disuse:
|
29
|
+
new_year_date: '1912-1-1'
|
30
|
+
note: ''
|
31
|
+
- name: 昭和
|
32
|
+
start_year:
|
33
|
+
japan: 1
|
34
|
+
western: 1926
|
35
|
+
start_date:
|
36
|
+
japan: 昭和01年12月25日
|
37
|
+
western: '1926-12-25'
|
38
|
+
disuse:
|
39
|
+
new_year_date: '1926-1-1'
|
40
|
+
note: ''
|
41
|
+
- name: 令和
|
42
|
+
start_year:
|
43
|
+
japan: 1
|
44
|
+
western: 2019
|
45
|
+
start_date:
|
46
|
+
japan: 令和01年05月01日
|
47
|
+
western: '2019-5-1'
|
48
|
+
disuse:
|
49
|
+
new_year_date: '2019-1-1'
|
50
|
+
note: ''
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './resource/parser'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Japan
|
9
|
+
# :nodoc:
|
10
|
+
module Gengou
|
11
|
+
#
|
12
|
+
# Resource yaml解析結果
|
13
|
+
#
|
14
|
+
module Resource
|
15
|
+
# @return [Array<Set>] 元号セット情報リスト
|
16
|
+
LIST = [
|
17
|
+
Parser.run(filepath: File.expand_path(
|
18
|
+
'./resource/yaml/set-001-until-south.yaml',
|
19
|
+
__dir__
|
20
|
+
)),
|
21
|
+
Parser.run(filepath: File.expand_path(
|
22
|
+
'./resource/yaml/set-002-from-north.yaml',
|
23
|
+
__dir__
|
24
|
+
)),
|
25
|
+
Parser.run(filepath: File.expand_path(
|
26
|
+
'./resource/yaml/set-003-modern.yaml',
|
27
|
+
__dir__
|
28
|
+
))
|
29
|
+
].freeze
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../western'
|
4
|
-
|
5
|
-
require_relative './gengou/
|
3
|
+
require_relative '../western/calendar'
|
4
|
+
|
5
|
+
require_relative './gengou/alignment'
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
@@ -11,95 +11,41 @@ module Zakuro
|
|
11
11
|
#
|
12
12
|
module Japan
|
13
13
|
#
|
14
|
-
#
|
14
|
+
# Gengou 元号
|
15
15
|
#
|
16
|
-
module
|
17
|
-
# @return [
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
__dir__
|
22
|
-
)),
|
23
|
-
Parser.run(filepath: File.expand_path(
|
24
|
-
'./yaml/set-002-from-north.yaml',
|
25
|
-
__dir__
|
26
|
-
)),
|
27
|
-
Parser.run(filepath: File.expand_path(
|
28
|
-
'./yaml/set-003-modern.yaml',
|
29
|
-
__dir__
|
30
|
-
))
|
31
|
-
].freeze
|
32
|
-
|
33
|
-
# :reek:TooManyStatements { max_statements: 9 }
|
34
|
-
|
35
|
-
#
|
36
|
-
# 元号(1行目,2行目)を引き当てる
|
37
|
-
#
|
38
|
-
# * LINE配列の元号情報を配列順で「x行目」(1始まり)とする
|
39
|
-
# * 1行目にデータがあれば、第一要素に1行目のデータが設定される
|
40
|
-
# * 1行目と2行目にデータがあれば、第二要素に2行目のデータが設定される
|
41
|
-
# * 1行目にデータがなく、2行目以降に1つだけデータがあれば、第一要素にそのデータを設定してそれ以外の要素は未設定
|
42
|
-
# * 1行目にデータがなく、2行目以降に2つ以上のデータがあれば、第一要素に末尾行に一番近いデータを設定してそれ以外の要素は未設定
|
43
|
-
#
|
44
|
-
# @param [Western::Calendar] date 日
|
45
|
-
#
|
46
|
-
# @return [Array<Gengou>] 元号情報(1行目, 2行目)
|
47
|
-
#
|
48
|
-
def self.lines(date:)
|
49
|
-
lines = native_lines(date: date)
|
50
|
-
return lines unless lines[0].invalid?
|
51
|
-
|
52
|
-
first = Japan::Gengou.new
|
53
|
-
lines[1..].each.with_index(1) do |item, index|
|
54
|
-
next if item.invalid?
|
55
|
-
|
56
|
-
first = item
|
57
|
-
lines[index] = Japan::Gengou.new
|
58
|
-
end
|
59
|
-
lines[0] = first
|
60
|
-
lines
|
61
|
-
end
|
62
|
-
|
63
|
-
#
|
64
|
-
# 元号を引き当てる
|
65
|
-
#
|
66
|
-
# * LISTから単純に元号を引き当てる
|
67
|
-
# * 1行目,2行目といった概念は無視する
|
68
|
-
#
|
69
|
-
# @param [Western::Calendar] date 日
|
70
|
-
#
|
71
|
-
# @return [Array<Gengou>] 元号情報
|
72
|
-
#
|
73
|
-
def self.native_lines(date:)
|
74
|
-
result = Array.new(LIST.size)
|
75
|
-
LIST.each_with_index do |set, index|
|
76
|
-
result[index] = set.include_item(date: date)
|
77
|
-
end
|
78
|
-
result
|
79
|
-
end
|
16
|
+
module Gengou
|
17
|
+
# @return [Integer] 1行目
|
18
|
+
FIRST_LINE = Alignment::Aligner::FIRST_LINE
|
19
|
+
# @return [Integer] 2行目
|
20
|
+
SECOND_LINE = Alignment::Aligner::SECOND_LINE
|
80
21
|
|
81
22
|
#
|
82
|
-
#
|
23
|
+
# 該当行の元号を取得する
|
83
24
|
#
|
84
|
-
# @param [
|
25
|
+
# @param [Integer] line 行番号
|
26
|
+
# @param [Western::Calendar] start_date 開始日
|
27
|
+
# @param [Western::Calendar] last_date 終了日
|
85
28
|
#
|
86
|
-
# @return [
|
29
|
+
# @return [Array<LinearGengou>] 該当行の元号
|
87
30
|
#
|
88
|
-
def self.
|
89
|
-
|
90
|
-
|
31
|
+
def self.line(line: FIRST_LINE,
|
32
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
33
|
+
Alignment.get(
|
34
|
+
line: line, start_date: start_date, last_date: last_date
|
35
|
+
)
|
91
36
|
end
|
92
37
|
|
93
38
|
#
|
94
|
-
#
|
39
|
+
# 該当行の元号を取得する(元号名)
|
95
40
|
#
|
96
|
-
# @param [
|
41
|
+
# @param [Integer] line 行番号
|
42
|
+
# @param [Western::Calendar] start_date 開始日
|
43
|
+
# @param [Western::Calendar] last_date 終了日
|
97
44
|
#
|
98
|
-
# @return [
|
45
|
+
# @return [Array<LinearGengou>] 該当行の元号
|
99
46
|
#
|
100
|
-
def self.
|
101
|
-
|
102
|
-
lines[1].clone
|
47
|
+
def self.line_by_name(line: FIRST_LINE, name:)
|
48
|
+
Alignment.get_by_name(line: line, name: name)
|
103
49
|
end
|
104
50
|
end
|
105
51
|
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../western/calendar'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
#
|
8
|
+
# Japan 和暦
|
9
|
+
#
|
10
|
+
module Japan
|
11
|
+
#
|
12
|
+
# Version 暦
|
13
|
+
#
|
14
|
+
module Version
|
15
|
+
#
|
16
|
+
# Range 暦(範囲)
|
17
|
+
#
|
18
|
+
class Range
|
19
|
+
# @return [String] 暦名
|
20
|
+
attr_reader :name
|
21
|
+
# @return [Western::Calendar] 暦の開始日
|
22
|
+
attr_reader :start_date
|
23
|
+
# @return [Integer] 開始西暦年
|
24
|
+
attr_reader :start_year
|
25
|
+
# @return [Integer] 終了西暦年
|
26
|
+
attr_reader :last_year
|
27
|
+
# @return [True] リリース済
|
28
|
+
# @return [False] 未リリース
|
29
|
+
attr_reader :released
|
30
|
+
|
31
|
+
#
|
32
|
+
# 初期化
|
33
|
+
#
|
34
|
+
# @param [String] name 暦名
|
35
|
+
# @param [Western::Calendar] start_date 暦の開始日
|
36
|
+
# @param [Integer] start_year 開始西暦年
|
37
|
+
# @param [Integer] last_year 終了西暦年
|
38
|
+
# @param [True, False] released リリース済 / 未リリース
|
39
|
+
#
|
40
|
+
def initialize(name:, start_date:, start_year:, last_year:, released:)
|
41
|
+
@name = name
|
42
|
+
@start_date = start_date
|
43
|
+
@start_year = start_year
|
44
|
+
@last_year = last_year
|
45
|
+
@released = released
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# TODO: yamlにする
|
50
|
+
# TODO: last_year は不要
|
51
|
+
|
52
|
+
# @return [Array<Range>] 全和暦
|
53
|
+
LIST = [
|
54
|
+
# 允恭天皇34年01月01日
|
55
|
+
Range.new(
|
56
|
+
name: 'Genka',
|
57
|
+
start_date: Western::Calendar.new(year: 445, month: 1, day: 24),
|
58
|
+
start_year: 445,
|
59
|
+
last_year: 697,
|
60
|
+
released: true
|
61
|
+
),
|
62
|
+
# 文武天皇02年01月01日
|
63
|
+
Range.new(
|
64
|
+
name: 'Gihou',
|
65
|
+
start_date: Western::Calendar.new(year: 698, month: 2, day: 16),
|
66
|
+
start_year: 698,
|
67
|
+
last_year: 763,
|
68
|
+
released: true
|
69
|
+
),
|
70
|
+
# 天平宝字08年01月01日
|
71
|
+
Range.new(
|
72
|
+
name: 'Daien',
|
73
|
+
start_date: Western::Calendar.new(year: 764, month: 2, day: 7),
|
74
|
+
start_year: 764,
|
75
|
+
last_year: 861,
|
76
|
+
released: true
|
77
|
+
),
|
78
|
+
# 貞観02年01月01日
|
79
|
+
Range.new(
|
80
|
+
name: 'Senmyou',
|
81
|
+
start_date: Western::Calendar.new(year: 862, month: 2, day: 3),
|
82
|
+
start_year: 862,
|
83
|
+
last_year: 1684,
|
84
|
+
released: true
|
85
|
+
),
|
86
|
+
# 貞享02年01月01日
|
87
|
+
Range.new(
|
88
|
+
name: 'Joukyou',
|
89
|
+
start_date: Western::Calendar.new(year: 1685, month: 2, day: 4),
|
90
|
+
start_year: 1685,
|
91
|
+
last_year: 1754,
|
92
|
+
released: false
|
93
|
+
),
|
94
|
+
# 宝暦05年01月01日
|
95
|
+
Range.new(
|
96
|
+
name: 'Houryaku',
|
97
|
+
start_date: Western::Calendar.new(year: 1755, month: 2, day: 11),
|
98
|
+
start_year: 1755,
|
99
|
+
last_year: 1797,
|
100
|
+
released: false
|
101
|
+
),
|
102
|
+
# 寛政10年01月01日
|
103
|
+
Range.new(
|
104
|
+
name: 'Kansei',
|
105
|
+
start_date: Western::Calendar.new(year: 1798, month: 2, day: 16),
|
106
|
+
start_year: 1798,
|
107
|
+
last_year: 1843,
|
108
|
+
released: false
|
109
|
+
),
|
110
|
+
# 天保13年01月01日
|
111
|
+
Range.new(
|
112
|
+
name: 'Tenpou',
|
113
|
+
start_date: Western::Calendar.new(year: 1844, month: 2, day: 18),
|
114
|
+
start_year: 1844,
|
115
|
+
last_year: 1867,
|
116
|
+
released: false
|
117
|
+
),
|
118
|
+
# 明治01年09月08日
|
119
|
+
Range.new(
|
120
|
+
name: 'Gregorio',
|
121
|
+
start_date: Western::Calendar.new(year: 1868, month: 10, day: 23),
|
122
|
+
start_year: 1868,
|
123
|
+
last_year: 9999,
|
124
|
+
released: false
|
125
|
+
)
|
126
|
+
].freeze
|
127
|
+
|
128
|
+
#
|
129
|
+
# 年を基準に暦を引き当てる
|
130
|
+
#
|
131
|
+
# @param [Integer] start_year 開始西暦年
|
132
|
+
# @param [Integer] last_year 終了西暦年
|
133
|
+
#
|
134
|
+
# @return [Array<Range>] 和暦
|
135
|
+
#
|
136
|
+
def self.ranges_with_year(start_year:, last_year:)
|
137
|
+
result = []
|
138
|
+
|
139
|
+
LIST.each do |range|
|
140
|
+
next if start_year > range.last_year
|
141
|
+
|
142
|
+
next if last_year < range.start_year
|
143
|
+
|
144
|
+
result.push(range)
|
145
|
+
end
|
146
|
+
|
147
|
+
result
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -381,18 +381,18 @@ module Zakuro
|
|
381
381
|
#
|
382
382
|
# 年月日情報(西暦)を生成する
|
383
383
|
#
|
384
|
-
# @param [String]
|
384
|
+
# @param [String] text 日付文字列
|
385
385
|
# @param [Symbol] type 日付種別
|
386
386
|
#
|
387
387
|
# @return [Calendar] 年月日情報(西暦)
|
388
388
|
#
|
389
|
-
def self.parse(
|
390
|
-
unless Calendar.valid_date_string(
|
391
|
-
raise ArgumentError, "invalid date string: #{
|
389
|
+
def self.parse(text: '', type: Type::DEFAULT)
|
390
|
+
unless Calendar.valid_date_string(text: text, type: type)
|
391
|
+
raise ArgumentError, "invalid date string: #{text}"
|
392
392
|
end
|
393
393
|
|
394
394
|
start = DATE_START.fetch(type, DATE_START[Type::DEFAULT])
|
395
|
-
date = Date.parse(
|
395
|
+
date = Date.parse(text, start)
|
396
396
|
|
397
397
|
Calendar.new(
|
398
398
|
year: date.year, month: date.month, day: date.day, type: type
|
@@ -402,18 +402,18 @@ module Zakuro
|
|
402
402
|
#
|
403
403
|
# 日付文字列を検証する
|
404
404
|
#
|
405
|
-
# @param [String]
|
405
|
+
# @param [String] text 日付文字列
|
406
406
|
# @param [Symbol] type 日付種別
|
407
407
|
#
|
408
408
|
# @return [True] 正しい
|
409
409
|
# @return [True] 正しくない
|
410
410
|
#
|
411
|
-
def self.valid_date_string(
|
411
|
+
def self.valid_date_string(text: '', type: Type::DEFAULT)
|
412
412
|
start = DATE_START.fetch(type, DATE_START[Type::DEFAULT])
|
413
413
|
begin
|
414
|
-
Date.parse(
|
414
|
+
Date.parse(text, start)
|
415
415
|
rescue ArgumentError => _e
|
416
|
-
false
|
416
|
+
return false
|
417
417
|
end
|
418
418
|
true
|
419
419
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './template'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Exception
|
9
|
+
# :nodoc:
|
10
|
+
module Case
|
11
|
+
#
|
12
|
+
# Pattern 原因パターン
|
13
|
+
#
|
14
|
+
module Pattern
|
15
|
+
INTERNAL_ERROR = Template.new(
|
16
|
+
code: 'ERROR_0001',
|
17
|
+
message: '致命的なエラーです。',
|
18
|
+
length: 0
|
19
|
+
)
|
20
|
+
|
21
|
+
INVALID_DATE = Template.new(
|
22
|
+
code: 'ERROR_0002',
|
23
|
+
message: '一日検索の日付指定が誤っています。',
|
24
|
+
length: 0
|
25
|
+
)
|
26
|
+
|
27
|
+
INVALID_RANGE = Template.new(
|
28
|
+
code: 'ERROR_0003',
|
29
|
+
message: '範囲検索の日付指定が誤っています。',
|
30
|
+
length: 0
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './template'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Exception
|
9
|
+
# :nodoc:
|
10
|
+
module Case
|
11
|
+
#
|
12
|
+
# Preset プリセット
|
13
|
+
#
|
14
|
+
class Preset
|
15
|
+
# @return [Template] テンプレート
|
16
|
+
attr_reader :template
|
17
|
+
# @return [Array<Object>] メッセージ引数
|
18
|
+
attr_reader :args
|
19
|
+
|
20
|
+
#
|
21
|
+
# 初期化
|
22
|
+
#
|
23
|
+
# @param [String] args メッセージ引数
|
24
|
+
# @param [String] template テンプレート
|
25
|
+
#
|
26
|
+
def initialize(*args, template:)
|
27
|
+
@template = template
|
28
|
+
@args = args
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# エラーコードを取得する
|
33
|
+
#
|
34
|
+
# @return [String] エラーコード
|
35
|
+
#
|
36
|
+
def code
|
37
|
+
@template.code
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# メッセージを作成する
|
42
|
+
#
|
43
|
+
# @return [String] メッセージ
|
44
|
+
#
|
45
|
+
def message
|
46
|
+
@template.format(*args)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Zakuro
|
5
|
+
# :nodoc:
|
6
|
+
module Exception
|
7
|
+
# :nodoc:
|
8
|
+
module Case
|
9
|
+
#
|
10
|
+
# Template テンプレート
|
11
|
+
#
|
12
|
+
class Template
|
13
|
+
# @return [String] エラーコード
|
14
|
+
attr_reader :code
|
15
|
+
# @return [String] メッセージ
|
16
|
+
attr_reader :message
|
17
|
+
# @return [Integer] テンプレート引数長
|
18
|
+
attr_reader :length
|
19
|
+
|
20
|
+
#
|
21
|
+
# 初期化
|
22
|
+
#
|
23
|
+
# @param [String] code エラーコード
|
24
|
+
# @param [String] message メッセージ
|
25
|
+
# @param [Integer] length テンプレート引数長
|
26
|
+
#
|
27
|
+
def initialize(code:, message:, length: 0)
|
28
|
+
@code = code
|
29
|
+
@message = message
|
30
|
+
@length = length
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# メッセージを作成する
|
35
|
+
#
|
36
|
+
# @param [Array<Object>] args テンプレート引数長
|
37
|
+
#
|
38
|
+
# @return [String] メッセージ
|
39
|
+
#
|
40
|
+
def format(*args)
|
41
|
+
return '' unless args.size == length
|
42
|
+
|
43
|
+
super(message, *args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Zakuro
|
5
|
+
# :nodoc:
|
6
|
+
module Exception
|
7
|
+
#
|
8
|
+
# Cause 原因
|
9
|
+
#
|
10
|
+
class Cause
|
11
|
+
# @return [String] エラーコード
|
12
|
+
attr_reader :code
|
13
|
+
# @return [String] メッセージ
|
14
|
+
attr_reader :message
|
15
|
+
|
16
|
+
#
|
17
|
+
# 初期化
|
18
|
+
#
|
19
|
+
# @param [String] code エラーコード
|
20
|
+
# @param [String] message メッセージ
|
21
|
+
#
|
22
|
+
def initialize(code:, message:)
|
23
|
+
@code = code
|
24
|
+
@message = message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../output/logger'
|
4
|
+
|
5
|
+
require_relative './cause'
|
6
|
+
|
7
|
+
require_relative './case/pattern'
|
8
|
+
|
9
|
+
require_relative './zakuro_error'
|
10
|
+
|
11
|
+
# :nodoc:
|
12
|
+
module Zakuro
|
13
|
+
# :nodoc:
|
14
|
+
module Exception
|
15
|
+
# @return [Output::Logger] ロガー
|
16
|
+
LOGGER = Output::Logger.new(location: 'exception')
|
17
|
+
|
18
|
+
# @return [String] 共通メッセージ
|
19
|
+
MESSAGE = 'an error has occurred'
|
20
|
+
|
21
|
+
#
|
22
|
+
# 例外を取得する
|
23
|
+
#
|
24
|
+
# @param [Array<Template>] presets 原因プリセット
|
25
|
+
#
|
26
|
+
# @return [ZakuroError] ライブラリエラー
|
27
|
+
#
|
28
|
+
def self.get(presets: [])
|
29
|
+
causes = []
|
30
|
+
presets.each do |preset|
|
31
|
+
causes.push(Cause.new(code: preset.code, message: preset.message))
|
32
|
+
end
|
33
|
+
|
34
|
+
ZakuroError.new(msg: MESSAGE, causes: causes)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './cause'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Exception
|
9
|
+
#
|
10
|
+
# ZakuroError ライブラリ内エラー
|
11
|
+
#
|
12
|
+
class ZakuroError < StandardError
|
13
|
+
# @return [Array<ErrorMessage>] エラーメッセージ
|
14
|
+
attr_reader :causes
|
15
|
+
|
16
|
+
#
|
17
|
+
# 初期化
|
18
|
+
#
|
19
|
+
# @param [String] msg メッセージ
|
20
|
+
# @param [Array<Cause>] causes 原因
|
21
|
+
#
|
22
|
+
def initialize(msg: '', causes: [])
|
23
|
+
super(msg)
|
24
|
+
@causes = causes
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|