zakuro 0.4.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -3
  3. data/VERSION +1 -0
  4. data/doc/operation/csv/month.csv +21 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/lib/zakuro/calculation/base/gengou.rb +82 -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/cycle/abstract_remainder.rb +0 -13
  11. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/list.rb +244 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +42 -0
  17. data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -0
  18. data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
  19. data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
  20. data/lib/zakuro/calculation/era/version/version.rb +24 -0
  21. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  22. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  23. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  24. data/lib/zakuro/calculation/range/full_range.rb +68 -107
  25. data/lib/zakuro/calculation/range/operated_range.rb +13 -9
  26. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  27. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  28. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  29. data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
  30. data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
  31. data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
  32. data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
  33. data/lib/zakuro/calculation/summary/range.rb +120 -0
  34. data/lib/zakuro/calculation/summary/single.rb +45 -64
  35. data/lib/zakuro/condition.rb +14 -0
  36. data/lib/zakuro/era/japan/calendar.rb +133 -0
  37. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
  38. data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
  39. data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
  40. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
  41. data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
  42. data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
  43. data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
  44. data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
  45. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
  46. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
  47. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
  48. data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
  49. data/lib/zakuro/era/japan/gengou.rb +35 -74
  50. data/lib/zakuro/era/japan/version.rb +151 -0
  51. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  52. data/lib/zakuro/merchant.rb +50 -3
  53. data/lib/zakuro/operation/month/parser.rb +1 -1
  54. data/lib/zakuro/operation/month/type.rb +1 -1
  55. data/lib/zakuro/operation/month/validator.rb +2 -2
  56. data/lib/zakuro/operation/yaml/month.yaml +672 -0
  57. data/lib/zakuro/output/response.rb +5 -5
  58. data/lib/zakuro/result/result.rb +17 -0
  59. data/lib/zakuro/tools/typeconv.rb +38 -0
  60. data/lib/zakuro/tools/typeof.rb +4 -1
  61. data/lib/zakuro/version/context.rb +24 -3
  62. data/lib/zakuro/version/daien/cycle/remainder.rb +26 -0
  63. data/lib/zakuro/version/daien/daien.rb +1 -26
  64. data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
  65. data/lib/zakuro/version/genka/const/number.rb +43 -0
  66. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  67. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  68. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  69. data/lib/zakuro/version/genka/genka.rb +1 -9
  70. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  71. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  72. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  73. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  74. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  75. data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
  76. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  77. data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
  78. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  79. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  80. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  81. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  82. data/lib/zakuro/version/senmyou/README.md +11 -7
  83. data/lib/zakuro/version/senmyou/cycle/remainder.rb +26 -0
  84. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  85. data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
  86. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  87. data/lib/zakuro/version/version_class_resolver.rb +4 -0
  88. data/zakuro.gemspec +1 -3
  89. metadata +45 -16
  90. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  91. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  92. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  93. data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
  94. data/lib/zakuro/era/japan/gengou/type.rb +0 -178
  95. data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
  96. data/lib/zakuro/era/japan/reki.rb +0 -91
  97. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  98. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  99. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  100. data/lib/zakuro/version/abstract_version.rb +0 -29
  101. data/lib/zakuro/version.rb +0 -7
  102. data/lib/zakuro/version_factory.rb +0 -59
@@ -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