zakuro 0.0.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- 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 +151 -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 +120 -0
- data/lib/zakuro/calculation/monthly/month.rb +184 -0
- data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
- data/lib/zakuro/calculation/monthly/operated_month.rb +201 -0
- data/lib/zakuro/calculation/range/full_range.rb +210 -0
- data/lib/zakuro/calculation/range/operated_range.rb +134 -0
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +76 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +142 -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 +17 -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 +1 -1
- 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 +164 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
- data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +7 -7
- data/lib/zakuro/version/senmyou/stella/solar_average.rb +103 -138
- data/lib/zakuro/version/senmyou/stella/solar_location.rb +213 -0
- data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +6 -191
- 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 +49 -20
- data/lib/zakuro/cycle/abstract_remainder.rb +0 -457
- data/lib/zakuro/cycle/zodiac.rb +0 -103
- data/lib/zakuro/era/japan.rb +0 -660
- data/lib/zakuro/output/result.rb +0 -219
- 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 -186
- data/lib/zakuro/version/senmyou/summary/full_range.rb +0 -216
- data/lib/zakuro/version/senmyou/summary/specifier.rb +0 -100
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../base/multi_gengou_roller'
|
4
|
+
require_relative '../base/year'
|
5
|
+
|
6
|
+
require_relative '../../era/western'
|
7
|
+
require_relative '../../output/response'
|
8
|
+
require_relative '../../output/logger'
|
9
|
+
|
10
|
+
# :nodoc:
|
11
|
+
module Zakuro
|
12
|
+
# :nodoc:
|
13
|
+
module Calculation
|
14
|
+
# :nodoc:
|
15
|
+
module Specifier
|
16
|
+
#
|
17
|
+
# SingleDay 一日検索
|
18
|
+
#
|
19
|
+
module SingleDay
|
20
|
+
# @return [Output::Logger] ロガー
|
21
|
+
LOGGER = Output::Logger.new(location: 'specifier')
|
22
|
+
|
23
|
+
#
|
24
|
+
# 取得する
|
25
|
+
#
|
26
|
+
# @param [Array<Year>] yeas 範囲
|
27
|
+
# @param [Western::Calendar] date 西暦日
|
28
|
+
#
|
29
|
+
# @return [Result::Data::SingleDay] 和暦日
|
30
|
+
#
|
31
|
+
def self.get(years: [], date: Western::Calendar.new)
|
32
|
+
year = specify_year(years: years, date: date)
|
33
|
+
|
34
|
+
year = transfer(year: year, date: date)
|
35
|
+
|
36
|
+
month = specify_month(year: year, date: date)
|
37
|
+
first_date = month.western_date
|
38
|
+
|
39
|
+
Output::Response::SingleDay.save_single_day(
|
40
|
+
param: Output::Response::SingleDay::Param.new(
|
41
|
+
year: year, month: month,
|
42
|
+
date: date, days: date - first_date
|
43
|
+
)
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# 年を特定する
|
49
|
+
#
|
50
|
+
# @param [Array<Year>] years 範囲
|
51
|
+
# @param [Western::Calendar] date 西暦日
|
52
|
+
#
|
53
|
+
# @return [Year] 対象年
|
54
|
+
#
|
55
|
+
def self.specify_year(years:, date:)
|
56
|
+
years.reverse_each do |year|
|
57
|
+
return year if date >= year.new_year_date
|
58
|
+
end
|
59
|
+
|
60
|
+
raise ArgumentError, "invalid year range. date: #{date.format}"
|
61
|
+
end
|
62
|
+
private_class_method :specify_year
|
63
|
+
|
64
|
+
#
|
65
|
+
# 改元する
|
66
|
+
#
|
67
|
+
# @param [Year] year 年
|
68
|
+
# @param [Western::Calendar] date 西暦日
|
69
|
+
#
|
70
|
+
# @return [Year] 改元後の年
|
71
|
+
#
|
72
|
+
def self.transfer(year:, date:)
|
73
|
+
multi_gengou = Calculation::Base::MultiGengouRoller.transfer(
|
74
|
+
multi_gengou: year.multi_gengou, date: date
|
75
|
+
)
|
76
|
+
Calculation::Base::Year.new(
|
77
|
+
multi_gengou: multi_gengou, new_year_date: year.new_year_date,
|
78
|
+
months: year.months, total_days: year.total_days
|
79
|
+
)
|
80
|
+
end
|
81
|
+
private_class_method :transfer
|
82
|
+
|
83
|
+
# :reek:TooManyStatements { max_statements: 7 }
|
84
|
+
|
85
|
+
#
|
86
|
+
# 月を特定する
|
87
|
+
#
|
88
|
+
# @param [Year] year 年
|
89
|
+
# @param [Western::Calendar] date 西暦日
|
90
|
+
#
|
91
|
+
# @return [Month] 対象月
|
92
|
+
#
|
93
|
+
def self.specify_month(year:, date:)
|
94
|
+
months = year.months
|
95
|
+
|
96
|
+
current_month = months[0]
|
97
|
+
months.each do |month|
|
98
|
+
return current_month if month.western_date > date
|
99
|
+
|
100
|
+
current_month = month
|
101
|
+
end
|
102
|
+
|
103
|
+
current_month
|
104
|
+
end
|
105
|
+
private_class_method :specify_month
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../specifier/single_day'
|
4
|
+
|
5
|
+
require_relative '../range/operated_range'
|
6
|
+
|
7
|
+
require_relative '../range/full_range'
|
8
|
+
|
9
|
+
# :nodoc:
|
10
|
+
module Zakuro
|
11
|
+
# :nodoc:
|
12
|
+
module Calculation
|
13
|
+
# :nodoc:
|
14
|
+
module Summary
|
15
|
+
#
|
16
|
+
# Single 一日
|
17
|
+
#
|
18
|
+
module Single
|
19
|
+
#
|
20
|
+
# 生成する
|
21
|
+
#
|
22
|
+
# @param [Context] context 暦コンテキスト
|
23
|
+
# @param [Western::Calendar] date 西暦日
|
24
|
+
#
|
25
|
+
# @return [Result::Single] 一日検索結果(和暦日)
|
26
|
+
#
|
27
|
+
def self.get(context:, date: Western::Calendar.new)
|
28
|
+
full_range = Calculation::Range::FullRange.new(context: context, start_date: date)
|
29
|
+
years = full_range.get
|
30
|
+
|
31
|
+
calc_date = Calculation::Specifier::SingleDay.get(
|
32
|
+
years: years, date: date
|
33
|
+
)
|
34
|
+
|
35
|
+
operated_range = Calculation::Range::OperatedRange.new(context: context, years: years)
|
36
|
+
|
37
|
+
Result::Single.new(
|
38
|
+
data: Calculation::Specifier::SingleDay.get(
|
39
|
+
years: operated_range.get, date: date
|
40
|
+
),
|
41
|
+
operation: create_operation(calc_date: calc_date)
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# 運用情報を生成する
|
47
|
+
#
|
48
|
+
# @param [Result::Data::SingleDay] calc_date 和暦日(計算値)
|
49
|
+
#
|
50
|
+
# @return [Result::Operation::Bundle] 運用情報
|
51
|
+
#
|
52
|
+
def self.create_operation(calc_date: Result::Data::SingleDay.new)
|
53
|
+
first_day = calc_date.month.first_day.western_date
|
54
|
+
operation_history = Operation.specify_history(western_date: first_day)
|
55
|
+
|
56
|
+
operation_month = create_operation_month(operation_history: operation_history)
|
57
|
+
|
58
|
+
Result::Operation::Bundle.new(
|
59
|
+
operated: !operation_history.invalid?, month: operation_month, original: calc_date
|
60
|
+
)
|
61
|
+
end
|
62
|
+
private_class_method :create_operation
|
63
|
+
|
64
|
+
#
|
65
|
+
# 月履歴集約情報を生成する
|
66
|
+
#
|
67
|
+
# @param [Operation::MonthHistory] operation_history 変更履歴(月)
|
68
|
+
#
|
69
|
+
# @return [Result::Operation::Month::Bundle] 月履歴集約情報
|
70
|
+
#
|
71
|
+
def self.create_operation_month(operation_history: Operation::MonthHistory.new)
|
72
|
+
return Result::Operation::Month::Bundle.new if operation_history.invalid?
|
73
|
+
|
74
|
+
parent_operation_history = Operation.specify_history_by_id(
|
75
|
+
id: operation_history.parent_id
|
76
|
+
)
|
77
|
+
|
78
|
+
Result::Operation::Month::Bundle.new(
|
79
|
+
current: create_operation_month_history(operation_history: operation_history),
|
80
|
+
parent: create_operation_month_history(operation_history: parent_operation_history)
|
81
|
+
)
|
82
|
+
end
|
83
|
+
private_class_method :create_operation_month
|
84
|
+
|
85
|
+
#
|
86
|
+
# 月別履歴情報を生成する
|
87
|
+
#
|
88
|
+
# @param [Operation::MonthHistory] operation_history 変更履歴(月)
|
89
|
+
#
|
90
|
+
# @return [Result::Operation::Month::History] 月別履歴情報
|
91
|
+
#
|
92
|
+
def self.create_operation_month_history(operation_history: Operation::MonthHistory.new)
|
93
|
+
return Result::Operation::Month::History.new if operation_history.invalid?
|
94
|
+
|
95
|
+
annotations = create_annnotations(operation_history: operation_history)
|
96
|
+
|
97
|
+
reference = operation_history.reference
|
98
|
+
Result::Operation::Month::History.new(
|
99
|
+
id: operation_history.id, western_date: operation_history.western_date.format,
|
100
|
+
page: reference.page, number: reference.number, annotations: annotations
|
101
|
+
)
|
102
|
+
end
|
103
|
+
private_class_method :create_operation_month_history
|
104
|
+
|
105
|
+
#
|
106
|
+
# 注釈情報を生成する
|
107
|
+
#
|
108
|
+
# @param [Operation::MonthHistory] operation_history 変更履歴(月)
|
109
|
+
#
|
110
|
+
# @return [Array<Result::Operation::Month::Annotation>] 注釈
|
111
|
+
#
|
112
|
+
def self.create_annnotations(operation_history: Operation::MonthHistory.new)
|
113
|
+
annotations = []
|
114
|
+
operation_history.annotations.each do |annotation|
|
115
|
+
annotations.push(
|
116
|
+
Result::Operation::Month::Annotation.new(
|
117
|
+
description: annotation.description,
|
118
|
+
note: annotation.note
|
119
|
+
)
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
annotations
|
124
|
+
end
|
125
|
+
private_class_method :create_annnotations
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
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
|
|
@@ -137,6 +138,7 @@ module Zakuro
|
|
137
138
|
class Options
|
138
139
|
# @return [Array<String>] オプション
|
139
140
|
attr_reader :options
|
141
|
+
|
140
142
|
#
|
141
143
|
# 初期化
|
142
144
|
#
|
@@ -147,7 +149,6 @@ module Zakuro
|
|
147
149
|
end
|
148
150
|
|
149
151
|
# TODO: オプションキーのバリデーション
|
150
|
-
# :reek:NilCheck
|
151
152
|
|
152
153
|
#
|
153
154
|
# 検証する
|
@@ -158,7 +159,9 @@ module Zakuro
|
|
158
159
|
#
|
159
160
|
def self.validate(options:)
|
160
161
|
failed = []
|
161
|
-
return failed
|
162
|
+
return failed unless options
|
163
|
+
|
164
|
+
return failed if options.is_a?(Hash)
|
162
165
|
|
163
166
|
failed.push("invalid options type. #{options}. should be hash")
|
164
167
|
|
@@ -221,8 +224,6 @@ module Zakuro
|
|
221
224
|
failed
|
222
225
|
end
|
223
226
|
|
224
|
-
# :reek:NilCheck
|
225
|
-
|
226
227
|
#
|
227
228
|
# 上書きする
|
228
229
|
#
|
@@ -232,7 +233,10 @@ module Zakuro
|
|
232
233
|
instance_variables.each do |var|
|
233
234
|
key = var.to_s.delete('@')
|
234
235
|
val = hash[key.intern]
|
235
|
-
|
236
|
+
|
237
|
+
next unless val
|
238
|
+
|
239
|
+
instance_variable_set(var, val)
|
236
240
|
end
|
237
241
|
end
|
238
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
|