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/output/error.rb
CHANGED
data/lib/zakuro/output/logger.rb
CHANGED
@@ -2,62 +2,65 @@
|
|
2
2
|
|
3
3
|
# :nodoc:
|
4
4
|
module Zakuro
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
# :nodoc:
|
6
|
+
module Output
|
7
|
+
#
|
8
|
+
# 軽量なロガー
|
9
|
+
# @note 本番では使用しない
|
10
|
+
#
|
11
|
+
class Logger
|
12
|
+
LEVELS = {
|
13
|
+
none: -1,
|
14
|
+
debug: 0,
|
15
|
+
info: 1
|
16
|
+
# warn : 2,
|
17
|
+
# error : 3,
|
18
|
+
}.freeze
|
17
19
|
|
18
|
-
|
20
|
+
LEVEL = LEVELS[:none]
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
# @return [String] 呼び出し位置
|
23
|
+
attr_reader :location
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
def initialize(location:)
|
26
|
+
@location = location
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
#
|
30
|
+
# DEBUGレベルの標準出力を行う
|
31
|
+
#
|
32
|
+
# @param [String] messages メッセージ
|
33
|
+
#
|
34
|
+
def debug(*messages)
|
35
|
+
return if LEVEL < LEVELS[:debug]
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
+
output('DEBUG', *messages)
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
#
|
41
|
+
# INFOレベルの標準出力を行う
|
42
|
+
#
|
43
|
+
# @param [String] messages メッセージ
|
44
|
+
#
|
45
|
+
def info(*messages)
|
46
|
+
return if LEVEL < LEVELS[:info]
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
output('INFO', *messages)
|
49
|
+
end
|
48
50
|
|
49
|
-
|
51
|
+
private
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
#
|
54
|
+
# 標準出力を行う
|
55
|
+
#
|
56
|
+
# @param [String] level ログレベル
|
57
|
+
# @param [String] messages メッセージ
|
58
|
+
#
|
59
|
+
def output(level, *messages)
|
60
|
+
messages.each do |message|
|
61
|
+
# :#{Thread.current.backtrace[5]}
|
62
|
+
p "[#{level}] #{@location}: #{message}"
|
63
|
+
end
|
61
64
|
end
|
62
65
|
end
|
63
66
|
end
|
@@ -1,170 +1,173 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'result'
|
3
|
+
require_relative '../result/result'
|
4
4
|
|
5
5
|
# :nodoc:
|
6
6
|
module Zakuro
|
7
|
-
#
|
8
|
-
|
9
|
-
#
|
10
|
-
module Response
|
7
|
+
# :nodoc:
|
8
|
+
module Output
|
11
9
|
#
|
12
|
-
#
|
10
|
+
# Response 返却値
|
13
11
|
#
|
14
|
-
module
|
12
|
+
module Response
|
15
13
|
#
|
16
|
-
#
|
14
|
+
# SingleDay 1日データ
|
17
15
|
#
|
18
|
-
|
19
|
-
#
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
module SingleDay
|
17
|
+
#
|
18
|
+
# Param 引数
|
19
|
+
#
|
20
|
+
class Param
|
21
|
+
# @return [Year] 年情報(各暦のデータ型)
|
22
|
+
attr_reader :year
|
23
|
+
# @return [Month] 月情報(各暦のデータ型)
|
24
|
+
attr_reader :month
|
25
|
+
# @return [Western::Calendar] 年月日情報(西暦)
|
26
|
+
attr_reader :date
|
27
|
+
# @return [Integer] 日数(月初日から指定日までの日数)
|
28
|
+
attr_reader :days
|
29
|
+
|
30
|
+
#
|
31
|
+
# 初期化
|
32
|
+
#
|
33
|
+
# @param [Year] year 年情報(各暦のデータ型)
|
34
|
+
# @param [Month] month 月情報(各暦のデータ型)
|
35
|
+
# @param [Western::Calendar] date 年月日情報(西暦)
|
36
|
+
# @param [Integer] days 日数(月初日から指定日までの日数)
|
37
|
+
#
|
38
|
+
def initialize(year:, month:, date:, days:)
|
39
|
+
@year = year
|
40
|
+
@month = month
|
41
|
+
@date = date
|
42
|
+
@days = days
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# 1日データを生成する
|
48
|
+
#
|
49
|
+
# @param [Parameter] param 引数
|
50
|
+
#
|
51
|
+
# @return [SingleDay] 1日データ
|
52
|
+
#
|
53
|
+
def self.save_single_day(param:)
|
54
|
+
year = param.year
|
55
|
+
month = param.month
|
56
|
+
date = param.date
|
57
|
+
days = param.days
|
58
|
+
Result::Data::SingleDay.new(
|
59
|
+
year: save_year(year: year),
|
60
|
+
month: save_month(month: month, date: date, days: days),
|
61
|
+
day: save_day(month: month, date: date, days: days)
|
62
|
+
)
|
63
|
+
end
|
27
64
|
|
28
65
|
#
|
29
|
-
#
|
66
|
+
# 年データを保存する
|
30
67
|
#
|
31
68
|
# @param [Year] year 年情報(各暦のデータ型)
|
69
|
+
#
|
70
|
+
# @return [Result::Year] 年データ
|
71
|
+
#
|
72
|
+
def self.save_year(year:)
|
73
|
+
multi_gengou = year.multi_gengou
|
74
|
+
first = multi_gengou.first_line
|
75
|
+
second = multi_gengou.second_line
|
76
|
+
Result::Data::Year.new(
|
77
|
+
first_gengou:
|
78
|
+
Result::Data::Gengou.new(name: first.name, number: first.year),
|
79
|
+
second_gengou:
|
80
|
+
Result::Data::Gengou.new(name: second.name, number: second.year),
|
81
|
+
zodiac_name: year.zodiac_name, total_days: year.total_days
|
82
|
+
)
|
83
|
+
end
|
84
|
+
private_class_method :save_year
|
85
|
+
|
86
|
+
#
|
87
|
+
# 月データを保存する
|
88
|
+
#
|
32
89
|
# @param [Month] month 月情報(各暦のデータ型)
|
33
90
|
# @param [Western::Calendar] date 年月日情報(西暦)
|
34
91
|
# @param [Integer] days 日数(月初日から指定日までの日数)
|
35
92
|
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
93
|
+
# @return [Result::Month] 月データ
|
94
|
+
#
|
95
|
+
def self.save_month(month:, date:, days:)
|
96
|
+
Result::Data::Month.new(
|
97
|
+
number: month.number, leaped: month.leaped?, days_name: month.days_name,
|
98
|
+
first_day: save_first_day(remainder: month.remainder,
|
99
|
+
date: date, days: days),
|
100
|
+
odd_solar_terms: save_solar_term(term: month.odd_term),
|
101
|
+
even_solar_terms: save_solar_term(term: month.even_term)
|
102
|
+
)
|
41
103
|
end
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
# 1日データを生成する
|
46
|
-
#
|
47
|
-
# @param [Parameter] param 引数
|
48
|
-
#
|
49
|
-
# @return [SingleDay] 1日データ
|
50
|
-
#
|
51
|
-
def self.save_single_day(param:)
|
52
|
-
year = param.year
|
53
|
-
month = param.month
|
54
|
-
date = param.date
|
55
|
-
days = param.days
|
56
|
-
Result::SingleDay.new(
|
57
|
-
year: save_year(year: year),
|
58
|
-
month: save_month(month: month, date: date, days: days),
|
59
|
-
day: save_day(month: month, date: date, days: days)
|
60
|
-
)
|
61
|
-
end
|
104
|
+
private_class_method :save_month
|
62
105
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
private_class_method :save_year
|
83
|
-
|
84
|
-
#
|
85
|
-
# 月データを保存する
|
86
|
-
#
|
87
|
-
# @param [Month] month 月情報(各暦のデータ型)
|
88
|
-
# @param [Western::Calendar] date 年月日情報(西暦)
|
89
|
-
# @param [Integer] days 日数(月初日から指定日までの日数)
|
90
|
-
#
|
91
|
-
# @return [Result::Month] 月データ
|
92
|
-
#
|
93
|
-
def self.save_month(month:, date:, days:)
|
94
|
-
Result::Month.new(
|
95
|
-
number: month.number, leaped: month.leaped, days_name: month.days_name,
|
96
|
-
first_day: save_first_day(remainder: month.remainder,
|
97
|
-
date: date, days: days),
|
98
|
-
odd_solar_terms: save_solar_term(term: month.odd_term),
|
99
|
-
even_solar_terms: save_solar_term(term: month.even_term)
|
100
|
-
)
|
101
|
-
end
|
102
|
-
private_class_method :save_month
|
106
|
+
#
|
107
|
+
# 月初日データを保存する
|
108
|
+
#
|
109
|
+
# @param [Cycle::AbstractRemainder] remainder 大余小余情報
|
110
|
+
# @param [Western::Calendar] date 年月日情報(西暦)
|
111
|
+
# @param [Integer] days 日数(月初日から指定日までの日数)
|
112
|
+
#
|
113
|
+
# @return [Result::Day] 日データ
|
114
|
+
#
|
115
|
+
def self.save_first_day(remainder:, date:, days:)
|
116
|
+
western_date = date.clone - days
|
117
|
+
Result::Data::Day.new(
|
118
|
+
number: 1,
|
119
|
+
zodiac_name: remainder.zodiac_name,
|
120
|
+
remainder: remainder,
|
121
|
+
western_date: western_date
|
122
|
+
)
|
123
|
+
end
|
124
|
+
private_class_method :save_first_day
|
103
125
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
Result::Day.new(
|
116
|
-
number: 1,
|
117
|
-
zodiac_name: remainder.zodiac_name,
|
118
|
-
remainder: remainder.format,
|
119
|
-
western_date: western_date.format
|
120
|
-
)
|
121
|
-
end
|
122
|
-
private_class_method :save_first_day
|
126
|
+
#
|
127
|
+
# 二十四節気データを保存する
|
128
|
+
#
|
129
|
+
# @note 今は宣明暦に合わせている。江戸期以降の暦には対応していない(複数の中気節気を指定できない)
|
130
|
+
#
|
131
|
+
# @param [SolarTerm] term 二十四節気情報(各暦のデータ型)
|
132
|
+
#
|
133
|
+
# @return [Array<Result::SolarTerm>] 二十四節気データ
|
134
|
+
#
|
135
|
+
def self.save_solar_term(term:)
|
136
|
+
return [] if term.invalid?
|
123
137
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
def self.save_solar_term(term:)
|
134
|
-
return [] if term.invalid?
|
138
|
+
[
|
139
|
+
Result::Data::SolarTerm.new(
|
140
|
+
index: term.index,
|
141
|
+
remainder: term.remainder
|
142
|
+
)
|
143
|
+
]
|
144
|
+
end
|
145
|
+
private_class_method :save_solar_term
|
135
146
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
147
|
+
#
|
148
|
+
# 日データを保存する
|
149
|
+
#
|
150
|
+
# @param [Month] month 月情報(各暦のデータ型)
|
151
|
+
# @param [Western::Calendar] date 年月日情報(西暦)
|
152
|
+
# @param [Integer] days 日数(月初日から指定日までの日数)
|
153
|
+
#
|
154
|
+
# @return [Result::Day] 日データ
|
155
|
+
#
|
156
|
+
def self.save_day(month:, date:, days:)
|
157
|
+
remainder = month.remainder
|
158
|
+
remainder = remainder.add(
|
159
|
+
# 常に参照元のRemainderクラスで生成する
|
160
|
+
remainder.class.new(day: days, minute: 0, second: 0)
|
140
161
|
)
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
# @param [Western::Calendar] date 年月日情報(西暦)
|
150
|
-
# @param [Integer] days 日数(月初日から指定日までの日数)
|
151
|
-
#
|
152
|
-
# @return [Result::Day] 日データ
|
153
|
-
#
|
154
|
-
def self.save_day(month:, date:, days:)
|
155
|
-
remainder = month.remainder
|
156
|
-
remainder = remainder.add(
|
157
|
-
# 常に参照元のRemainderクラスで生成する
|
158
|
-
remainder.class.new(day: days, minute: 0, second: 0)
|
159
|
-
)
|
160
|
-
Result::Day.new(
|
161
|
-
number: (days + 1),
|
162
|
-
zodiac_name: remainder.zodiac_name,
|
163
|
-
remainder: remainder.format,
|
164
|
-
western_date: date.format
|
165
|
-
)
|
162
|
+
Result::Data::Day.new(
|
163
|
+
number: (days + 1),
|
164
|
+
zodiac_name: remainder.zodiac_name,
|
165
|
+
remainder: remainder,
|
166
|
+
western_date: date
|
167
|
+
)
|
168
|
+
end
|
169
|
+
private_class_method :save_day
|
166
170
|
end
|
167
|
-
private_class_method :save_day
|
168
171
|
end
|
169
172
|
end
|
170
173
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require_relative '../tools/stringifier'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
#
|
10
|
+
# Result 演算結果
|
11
|
+
#
|
12
|
+
module Result
|
13
|
+
#
|
14
|
+
# Core 共通処理
|
15
|
+
#
|
16
|
+
class Core
|
17
|
+
#
|
18
|
+
# 初期化
|
19
|
+
#
|
20
|
+
def initialize(*_args); end
|
21
|
+
|
22
|
+
#
|
23
|
+
# ハッシュ化する
|
24
|
+
#
|
25
|
+
# @return [Hash<String, Object>] ハッシュ
|
26
|
+
#
|
27
|
+
def to_h
|
28
|
+
Tools::Stringifier.to_h(obj: self, class_prefix: 'Zakuro::Result')
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# JSON化する
|
33
|
+
#
|
34
|
+
# @param [JSON::State] _args 引数( Struct#to_json )
|
35
|
+
#
|
36
|
+
# @return [String] JSON文字列
|
37
|
+
#
|
38
|
+
def to_json(*_args)
|
39
|
+
JSON.generate(to_h)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# JSON(整形)化する
|
44
|
+
#
|
45
|
+
# @return [String] JSON(整形)文字列
|
46
|
+
#
|
47
|
+
def to_pretty_json
|
48
|
+
JSON.pretty_generate(to_h)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|