zakuro 0.0.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +4 -0
- data/.gitignore +7 -1
- data/.rubocop.yml +3 -0
- data/Gemfile +2 -0
- data/Makefile +2 -0
- data/README.md +156 -10
- data/Rakefile +1 -1
- data/doc/gengou.md +315 -0
- 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/condition.rb +19 -15
- data/lib/zakuro/cycle/abstract_remainder.rb +3 -4
- 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/japan/yaml/set-001-until-south.yaml +1121 -0
- data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +485 -0
- data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +28 -0
- data/lib/zakuro/era/western.rb +11 -1
- data/lib/zakuro/merchant.rb +3 -1
- data/lib/zakuro/operation/month/parser.rb +373 -0
- data/lib/zakuro/operation/month/type.rb +458 -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 +2 -0
- data/lib/zakuro/output/logger.rb +2 -0
- data/lib/zakuro/output/response.rb +21 -19
- 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/senmyou/README.md +3 -1
- data/lib/zakuro/version/senmyou/base/era.rb +3 -1
- data/lib/zakuro/version/senmyou/base/multi_gengou.rb +98 -0
- data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +217 -0
- data/lib/zakuro/version/senmyou/base/remainder.rb +4 -4
- data/lib/zakuro/version/senmyou/base/solar_term.rb +20 -0
- data/lib/zakuro/version/senmyou/base/year.rb +52 -6
- data/lib/zakuro/version/senmyou/monthly/first_day.rb +44 -0
- data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +48 -0
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
- data/lib/zakuro/version/senmyou/monthly/month.rb +136 -67
- data/lib/zakuro/version/senmyou/monthly/month_label.rb +87 -0
- data/lib/zakuro/version/senmyou/monthly/operated_month.rb +167 -0
- data/lib/zakuro/version/senmyou/{summary/annual_data.rb → range/annual_range.rb} +38 -40
- data/lib/zakuro/version/senmyou/range/full_range.rb +324 -0
- data/lib/zakuro/version/senmyou/range/operated_range.rb +126 -0
- data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +181 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +2 -2
- data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +102 -0
- data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +1 -1
- data/lib/zakuro/version/senmyou/stella/solar_average.rb +54 -32
- data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +3 -7
- data/lib/zakuro/version/senmyou/summary/single.rb +125 -0
- data/lib/zakuro/version_factory.rb +1 -1
- metadata +40 -13
- data/.travis.yml +0 -6
- data/lib/zakuro/era/gengou/set-001-until-south.yaml +0 -375
- data/lib/zakuro/era/gengou/set-002-from-north.yaml +0 -166
- data/lib/zakuro/era/gengou/set-003-modern.yaml +0 -12
- data/lib/zakuro/era/japan.rb +0 -630
- data/lib/zakuro/output/result.rb +0 -219
- data/lib/zakuro/version/senmyou/base/gengou.rb +0 -210
- data/lib/zakuro/version/senmyou/summary/gengou_data.rb +0 -294
data/lib/zakuro/output/error.rb
CHANGED
data/lib/zakuro/output/logger.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'result'
|
3
|
+
require_relative '../result/result'
|
4
|
+
|
5
|
+
# TODO: outputモジュール内にする
|
4
6
|
|
5
7
|
# :nodoc:
|
6
8
|
module Zakuro
|
@@ -53,7 +55,7 @@ module Zakuro
|
|
53
55
|
month = param.month
|
54
56
|
date = param.date
|
55
57
|
days = param.days
|
56
|
-
Result::SingleDay.new(
|
58
|
+
Result::Data::SingleDay.new(
|
57
59
|
year: save_year(year: year),
|
58
60
|
month: save_month(month: month, date: date, days: days),
|
59
61
|
day: save_day(month: month, date: date, days: days)
|
@@ -68,15 +70,15 @@ module Zakuro
|
|
68
70
|
# @return [Result::Year] 年データ
|
69
71
|
#
|
70
72
|
def self.save_year(year:)
|
71
|
-
|
72
|
-
first =
|
73
|
-
second =
|
74
|
-
Result::Year.new(
|
73
|
+
multi_gengou = year.multi_gengou
|
74
|
+
first = multi_gengou.first_line
|
75
|
+
second = multi_gengou.second_line
|
76
|
+
Result::Data::Year.new(
|
75
77
|
first_gengou:
|
76
|
-
Result::Gengou.new(name: first.name, number: first.year),
|
78
|
+
Result::Data::Gengou.new(name: first.name, number: first.year),
|
77
79
|
second_gengou:
|
78
|
-
Result::Gengou.new(name: second.name, number: second.year),
|
79
|
-
zodiac_name:
|
80
|
+
Result::Data::Gengou.new(name: second.name, number: second.year),
|
81
|
+
zodiac_name: year.zodiac_name, total_days: year.total_days
|
80
82
|
)
|
81
83
|
end
|
82
84
|
private_class_method :save_year
|
@@ -91,8 +93,8 @@ module Zakuro
|
|
91
93
|
# @return [Result::Month] 月データ
|
92
94
|
#
|
93
95
|
def self.save_month(month:, date:, days:)
|
94
|
-
Result::Month.new(
|
95
|
-
number: month.number, leaped: month.leaped
|
96
|
+
Result::Data::Month.new(
|
97
|
+
number: month.number, leaped: month.leaped?, days_name: month.days_name,
|
96
98
|
first_day: save_first_day(remainder: month.remainder,
|
97
99
|
date: date, days: days),
|
98
100
|
odd_solar_terms: save_solar_term(term: month.odd_term),
|
@@ -112,11 +114,11 @@ module Zakuro
|
|
112
114
|
#
|
113
115
|
def self.save_first_day(remainder:, date:, days:)
|
114
116
|
western_date = date.clone - days
|
115
|
-
Result::Day.new(
|
117
|
+
Result::Data::Day.new(
|
116
118
|
number: 1,
|
117
119
|
zodiac_name: remainder.zodiac_name,
|
118
|
-
remainder: remainder
|
119
|
-
western_date: western_date
|
120
|
+
remainder: remainder,
|
121
|
+
western_date: western_date
|
120
122
|
)
|
121
123
|
end
|
122
124
|
private_class_method :save_first_day
|
@@ -134,9 +136,9 @@ module Zakuro
|
|
134
136
|
return [] if term.invalid?
|
135
137
|
|
136
138
|
[
|
137
|
-
Result::SolarTerm.new(
|
139
|
+
Result::Data::SolarTerm.new(
|
138
140
|
index: term.index,
|
139
|
-
remainder: term.remainder
|
141
|
+
remainder: term.remainder
|
140
142
|
)
|
141
143
|
]
|
142
144
|
end
|
@@ -157,11 +159,11 @@ module Zakuro
|
|
157
159
|
# 常に参照元のRemainderクラスで生成する
|
158
160
|
remainder.class.new(day: days, minute: 0, second: 0)
|
159
161
|
)
|
160
|
-
Result::Day.new(
|
162
|
+
Result::Data::Day.new(
|
161
163
|
number: (days + 1),
|
162
164
|
zodiac_name: remainder.zodiac_name,
|
163
|
-
remainder: remainder
|
164
|
-
western_date: date
|
165
|
+
remainder: remainder,
|
166
|
+
western_date: date
|
165
167
|
)
|
166
168
|
end
|
167
169
|
private_class_method :save_day
|
@@ -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
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './core'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
#
|
8
|
+
# Result 演算結果
|
9
|
+
#
|
10
|
+
module Result
|
11
|
+
#
|
12
|
+
# データ部
|
13
|
+
#
|
14
|
+
module Data
|
15
|
+
#
|
16
|
+
# SingleDay 1日
|
17
|
+
#
|
18
|
+
class SingleDay < Core
|
19
|
+
# @return [Year] 年
|
20
|
+
attr_reader :year
|
21
|
+
# @return [Month] 月
|
22
|
+
attr_reader :month
|
23
|
+
# @return [Day] 日
|
24
|
+
attr_reader :day
|
25
|
+
|
26
|
+
#
|
27
|
+
# 初期化
|
28
|
+
#
|
29
|
+
# @param [Year] year 年
|
30
|
+
# @param [Month] month 月
|
31
|
+
# @param [Day] day 日
|
32
|
+
#
|
33
|
+
def initialize(year:, month:, day:)
|
34
|
+
super
|
35
|
+
@year = year
|
36
|
+
@month = month
|
37
|
+
@day = day
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Gengou 元号
|
43
|
+
#
|
44
|
+
class Gengou
|
45
|
+
# @return [String] 元号名
|
46
|
+
attr_reader :name
|
47
|
+
# @return [Integer] 元号年
|
48
|
+
attr_reader :number
|
49
|
+
|
50
|
+
#
|
51
|
+
# 初期化
|
52
|
+
#
|
53
|
+
# @param [String] name 元号名
|
54
|
+
# @param [Integer] number 元号年
|
55
|
+
#
|
56
|
+
def initialize(name: '', number: -1)
|
57
|
+
@name = name
|
58
|
+
@number = number
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Year 年
|
64
|
+
#
|
65
|
+
class Year
|
66
|
+
# @return [Gengou] 元号(1行目)
|
67
|
+
attr_reader :first_gengou
|
68
|
+
# @return [Gengou] 元号(2行目)
|
69
|
+
attr_reader :second_gengou
|
70
|
+
# @return [String] 十干十二支
|
71
|
+
attr_reader :zodiac_name
|
72
|
+
# @return [Integer] 日数
|
73
|
+
attr_reader :total_days
|
74
|
+
|
75
|
+
#
|
76
|
+
# 初期化
|
77
|
+
#
|
78
|
+
# @param [Gengou] first_gengou 元号(1行目)
|
79
|
+
# @param [Gengou] second_gengou 元号(2行目)
|
80
|
+
# @param [String] zodiac_name 十干十二支
|
81
|
+
# @param [Integer] total_days 日数
|
82
|
+
#
|
83
|
+
def initialize(first_gengou:, second_gengou:, zodiac_name:, total_days:)
|
84
|
+
@first_gengou = first_gengou
|
85
|
+
@second_gengou = second_gengou
|
86
|
+
@zodiac_name = zodiac_name
|
87
|
+
@total_days = total_days
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# SolarTerm 二十四節気
|
93
|
+
#
|
94
|
+
class SolarTerm
|
95
|
+
# @return [Integer] 連番
|
96
|
+
attr_reader :index
|
97
|
+
# @return [String] 大余小余
|
98
|
+
attr_reader :remainder
|
99
|
+
|
100
|
+
#
|
101
|
+
# 初期化
|
102
|
+
#
|
103
|
+
# @param [Integer] index 連番
|
104
|
+
# @param [String] remainder 大余小余
|
105
|
+
#
|
106
|
+
def initialize(index:, remainder:)
|
107
|
+
@index = index
|
108
|
+
@remainder = remainder
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# :reek:TooManyInstanceVariables { max_instance_variables: 6 }
|
113
|
+
|
114
|
+
#
|
115
|
+
# Month 月
|
116
|
+
#
|
117
|
+
class Month
|
118
|
+
# @return [Integer] 月順(1-12)
|
119
|
+
attr_reader :number
|
120
|
+
# @return [True] 閏月
|
121
|
+
# @return [False] 平月
|
122
|
+
attr_reader :leaped
|
123
|
+
# @return [String] 月の大小
|
124
|
+
attr_reader :days_name
|
125
|
+
# @return [Day] 月初日データ
|
126
|
+
attr_reader :first_day
|
127
|
+
# @return [SolarTerm] 二十四節気(節気)
|
128
|
+
attr_reader :odd_solar_terms
|
129
|
+
# @return [SolarTerm] 二十四節気(中気)
|
130
|
+
attr_reader :even_solar_terms
|
131
|
+
|
132
|
+
# rubocop:disable Metrics/ParameterLists
|
133
|
+
# :reek:LongParameterList { max_params: 6 }
|
134
|
+
|
135
|
+
#
|
136
|
+
# 初期化
|
137
|
+
#
|
138
|
+
# @param [Integer] number 月順(1-12)
|
139
|
+
# @param [True, False] leaped 閏月/平月
|
140
|
+
# @param [String] days_name 月の大小
|
141
|
+
# @param [Day] first_day 月初日データ
|
142
|
+
# @param [SolarTerm] odd_solar_terms 二十四節気(節気)
|
143
|
+
# @param [SolarTerm] even_solar_terms 二十四節気(中気)
|
144
|
+
#
|
145
|
+
def initialize(number:, leaped:, days_name:, first_day:,
|
146
|
+
odd_solar_terms:, even_solar_terms:)
|
147
|
+
@number = number
|
148
|
+
@leaped = leaped
|
149
|
+
@days_name = days_name
|
150
|
+
@first_day = first_day
|
151
|
+
@odd_solar_terms = odd_solar_terms
|
152
|
+
@even_solar_terms = even_solar_terms
|
153
|
+
end
|
154
|
+
# rubocop:enable Metrics/ParameterLists
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Day 日
|
159
|
+
#
|
160
|
+
class Day
|
161
|
+
# @return [Integer] 月初日から数えた日(M月d日のdに相当)
|
162
|
+
attr_reader :number
|
163
|
+
# @return [String] 十干十二支
|
164
|
+
attr_reader :zodiac_name
|
165
|
+
# @return [String] 大余小余
|
166
|
+
attr_reader :remainder
|
167
|
+
# @return [String] 年月日
|
168
|
+
attr_reader :western_date
|
169
|
+
|
170
|
+
#
|
171
|
+
# 初期化
|
172
|
+
#
|
173
|
+
# @param [Integer] number 月初日から数えた日(M月d日のdに相当)
|
174
|
+
# @param [String] zodiac_name 十干十二支
|
175
|
+
# @param [String] remainder 大余小余
|
176
|
+
# @param [String] western_date 年月日
|
177
|
+
#
|
178
|
+
def initialize(number:, zodiac_name:, remainder:, western_date:)
|
179
|
+
@number = number
|
180
|
+
@zodiac_name = zodiac_name
|
181
|
+
@remainder = remainder
|
182
|
+
@western_date = western_date
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Zakuro
|
5
|
+
#
|
6
|
+
# Result 演算結果
|
7
|
+
#
|
8
|
+
module Result
|
9
|
+
#
|
10
|
+
# 運用情報
|
11
|
+
#
|
12
|
+
module Operation
|
13
|
+
#
|
14
|
+
# Bundle 運用情報
|
15
|
+
#
|
16
|
+
class Bundle
|
17
|
+
# @return [True] 運用あり
|
18
|
+
# @return [False] 運用なし
|
19
|
+
attr_reader :operated
|
20
|
+
# @return [Month::Bundle] 月別履歴情報
|
21
|
+
attr_reader :month
|
22
|
+
# @return [Data::SingleDay] 計算値
|
23
|
+
attr_reader :original
|
24
|
+
|
25
|
+
#
|
26
|
+
# 初期化
|
27
|
+
#
|
28
|
+
# @param [True, False] operated 運用有無
|
29
|
+
# @param [Month::Bundle] month 月別履歴情報
|
30
|
+
# @param [Data::SingleDay] original 計算値
|
31
|
+
#
|
32
|
+
def initialize(operated:, month:, original:)
|
33
|
+
@operated = operated
|
34
|
+
@month = month
|
35
|
+
@original = original
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Month 運用情報(月)
|
41
|
+
#
|
42
|
+
module Month
|
43
|
+
#
|
44
|
+
# Bundle 月履歴集約情報
|
45
|
+
#
|
46
|
+
class Bundle
|
47
|
+
# @return [History] 月別履歴情報(当月)
|
48
|
+
attr_reader :current
|
49
|
+
# @return [History] 月別履歴情報(影響を与えた月)
|
50
|
+
attr_reader :parent
|
51
|
+
|
52
|
+
def initialize(current: History.new, parent: History.new)
|
53
|
+
@current = current
|
54
|
+
@parent = parent
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# History 月別履歴情報
|
60
|
+
#
|
61
|
+
class History
|
62
|
+
# @return [String] ID
|
63
|
+
attr_reader :id
|
64
|
+
# @return [String] 月初日の西暦日
|
65
|
+
attr_reader :western_date
|
66
|
+
# @return [Integer] 原文頁数
|
67
|
+
attr_reader :page
|
68
|
+
# @return [Integer] 原文注釈番号
|
69
|
+
attr_reader :number
|
70
|
+
# @return [Array<Zakuro::Result::Operation::Annotation>] 注釈
|
71
|
+
attr_reader :annotations
|
72
|
+
|
73
|
+
#
|
74
|
+
# 初期化
|
75
|
+
#
|
76
|
+
# @param [String] id ID
|
77
|
+
# @param [String] western_date 月初日の西暦日
|
78
|
+
# @param [Integer] page 原文頁数
|
79
|
+
# @param [Integer] number 原文注釈番号
|
80
|
+
# @param [Array<Annotation>] annotations 注釈
|
81
|
+
#
|
82
|
+
def initialize(id: '', western_date: '', page: -1, number: -1, annotations: [])
|
83
|
+
@id = id
|
84
|
+
@western_date = western_date
|
85
|
+
@page = page
|
86
|
+
@number = number
|
87
|
+
@annotations = annotations
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Annotation 注釈
|
93
|
+
#
|
94
|
+
class Annotation
|
95
|
+
# @return [String] 注釈内容
|
96
|
+
attr_reader :description
|
97
|
+
# @return [String] 注釈補記
|
98
|
+
attr_reader :note
|
99
|
+
|
100
|
+
#
|
101
|
+
# 初期化
|
102
|
+
#
|
103
|
+
# @param [String] description 注釈内容
|
104
|
+
# @param [<Type>] note 注釈補記
|
105
|
+
#
|
106
|
+
def initialize(description:, note:)
|
107
|
+
@description = description
|
108
|
+
@note = note
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|