zakuro 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +22 -7
  4. data/VERSION +1 -0
  5. data/doc/operation/transfer.rb +8 -8
  6. data/lib/zakuro/calculation/base/gengou.rb +128 -0
  7. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  8. data/lib/zakuro/calculation/base/operated_year.rb +5 -15
  9. data/lib/zakuro/calculation/base/year.rb +26 -14
  10. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
  11. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +41 -0
  23. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  24. data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
  25. data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
  26. data/lib/zakuro/calculation/era/version/version.rb +24 -0
  27. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  28. data/lib/zakuro/calculation/monthly/month.rb +88 -2
  29. data/lib/zakuro/calculation/monthly/operated_month.rb +3 -3
  30. data/lib/zakuro/calculation/range/abstract_full_range.rb +172 -0
  31. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +17 -15
  32. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  33. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  34. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  35. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  36. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -19
  37. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  38. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  39. data/lib/zakuro/calculation/summary/internal/month.rb +84 -0
  40. data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -37
  41. data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
  42. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  43. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -0
  44. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  45. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  46. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +169 -0
  47. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
  48. data/lib/zakuro/condition.rb +15 -2
  49. data/lib/zakuro/era/japan/calendar.rb +133 -0
  50. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +121 -0
  51. data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
  52. data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
  53. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
  54. data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
  55. data/lib/zakuro/era/japan/gengou/resource/parser.rb +243 -0
  56. data/lib/zakuro/era/japan/gengou/resource/type.rb +293 -0
  57. data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
  58. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
  59. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
  60. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
  61. data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
  62. data/lib/zakuro/era/japan/gengou.rb +26 -80
  63. data/lib/zakuro/era/japan/version.rb +151 -0
  64. data/lib/zakuro/era/{western.rb → western/calendar.rb} +9 -9
  65. data/lib/zakuro/exception/case/pattern.rb +35 -0
  66. data/lib/zakuro/exception/case/preset.rb +51 -0
  67. data/lib/zakuro/exception/case/template.rb +48 -0
  68. data/lib/zakuro/exception/cause.rb +28 -0
  69. data/lib/zakuro/exception/exception.rb +37 -0
  70. data/lib/zakuro/exception/zakuro_error.rb +28 -0
  71. data/lib/zakuro/gateway/locale/date.rb +127 -0
  72. data/lib/zakuro/gateway/locale/range.rb +67 -0
  73. data/lib/zakuro/gateway/range.rb +99 -0
  74. data/lib/zakuro/gateway/single.rb +70 -0
  75. data/lib/zakuro/merchant.rb +15 -4
  76. data/lib/zakuro/operation/month/parser.rb +10 -10
  77. data/lib/zakuro/operation/month/type.rb +32 -32
  78. data/lib/zakuro/operation/month/validator.rb +51 -51
  79. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  80. data/lib/zakuro/output/logger.rb +17 -3
  81. data/lib/zakuro/output/response.rb +5 -5
  82. data/lib/zakuro/result/data/day.rb +43 -0
  83. data/lib/zakuro/result/data/gengou.rb +35 -0
  84. data/lib/zakuro/result/data/month.rb +63 -0
  85. data/lib/zakuro/result/data/single_day.rb +48 -0
  86. data/lib/zakuro/result/data/solar_term.rb +35 -0
  87. data/lib/zakuro/result/data/year.rb +45 -0
  88. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  89. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  90. data/lib/zakuro/result/operation/month/history.rb +54 -0
  91. data/lib/zakuro/result/operation/operation.rb +44 -0
  92. data/lib/zakuro/result/result.rb +21 -2
  93. data/lib/zakuro/tools/typeconv.rb +38 -0
  94. data/lib/zakuro/tools/typeof.rb +4 -1
  95. data/lib/zakuro/version/context.rb +24 -3
  96. data/lib/zakuro/version/daien/daien.rb +1 -26
  97. data/lib/zakuro/version/genka/genka.rb +1 -26
  98. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  99. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  100. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  101. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  102. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  103. data/lib/zakuro/version/senmyou/README.md +11 -7
  104. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  105. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  106. data/zakuro.gemspec +1 -3
  107. metadata +74 -22
  108. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  109. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  110. data/lib/zakuro/calculation/range/full_range.rb +0 -210
  111. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  112. data/lib/zakuro/calculation/specifier/single_day.rb +0 -109
  113. data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
  114. data/lib/zakuro/era/japan/gengou/type.rb +0 -178
  115. data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
  116. data/lib/zakuro/era/japan/reki.rb +0 -91
  117. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  118. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  119. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  120. data/lib/zakuro/result/data.rb +0 -187
  121. data/lib/zakuro/result/operation.rb +0 -114
  122. data/lib/zakuro/version/abstract_version.rb +0 -29
  123. data/lib/zakuro/version.rb +0 -7
  124. data/lib/zakuro/version_factory.rb +0 -59
