zakuro 0.6.1 → 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 +6 -4
- data/VERSION +1 -1
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/gengou.rb +46 -0
- data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +6 -8
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +37 -51
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +17 -17
- 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 +2 -3
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- data/lib/zakuro/calculation/monthly/month.rb +39 -0
- data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
- data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +5 -4
- data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +9 -11
- 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 +0 -2
- data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +1 -1
- 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 +1 -2
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +89 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +125 -122
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +141 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +171 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +38 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +183 -182
- data/lib/zakuro/era/japan/gengou/resource/type.rb +233 -232
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +255 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +5 -20
- data/lib/zakuro/era/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 +8 -44
- data/lib/zakuro/operation/month/parser.rb +9 -9
- data/lib/zakuro/operation/month/type.rb +31 -31
- data/lib/zakuro/operation/month/validator.rb +49 -49
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- 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 +4 -2
- metadata +46 -14
- data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
- data/lib/zakuro/calculation/summary/range.rb +0 -120
- data/lib/zakuro/calculation/summary/single.rb +0 -110
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/result/operation.rb +0 -114
@@ -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
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../era/japan/calendar'
|
4
|
+
require_relative '../../era/western/calendar'
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
module Zakuro
|
10
|
+
# :nodoc:
|
11
|
+
module Gateway
|
12
|
+
# :nodoc:
|
13
|
+
class Locale
|
14
|
+
#
|
15
|
+
# Date 日付
|
16
|
+
#
|
17
|
+
class Date
|
18
|
+
INDALID = Object::Date.new
|
19
|
+
|
20
|
+
# @return [Western::Calendar] 西暦日
|
21
|
+
attr_reader :western_date
|
22
|
+
# @return [Japan::Calendar] 和暦日
|
23
|
+
attr_reader :japan_date
|
24
|
+
|
25
|
+
#
|
26
|
+
# 初期化
|
27
|
+
#
|
28
|
+
# @param [Date, String] date 日付
|
29
|
+
#
|
30
|
+
def initialize(date: INDALID)
|
31
|
+
@western_date = Western::Calendar.new
|
32
|
+
@japan_date = Japan::Calendar.new
|
33
|
+
|
34
|
+
parse(date: date)
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# 和暦日が有効か
|
39
|
+
#
|
40
|
+
# @return [True] 有効
|
41
|
+
# @return [False] 無効
|
42
|
+
#
|
43
|
+
def valid_japan?
|
44
|
+
!invalid_japan?
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# 和暦日が不正か
|
49
|
+
#
|
50
|
+
# @return [True] 不正
|
51
|
+
# @return [False] 不正なし
|
52
|
+
#
|
53
|
+
def invalid_japan?
|
54
|
+
@japan_date.invalid?
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# 西暦日が有効か
|
59
|
+
#
|
60
|
+
# @return [True] 有効
|
61
|
+
# @return [False] 無効
|
62
|
+
#
|
63
|
+
def valid_western?
|
64
|
+
!invalid_western?
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# 西暦日が不正か
|
69
|
+
#
|
70
|
+
# @return [True] 不正
|
71
|
+
# @return [False] 不正なし
|
72
|
+
#
|
73
|
+
def invalid_western?
|
74
|
+
@western_date.invalid?
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# 不正か
|
79
|
+
#
|
80
|
+
# @return [True] 不正
|
81
|
+
# @return [False] 不正なし
|
82
|
+
#
|
83
|
+
def invalid?
|
84
|
+
invalid_japan? && invalid_western?
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
#
|
90
|
+
# 解析する
|
91
|
+
#
|
92
|
+
# @param [Date, String] date 日付
|
93
|
+
#
|
94
|
+
def parse(date:)
|
95
|
+
return unless date
|
96
|
+
|
97
|
+
return if date == INDALID
|
98
|
+
|
99
|
+
if date.is_a?(Object::Date)
|
100
|
+
@western_date = Western::Calendar.create(date: date)
|
101
|
+
return
|
102
|
+
end
|
103
|
+
|
104
|
+
return unless date.is_a?(String)
|
105
|
+
|
106
|
+
parse_text(text: date)
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# 文字解析する
|
111
|
+
#
|
112
|
+
# @param [String] text 日付文字列
|
113
|
+
#
|
114
|
+
def parse_text(text:)
|
115
|
+
if Western::Calendar.valid_date_string(text: text)
|
116
|
+
@western_date = Western::Calendar.parse(text: text)
|
117
|
+
return
|
118
|
+
end
|
119
|
+
|
120
|
+
return unless Japan::Calendar.valid_date_string(text: text)
|
121
|
+
|
122
|
+
@japan_date = Japan::Calendar.parse(text: text)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './date'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Gateway
|
9
|
+
# :nodoc:
|
10
|
+
class Locale
|
11
|
+
#
|
12
|
+
# Range 範囲
|
13
|
+
#
|
14
|
+
class Range
|
15
|
+
# @return [LocaleDate] 開始日
|
16
|
+
attr_reader :start_date
|
17
|
+
# @return [LocaleDate] 終了日
|
18
|
+
attr_reader :last_date
|
19
|
+
|
20
|
+
#
|
21
|
+
# 初期化
|
22
|
+
#
|
23
|
+
# @param [Hash<Symbol, Object>] range 範囲
|
24
|
+
#
|
25
|
+
def initialize(range:)
|
26
|
+
@start_date = Date.new
|
27
|
+
@last_date = Date.new
|
28
|
+
|
29
|
+
return unless range
|
30
|
+
|
31
|
+
@start_date = Date.new(date: range[:start])
|
32
|
+
@last_date = Date.new(date: range[:last])
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# 西暦日は有効か
|
37
|
+
#
|
38
|
+
# @return [True] 有効
|
39
|
+
# @return [False] 無効
|
40
|
+
#
|
41
|
+
def valid_western?
|
42
|
+
@start_date.valid_western? && @last_date.valid_western?
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# 和暦日は有効か
|
47
|
+
#
|
48
|
+
# @return [True] 有効
|
49
|
+
# @return [False] 無効
|
50
|
+
#
|
51
|
+
def valid_japan?
|
52
|
+
@start_date.valid_japan? && @last_date.valid_japan?
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# 不正か
|
57
|
+
#
|
58
|
+
# @return [True] 不正
|
59
|
+
# @return [False] 不正なし
|
60
|
+
#
|
61
|
+
def invalid?
|
62
|
+
@start_date.invalid? && @last_date.invalid?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../calculation/summary/japan/range'
|
4
|
+
require_relative '../calculation/summary/western/range'
|
5
|
+
require_relative '../exception/case/preset'
|
6
|
+
require_relative '../exception/exception'
|
7
|
+
|
8
|
+
require_relative './locale/range'
|
9
|
+
|
10
|
+
# :nodoc:
|
11
|
+
module Zakuro
|
12
|
+
# :nodoc:
|
13
|
+
module Gateway
|
14
|
+
#
|
15
|
+
# Range 範囲
|
16
|
+
#
|
17
|
+
class Range
|
18
|
+
# @return [Context] 暦コンテキスト
|
19
|
+
attr_reader :context
|
20
|
+
# @return [Locale::Range] 範囲
|
21
|
+
attr_reader :range
|
22
|
+
|
23
|
+
#
|
24
|
+
# 初期化
|
25
|
+
#
|
26
|
+
# @param [Context] context 暦コンテキスト
|
27
|
+
# @param [Hash<Symbol, Object>] range 範囲
|
28
|
+
#
|
29
|
+
def initialize(context:, range:)
|
30
|
+
@context = context
|
31
|
+
@range = Locale::Range.new(range: range)
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# 不正か
|
36
|
+
#
|
37
|
+
# @return [True] 不正
|
38
|
+
# @return [False] 不正なし
|
39
|
+
#
|
40
|
+
def invalid?
|
41
|
+
@range.invalid?
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# 検索結果を取得する
|
46
|
+
#
|
47
|
+
# @return [Result::Range] 範囲検索結果(和暦日)
|
48
|
+
#
|
49
|
+
def get
|
50
|
+
start_date = range.start_date
|
51
|
+
last_date = range.last_date
|
52
|
+
|
53
|
+
return western(start_date: start_date, last_date: last_date) if range.valid_western?
|
54
|
+
|
55
|
+
return japan(start_date: start_date, last_date: last_date) if range.valid_japan?
|
56
|
+
|
57
|
+
raise Exception.get(
|
58
|
+
presets: [
|
59
|
+
Exception::Case::Preset.new(
|
60
|
+
template: Exception::Case::Pattern::INVALID_RANGE
|
61
|
+
)
|
62
|
+
]
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
#
|
69
|
+
# 西暦日による結果を取得する
|
70
|
+
#
|
71
|
+
# @param [Locale::Date] start_date 西暦開始日
|
72
|
+
# @param [Locale::Date] last_date 西暦終了日
|
73
|
+
#
|
74
|
+
# @return [Result::Range] 範囲検索結果(和暦日)
|
75
|
+
#
|
76
|
+
def western(start_date: Locale::Date.new, last_date: Locale::Date.new)
|
77
|
+
Calculation::Summary::Western::Range.get(
|
78
|
+
context: context, start_date: start_date.western_date,
|
79
|
+
last_date: last_date.western_date
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# 和暦日による結果を取得する
|
85
|
+
#
|
86
|
+
# @param [Locale::Date] start_date 和暦開始日
|
87
|
+
# @param [Locale::Date] last_date 和暦終了日
|
88
|
+
#
|
89
|
+
# @return [Result::Range] 範囲検索結果(和暦日)
|
90
|
+
#
|
91
|
+
def japan(start_date: Locale::Date.new, last_date: Locale::Date.new)
|
92
|
+
Calculation::Summary::Japan::Range.get(
|
93
|
+
context: context, start_date: start_date.japan_date,
|
94
|
+
last_date: last_date.japan_date
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../calculation/summary/japan/single'
|
4
|
+
require_relative '../calculation/summary/western/single'
|
5
|
+
require_relative '../exception/case/preset'
|
6
|
+
require_relative '../exception/exception'
|
7
|
+
|
8
|
+
require_relative './locale/date'
|
9
|
+
|
10
|
+
# :nodoc:
|
11
|
+
module Zakuro
|
12
|
+
# :nodoc:
|
13
|
+
module Gateway
|
14
|
+
#
|
15
|
+
# Single 1日
|
16
|
+
#
|
17
|
+
class Single
|
18
|
+
# @return [Locale::Date] 日付
|
19
|
+
attr_reader :date
|
20
|
+
|
21
|
+
#
|
22
|
+
# 初期化
|
23
|
+
#
|
24
|
+
# @param [Context] context 暦コンテキスト
|
25
|
+
# @param [Date, String] date 日付
|
26
|
+
#
|
27
|
+
def initialize(context:, date:)
|
28
|
+
@context = context
|
29
|
+
@date = Locale::Date.new(date: date)
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# 不正か
|
34
|
+
#
|
35
|
+
# @return [True] 不正
|
36
|
+
# @return [False] 不正なし
|
37
|
+
#
|
38
|
+
def invalid?
|
39
|
+
@date.invalid?
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# 検索結果を取得する
|
44
|
+
#
|
45
|
+
# @return [Result::Single] 一日検索結果(和暦日)
|
46
|
+
#
|
47
|
+
def get
|
48
|
+
if date.valid_western?
|
49
|
+
return Calculation::Summary::Western::Single.get(
|
50
|
+
context: @context, date: date.western_date
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
if date.valid_japan?
|
55
|
+
return Calculation::Summary::Japan::Single.get(
|
56
|
+
context: @context, date: date.japan_date
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
raise Exception.get(
|
61
|
+
presets: [
|
62
|
+
Exception::Case::Preset.new(
|
63
|
+
template: Exception::Case::Pattern::INVALID_DATE
|
64
|
+
)
|
65
|
+
]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|