zakuro 0.0.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +102 -42
- data/doc/operation.md +25 -0
- data/doc/operation/csv/month.csv +202 -0
- data/doc/operation/operation.xlsx +0 -0
- data/doc/operation/transfer.rb +77 -0
- data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
- data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
- data/lib/zakuro/calculation/base/year.rb +107 -0
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +459 -0
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
- data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
- data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
- data/lib/zakuro/calculation/monthly/month.rb +187 -0
- data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
- data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
- data/lib/zakuro/calculation/range/full_range.rb +210 -0
- data/lib/zakuro/calculation/range/operated_range.rb +144 -0
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
- data/lib/zakuro/calculation/summary/single.rb +129 -0
- data/lib/zakuro/condition.rb +16 -13
- data/lib/zakuro/era/japan/gengou.rb +106 -0
- data/lib/zakuro/era/japan/gengou/parser.rb +167 -0
- data/lib/zakuro/era/japan/gengou/type.rb +178 -0
- data/lib/zakuro/era/japan/gengou/validator.rb +236 -0
- data/lib/zakuro/era/japan/reki.rb +91 -0
- data/lib/zakuro/era/{gengou → japan/yaml}/set-001-until-south.yaml +0 -0
- data/lib/zakuro/era/{gengou → japan/yaml}/set-002-from-north.yaml +0 -0
- data/lib/zakuro/era/{gengou → japan/yaml}/set-003-modern.yaml +0 -0
- data/lib/zakuro/era/western.rb +1 -1
- data/lib/zakuro/merchant.rb +2 -2
- data/lib/zakuro/operation/month/parser.rb +373 -0
- data/lib/zakuro/operation/month/type.rb +453 -0
- data/lib/zakuro/operation/month/validator.rb +802 -0
- data/lib/zakuro/operation/operation.rb +66 -0
- data/lib/zakuro/operation/yaml/month.yaml +6452 -0
- data/lib/zakuro/output/error.rb +7 -4
- data/lib/zakuro/output/logger.rb +50 -47
- data/lib/zakuro/output/response.rb +146 -143
- data/lib/zakuro/result/core.rb +52 -0
- data/lib/zakuro/result/data.rb +187 -0
- data/lib/zakuro/result/operation.rb +114 -0
- data/lib/zakuro/result/result.rb +37 -0
- data/lib/zakuro/{output → tools}/stringifier.rb +16 -9
- data/lib/zakuro/tools/typeof.rb +33 -0
- data/lib/zakuro/version.rb +1 -1
- data/lib/zakuro/version/abstract_version.rb +1 -1
- data/lib/zakuro/version/context.rb +23 -0
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +63 -0
- data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +186 -182
- data/lib/zakuro/version/senmyou/range/annual_range.rb +167 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
- data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +6 -6
- data/lib/zakuro/version/senmyou/stella/solar_average.rb +103 -152
- data/lib/zakuro/version/senmyou/stella/solar_location.rb +213 -0
- data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +3 -184
- data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +4 -4
- data/lib/zakuro/version/version_class_resolver.rb +62 -0
- data/lib/zakuro/version_factory.rb +3 -3
- metadata +53 -24
- data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
- data/lib/zakuro/cycle/zodiac.rb +0 -103
- data/lib/zakuro/era/japan.rb +0 -664
- data/lib/zakuro/output/result.rb +0 -225
- data/lib/zakuro/version/senmyou/base/era.rb +0 -83
- data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
- data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -205
- data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
- data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -66
- data/lib/zakuro/version/senmyou/base/year.rb +0 -104
- data/lib/zakuro/version/senmyou/monthly/month.rb +0 -122
- data/lib/zakuro/version/senmyou/summary/annual_range.rb +0 -187
- data/lib/zakuro/version/senmyou/summary/full_range.rb +0 -224
- data/lib/zakuro/version/senmyou/summary/specifier.rb +0 -100
data/lib/zakuro/condition.rb
CHANGED
@@ -25,8 +25,6 @@ module Zakuro
|
|
25
25
|
@date = date
|
26
26
|
end
|
27
27
|
|
28
|
-
# :reek:NilCheck
|
29
|
-
|
30
28
|
#
|
31
29
|
# 検証する
|
32
30
|
#
|
@@ -36,7 +34,9 @@ module Zakuro
|
|
36
34
|
#
|
37
35
|
def self.validate(date:)
|
38
36
|
failed = []
|
39
|
-
return failed
|
37
|
+
return failed unless date
|
38
|
+
|
39
|
+
return failed if date.is_a?(Date) || date.is_a?(String)
|
40
40
|
|
41
41
|
failed.push("invalid date: #{date}")
|
42
42
|
failed
|
@@ -64,7 +64,7 @@ module Zakuro
|
|
64
64
|
@last = hash[:last]
|
65
65
|
end
|
66
66
|
|
67
|
-
# :reek:TooManyStatements { max_statements: 7 }
|
67
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
68
68
|
|
69
69
|
#
|
70
70
|
# 検証する
|
@@ -75,7 +75,7 @@ module Zakuro
|
|
75
75
|
#
|
76
76
|
def self.validate(hash:)
|
77
77
|
failed = []
|
78
|
-
return failed
|
78
|
+
return failed unless hash
|
79
79
|
|
80
80
|
unless hash.is_a?(Hash)
|
81
81
|
failed.push("invalid range type. #{hash}. should be hash")
|
@@ -106,8 +106,6 @@ module Zakuro
|
|
106
106
|
@columns = columns
|
107
107
|
end
|
108
108
|
|
109
|
-
# :reek:NilCheck
|
110
|
-
|
111
109
|
#
|
112
110
|
# 検証する
|
113
111
|
#
|
@@ -118,7 +116,10 @@ module Zakuro
|
|
118
116
|
def self.validate(columns:)
|
119
117
|
# TODO: 列内容のバリデーション
|
120
118
|
failed = []
|
121
|
-
|
119
|
+
|
120
|
+
return failed unless columns
|
121
|
+
|
122
|
+
return failed if columns.is_a?(Array)
|
122
123
|
|
123
124
|
failed.push("invalid columns type. #{columns}. should be array")
|
124
125
|
|
@@ -148,7 +149,6 @@ module Zakuro
|
|
148
149
|
end
|
149
150
|
|
150
151
|
# TODO: オプションキーのバリデーション
|
151
|
-
# :reek:NilCheck
|
152
152
|
|
153
153
|
#
|
154
154
|
# 検証する
|
@@ -159,7 +159,9 @@ module Zakuro
|
|
159
159
|
#
|
160
160
|
def self.validate(options:)
|
161
161
|
failed = []
|
162
|
-
return failed
|
162
|
+
return failed unless options
|
163
|
+
|
164
|
+
return failed if options.is_a?(Hash)
|
163
165
|
|
164
166
|
failed.push("invalid options type. #{options}. should be hash")
|
165
167
|
|
@@ -222,8 +224,6 @@ module Zakuro
|
|
222
224
|
failed
|
223
225
|
end
|
224
226
|
|
225
|
-
# :reek:NilCheck
|
226
|
-
|
227
227
|
#
|
228
228
|
# 上書きする
|
229
229
|
#
|
@@ -233,7 +233,10 @@ module Zakuro
|
|
233
233
|
instance_variables.each do |var|
|
234
234
|
key = var.to_s.delete('@')
|
235
235
|
val = hash[key.intern]
|
236
|
-
|
236
|
+
|
237
|
+
next unless val
|
238
|
+
|
239
|
+
instance_variable_set(var, val)
|
237
240
|
end
|
238
241
|
end
|
239
242
|
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../western'
|
4
|
+
require_relative './gengou/parser'
|
5
|
+
require_relative './gengou/type'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
#
|
10
|
+
# Japan 和暦
|
11
|
+
#
|
12
|
+
module Japan
|
13
|
+
#
|
14
|
+
# GengouResource 元号情報
|
15
|
+
#
|
16
|
+
module GengouResource
|
17
|
+
# @return [Array<Set>] 元号セット情報リスト
|
18
|
+
LIST = [
|
19
|
+
Parser.run(filepath: File.expand_path(
|
20
|
+
'./yaml/set-001-until-south.yaml',
|
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
|
80
|
+
|
81
|
+
#
|
82
|
+
# 「日本暦日原典」1行目の元号を返す
|
83
|
+
#
|
84
|
+
# @param [Western::Calendar] date 日
|
85
|
+
#
|
86
|
+
# @return [Gengou] 元号情報(1行目)
|
87
|
+
#
|
88
|
+
def self.first_line(date:)
|
89
|
+
lines = lines(date: date)
|
90
|
+
lines[0].clone
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# 「日本暦日原典」2行目の元号を返す
|
95
|
+
#
|
96
|
+
# @param [Western::Calendar] date 日
|
97
|
+
#
|
98
|
+
# @return [Gengou] 元号情報(2行目)
|
99
|
+
#
|
100
|
+
def self.second_line(date:)
|
101
|
+
lines = lines(date: date)
|
102
|
+
lines[1].clone
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../western'
|
4
|
+
require_relative './type'
|
5
|
+
require_relative './validator'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
module Zakuro
|
10
|
+
#
|
11
|
+
# Japan 和暦
|
12
|
+
#
|
13
|
+
module Japan
|
14
|
+
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
15
|
+
|
16
|
+
#
|
17
|
+
# Parser yaml解析
|
18
|
+
#
|
19
|
+
module Parser
|
20
|
+
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
21
|
+
|
22
|
+
#
|
23
|
+
# GengouParser 元号情報の検証/展開を行う
|
24
|
+
#
|
25
|
+
class GengouParser
|
26
|
+
# @return [Integer] 要素位置
|
27
|
+
attr_reader :index
|
28
|
+
# @return [String] 元号名
|
29
|
+
attr_reader :name
|
30
|
+
# @return [String] 開始日
|
31
|
+
attr_reader :start_date
|
32
|
+
# @return [String] 元旦
|
33
|
+
attr_reader :new_year_date
|
34
|
+
# @return [String] 開始年
|
35
|
+
attr_reader :start_year
|
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
|
+
@start_date = hash['start_date']
|
47
|
+
@new_year_date = hash['new_year_date']
|
48
|
+
@start_year = hash['start_year']
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# 元号情報を生成する
|
53
|
+
#
|
54
|
+
# @return [Gengou] 元号情報
|
55
|
+
#
|
56
|
+
def create
|
57
|
+
start_date = Western::Calendar.parse(str: @start_date)
|
58
|
+
new_year_date = Western::Calendar.parse(str: @new_year_date)
|
59
|
+
start_year = @start_year || 1
|
60
|
+
|
61
|
+
Gengou.new(name: @name, start_date: start_date, new_year_date: new_year_date,
|
62
|
+
year: start_year)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# SetParser 元号セット情報の検証/展開
|
68
|
+
#
|
69
|
+
class SetParser
|
70
|
+
# @return [String] 元号セットID
|
71
|
+
attr_reader :id
|
72
|
+
# @return [String] 元号セット名
|
73
|
+
attr_reader :name
|
74
|
+
# @return [String] 終了日
|
75
|
+
attr_reader :end_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
|
+
@end_date = hash['end_date']
|
88
|
+
@list = hash['list']
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# 元号セット情報を生成する
|
93
|
+
#
|
94
|
+
# @return [Set] 元号セット情報
|
95
|
+
#
|
96
|
+
def create
|
97
|
+
end_date = Western::Calendar.parse(str: @end_date)
|
98
|
+
list = create_list
|
99
|
+
Set.new(
|
100
|
+
id: @id, name: @name, end_date: end_date, list: list
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
105
|
+
|
106
|
+
#
|
107
|
+
# 元号情報を生成する
|
108
|
+
#
|
109
|
+
# @return [Array<Gengou>] 元号情報
|
110
|
+
#
|
111
|
+
def create_list
|
112
|
+
result = []
|
113
|
+
@list.each_with_index do |li, index|
|
114
|
+
gengou = GengouParser.new(hash: li, index: index).create
|
115
|
+
next_index = index + 1
|
116
|
+
gengou = calc_end_date_on_gengou_data(next_index: next_index,
|
117
|
+
gengou: gengou)
|
118
|
+
result.push(gengou)
|
119
|
+
end
|
120
|
+
|
121
|
+
result
|
122
|
+
end
|
123
|
+
|
124
|
+
# :reek:TooManyStatements { max_statements: 6 }
|
125
|
+
|
126
|
+
#
|
127
|
+
# 次の元号の開始日から、元号の終了日に変換する
|
128
|
+
#
|
129
|
+
# @param [Integer] next_index 次の元号の要素位置
|
130
|
+
# @param [String] gengou 次回開始日
|
131
|
+
#
|
132
|
+
# @return [Gengou] 元号情報
|
133
|
+
#
|
134
|
+
def calc_end_date_on_gengou_data(next_index:, gengou:)
|
135
|
+
if next_index >= @list.size
|
136
|
+
end_date = Western::Calendar.parse(str: @end_date)
|
137
|
+
gengou.write_end_date(end_date: end_date)
|
138
|
+
return gengou
|
139
|
+
end
|
140
|
+
next_start_date = @list[next_index]['start_date']
|
141
|
+
gengou.convert_next_start_date_to_end_date(
|
142
|
+
next_start_date_string: next_start_date
|
143
|
+
)
|
144
|
+
gengou
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# 解析/展開する
|
150
|
+
#
|
151
|
+
# @param [String] filepath 元号セットファイルパス
|
152
|
+
#
|
153
|
+
# @return [Set] 元号セット情報
|
154
|
+
#
|
155
|
+
def self.run(filepath: '')
|
156
|
+
yaml = YAML.load_file(filepath)
|
157
|
+
|
158
|
+
failed = Validator.run(yaml_hash: yaml)
|
159
|
+
|
160
|
+
raise ArgumentError, failed.join("\n") unless failed.empty?
|
161
|
+
|
162
|
+
parser = SetParser.new(hash: yaml)
|
163
|
+
parser.create
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../western'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
#
|
8
|
+
# Japan 和暦
|
9
|
+
#
|
10
|
+
module Japan
|
11
|
+
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
12
|
+
|
13
|
+
#
|
14
|
+
# Gengou 元号情報
|
15
|
+
#
|
16
|
+
class Gengou
|
17
|
+
# @return [String] 元号名
|
18
|
+
attr_reader :name
|
19
|
+
# @return [Western::Calendar] 開始日
|
20
|
+
attr_reader :start_date
|
21
|
+
# @return [Western::Calendar] 元旦
|
22
|
+
attr_reader :new_year_date
|
23
|
+
# @return [Western::Calendar] 終了日
|
24
|
+
attr_reader :end_date
|
25
|
+
# @return [Integer] 元号年
|
26
|
+
attr_reader :year
|
27
|
+
|
28
|
+
#
|
29
|
+
# 初期化
|
30
|
+
#
|
31
|
+
# @param [String] name 元号名
|
32
|
+
# @param [Western::Calendar] start_date 開始日
|
33
|
+
# @param [Western::Calendar] new_year_date 元旦
|
34
|
+
# @param [Western::Calendar] end_date 終了日
|
35
|
+
# @param [Integer] year 元号年
|
36
|
+
#
|
37
|
+
def initialize(name: '', start_date: Western::Calendar.new,
|
38
|
+
new_year_date: Western::Calendar.new,
|
39
|
+
end_date: Western::Calendar.new, year: -1)
|
40
|
+
@name = name
|
41
|
+
@start_date = start_date
|
42
|
+
@new_year_date = new_year_date
|
43
|
+
@end_date = end_date
|
44
|
+
@year = year
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# 終了日を更新する
|
49
|
+
#
|
50
|
+
# @param [Western::Calendar] end_date 終了日
|
51
|
+
#
|
52
|
+
def write_end_date(end_date:)
|
53
|
+
unless Gengou.valid_date(date: end_date)
|
54
|
+
raise ArgumentError, "invalid date format. [#{end_date}]"
|
55
|
+
end
|
56
|
+
|
57
|
+
@end_date = end_date
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# 日付が有効かどうかを確認する
|
63
|
+
#
|
64
|
+
# @param [Western::Calendar] date 日付
|
65
|
+
#
|
66
|
+
# @return [True] 有効
|
67
|
+
# @return [False] 無効
|
68
|
+
#
|
69
|
+
def self.valid_date(date:)
|
70
|
+
return false unless date
|
71
|
+
|
72
|
+
date.is_a?(Western::Calendar)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# 次の元号の開始日から、元号の終了日に変換する
|
77
|
+
#
|
78
|
+
# @param [String] next_start_date_string 次回開始日
|
79
|
+
#
|
80
|
+
def convert_next_start_date_to_end_date(next_start_date_string: '')
|
81
|
+
raise ArgumentError, 'empty string cannot convert' if next_start_date_string.empty?
|
82
|
+
|
83
|
+
start_date = Western::Calendar.parse(str: next_start_date_string)
|
84
|
+
@end_date = start_date - 1
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# 指定した日が元号に含まれるか
|
90
|
+
#
|
91
|
+
# @param [Western::Calendar] date 日
|
92
|
+
#
|
93
|
+
# @return [True] 含まれる
|
94
|
+
# @return [False] 含まれない
|
95
|
+
#
|
96
|
+
def include?(date:)
|
97
|
+
date >= @start_date && date <= @end_date
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# 不正な元号データかを確認する
|
102
|
+
#
|
103
|
+
# @return [True] 正しくない
|
104
|
+
# @return [True] 正しい
|
105
|
+
#
|
106
|
+
def invalid?
|
107
|
+
@year == -1
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# 1元号年を追加する
|
112
|
+
#
|
113
|
+
def next_year
|
114
|
+
@year += 1 unless invalid?
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def to_s
|
119
|
+
"name: #{@name}, start_date: #{@start_date.format}, " \
|
120
|
+
"end_date: #{@end_date.format}, year: #{@year}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Set 元号セット
|
126
|
+
#
|
127
|
+
class Set
|
128
|
+
# @return [Integer] 元号セットID
|
129
|
+
attr_reader :id
|
130
|
+
# @return [String] 元号セット名
|
131
|
+
attr_reader :name
|
132
|
+
# @return [Western::Calendar] 元号セットでの終了日
|
133
|
+
attr_reader :end_date
|
134
|
+
# @return [Array<Gengou>] 元号リスト
|
135
|
+
attr_reader :list
|
136
|
+
|
137
|
+
#
|
138
|
+
# 初期化
|
139
|
+
#
|
140
|
+
# @param [Integer] id 元号セットID
|
141
|
+
# @param [String] name 元号セット名
|
142
|
+
# @param [Western::Calendar] end_date 元号セットでの終了日
|
143
|
+
# @param [Array<Gengou>] list 元号リスト
|
144
|
+
#
|
145
|
+
def initialize(id: -1, name: '', end_date: Western::Calendar.new, list: [])
|
146
|
+
@id = id
|
147
|
+
@name = name
|
148
|
+
@end_date = end_date
|
149
|
+
@list = list
|
150
|
+
end
|
151
|
+
|
152
|
+
#
|
153
|
+
# 指定した日付を含む元号を返す
|
154
|
+
#
|
155
|
+
# @param [Western::Calendar] date 日
|
156
|
+
#
|
157
|
+
# @return [Gengou] 元号
|
158
|
+
#
|
159
|
+
def include_item(date:)
|
160
|
+
@list.each do |item|
|
161
|
+
return item if item.include?(date: date)
|
162
|
+
end
|
163
|
+
|
164
|
+
Gengou.new
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
# 元号セットが不正かどうかを確認する
|
169
|
+
#
|
170
|
+
# @return [True] 正しくない
|
171
|
+
# @return [False] 正しい
|
172
|
+
#
|
173
|
+
def invalid?
|
174
|
+
@id == -1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|