@@ -1,167 +0,0 @@
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
@@ -1,178 +0,0 @@
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
@@ -1,236 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../western'
4
- require_relative './type'
5
- require 'yaml'
6
-
7
- # :nodoc:
8
- module Zakuro
9
- #
10
- # Japan 和暦
11
- #
12
- module Japan
13
- #
14
- # Validator yaml解析
15
- #
16
- module Validator
17
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
18
-
19
- #
20
- # Set 元号セット情報の検証/展開
21
- #
22
- class Set
23
- # @return [String] 元号セットID
24
- attr_reader :id
25
- # @return [String] 元号セット名
26
- attr_reader :name
27
- # @return [String] 終了日
28
- attr_reader :end_date
29
- # @return [Array<Hash<String, String>>] 元号情報
30
- attr_reader :list
31
-
32
- #
33
- # 初期化
34
- #
35
- # @param [Hash<String, Object>] hash 元号セット情報
36
- #
37
- def initialize(hash:)
38
- @id = hash['id']
39
- @name = hash['name']
40
- @end_date = hash['end_date']
41
- @list = hash['list']
42
- end
43
-
44
- # :reek:TooManyStatements { max_statements: 6 }
45
-
46
- #
47
- # 検証する
48
- #
49
- # @return [Array<String>] 不正メッセージ
50
- #
51
- def validate
52
- failed = []
53
- failed.push("invalid id. #{id}") unless id?
54
-
55
- failed.push("invalid name. #{name}") unless name?
56
-
57
- failed.push("invalid end_date. #{end_date}") unless western_date?
58
-
59
- failed |= validate_list
60
- failed
61
- end
62
-
63
- #
64
- # IDを検証する
65
- #
66
- # @return [True] 正しい
67
- # @return [False] 正しくない
68
- #
69
- def id?
70
- return false unless @id
71
-
72
- @id.is_a?(Integer)
73
- end
74
-
75
- #
76
- # 元号セット名を検証する
77
- #
78
- # @return [True] 正しい
79
- # @return [False] 正しくない
80
- #
81
- def name?
82
- return false unless @name
83
-
84
- @name.is_a?(String)
85
- end
86
-
87
- #
88
- # 日付文字列を検証する
89
- #
90
- # @return [True] 正しい
91
- # @return [False] 正しくない
92
- #
93
- def western_date?
94
- Western::Calendar.valid_date_string(str: @end_date)
95
- end
96
-
97
- #
98
- # 元号情報を検証する
99
- #
100
- # @return [True] 正しい
101
- # @return [False] 正しくない
102
- #
103
- def list?
104
- return false unless @list
105
-
106
- @list.is_a?(Array)
107
- end
108
-
109
- #
110
- # 元号情報を検証する
111
- #
112
- # @return [True] 正しい
113
- # @return [False] 正しくない
114
- #
115
- def validate_list
116
- return ["invalid list. #{@list.class}"] unless list?
117
-
118
- failed = []
119
- list.each_with_index do |li, index|
120
- failed |= Gengou.new(hash: li, index: index).validate
121
- end
122
- failed
123
- end
124
- end
125
-
126
- # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
127
-
128
- #
129
- # Gengou 元号情報
130
- #
131
- class Gengou
132
- # @return [Integer] 要素位置
133
- attr_reader :index
134
- # @return [String] 元号名
135
- attr_reader :name
136
- # @return [String] 開始日
137
- attr_reader :start_date
138
- # @return [String] 元旦
139
- attr_reader :new_year_date
140
- # @return [String] 開始年
141
- attr_reader :start_year
142
-
143
- #
144
- # 初期化
145
- #
146
- # @param [Hash<String, Strin>] hash 元号情報
147
- # @param [Integer] index (元号セット内での)元号の要素位置
148
- #
149
- def initialize(hash:, index:)
150
- @index = index
151
- @name = hash['name']
152
- @start_date = hash['start_date']
153
- @new_year_date = hash['new_year_date']
154
- @start_year = hash['start_year']
155
- end
156
-
157
- # :reek:TooManyStatements { max_statements: 7 }
158
-
159
- #
160
- # 検証する
161
- #
162
- # @return [Array<String>] 不正メッセージ
163
- #
164
- def validate
165
- prefix = "list[#{index}]. "
166
- failed = []
167
-
168
- failed.push(prefix + "invalid name. #{@name}") unless name?
169
-
170
- failed.push(prefix + "invalid start_date. #{@start_date}") unless start_date?
171
-
172
- failed.push(prefix + "invalid start_year. #{@start_year}") unless year?
173
-
174
- failed.push(prefix + "invalid new_year_date. #{@new_year_date}") unless new_year_date?
175
-
176
- failed
177
- end
178
-
179
- #
180
- # 元号名を検証する
181
- #
182
- # @return [True] 正しい
183
- # @return [False] 正しくない
184
- #
185
- def name?
186
- return false unless @name
187
-
188
- @name.is_a?(String)
189
- end
190
-
191
- #
192
- # 開始日文字列を検証する
193
- #
194
- # @return [True] 正しい
195
- # @return [False] 正しくない
196
- #
197
- def start_date?
198
- Western::Calendar.valid_date_string(str: @start_date)
199
- end
200
-
201
- #
202
- # 元旦文字列を検証する
203
- #
204
- # @return [True] 正しい
205
- # @return [False] 正しくない
206
- #
207
- def new_year_date?
208
- Western::Calendar.valid_date_string(str: @new_year_date)
209
- end
210
-
211
- #
212
- # 元号年を検証する
213
- #
214
- # @return [True] 正しい
215
- # @return [False] 正しくない
216
- #
217
- def year?
218
- return true unless @start_year
219
-
220
- @start_year.is_a?(Integer)
221
- end
222
- end
223
-
224
- #
225
- # 検証する
226
- #
227
- # @param [Hash<String, Object>] yaml_hash yaml取得結果
228
- #
229
- # @return [Array<String>] 不正メッセージ
230
- #
231
- def self.run(yaml_hash:)
232
- Set.new(hash: yaml_hash).validate
233
- end
234
- end
235
- end
236
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../western'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- #
8
- # Japan 和暦
9
- #
10
- module Japan
11
- #
12
- # Reki 暦
13
- #
14
- module Reki
15
- #
16
- # Range 暦(範囲)
17
- #
18
- class Range
19
- # @return [String] 暦のクラス名
20
- # version 以下を参照
21
- attr_reader :class_name
22
- # @return [Western::Calendar] 暦の開始日
23
- attr_reader :start_date
24
-
25
- #
26
- # 初期化
27
- #
28
- # @param [String] class_name 暦のクラス名
29
- # @param [Western::Calendar] start_date 暦の開始日
30
- #
31
- def initialize(class_name:, start_date:)
32
- @class_name = class_name
33
- @start_date = start_date
34
- end
35
- end
36
-
37
- LIST = [
38
- Range.new(
39
- class_name: 'Zakuro::Genka::Gateway',
40
- start_date: Western::Calendar.new(year: 445, month: 1, day: 24)
41
- ),
42
- Range.new(
43
- class_name: 'Zakuro::Gihou::Gateway',
44
- start_date: Western::Calendar.new(year: 698, month: 2, day: 16)
45
- ),
46
- Range.new(
47
- class_name: 'Zakuro::Daien::Gateway',
48
- start_date: Western::Calendar.new(year: 764, month: 2, day: 7)
49
- ),
50
- Range.new(
51
- class_name: 'Zakuro::Senmyou::Gateway',
52
- start_date: Western::Calendar.new(year: 862, month: 2, day: 3)
53
- ),
54
- Range.new(
55
- class_name: 'Zakuro::Joukyou::Gateway',
56
- start_date: Western::Calendar.new(year: 1685, month: 2, day: 4)
57
- ),
58
- Range.new(
59
- class_name: 'Zakuro::Houryaku::Gateway',
60
- start_date: Western::Calendar.new(year: 1755, month: 2, day: 11)
61
- ),
62
- Range.new(
63
- class_name: 'Zakuro::Kansei::Gateway',
64
- start_date: Western::Calendar.new(year: 1798, month: 2, day: 16)
65
- ),
66
- Range.new(
67
- class_name: 'Zakuro::Tenpou::Gateway',
68
- start_date: Western::Calendar.new(year: 1844, month: 2, day: 18)
69
- ),
70
- Range.new(
71
- class_name: 'Zakuro::Gregorio::Gateway',
72
- start_date: Western::Calendar.new(year: 1872, month: 12, day: 9)
73
- )
74
- ].freeze
75
-
76
- #
77
- # 指定した日付から対象の暦を引き当てる
78
- #
79
- # @param [Western::Calendar] date 日付
80
- #
81
- # @return [String] 暦のクラス名
82
- #
83
- def self.class_name(date: Western::Calendar.new)
84
- LIST.reverse_each do |range|
85
- return range.class_name if date >= range.start_date
86
- end
87
- raise ArgumentError, "invalid date: #{date.format}"
88
- end
89
- end
90
- end
91
- end