zakuro 0.1.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/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/merchant.rb +2 -2
- data/lib/zakuro/output/error.rb +7 -6
- data/lib/zakuro/output/logger.rb +50 -49
- data/lib/zakuro/output/response.rb +145 -144
- data/lib/zakuro/tools/typeof.rb +2 -2
- 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 +134 -129
- data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
- data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +5 -5
- data/lib/zakuro/version/senmyou/stella/solar_average.rb +4 -4
- data/lib/zakuro/version/senmyou/stella/solar_location.rb +27 -27
- data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +2 -2
- 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 +2 -2
- metadata +24 -22
- data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
- data/lib/zakuro/cycle/zodiac.rb +0 -103
- 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 -217
- data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
- data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -148
- data/lib/zakuro/version/senmyou/base/year.rb +0 -104
- data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
- data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -119
- data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
- data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
- data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -196
- data/lib/zakuro/version/senmyou/range/full_range.rb +0 -194
- data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
- data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
- data/lib/zakuro/version/senmyou/range/western_date_allocation.rb +0 -68
- data/lib/zakuro/version/senmyou/range/year_boundary.rb +0 -138
- data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
- data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
@@ -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/merchant.rb
CHANGED
@@ -22,7 +22,7 @@ module Zakuro
|
|
22
22
|
#
|
23
23
|
def initialize(condition: {})
|
24
24
|
failed = Condition.validate(hash: condition)
|
25
|
-
raise ZakuroError, failed.join('\n') unless failed.empty?
|
25
|
+
raise Output::ZakuroError, failed.join('\n') unless failed.empty?
|
26
26
|
|
27
27
|
@condition = Condition.new(hash: condition)
|
28
28
|
end
|
@@ -36,7 +36,7 @@ module Zakuro
|
|
36
36
|
#
|
37
37
|
def offer(condition: {})
|
38
38
|
failed = Condition.validate(hash: condition)
|
39
|
-
raise ZakuroError, failed.join('\n') unless failed.empty?
|
39
|
+
raise Output::ZakuroError, failed.join('\n') unless failed.empty?
|
40
40
|
|
41
41
|
@condition.rewrite(hash: condition)
|
42
42
|
|
data/lib/zakuro/output/error.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# TODO: outputモジュール内にする
|
4
|
-
|
5
3
|
# :nodoc:
|
6
4
|
module Zakuro
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
# :nodoc:
|
6
|
+
module Output
|
7
|
+
#
|
8
|
+
# ZakuroError ライブラリ内エラー
|
9
|
+
#
|
10
|
+
class ZakuroError < StandardError
|
11
|
+
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/zakuro/output/logger.rb
CHANGED
@@ -1,65 +1,66 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# TODO: outputモジュール内にする
|
4
|
-
|
5
3
|
# :nodoc:
|
6
4
|
module Zakuro
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
19
19
|
|
20
|
-
|
20
|
+
LEVEL = LEVELS[:none]
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
# @return [String] 呼び出し位置
|
23
|
+
attr_reader :location
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def initialize(location:)
|
26
|
+
@location = location
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
#
|
30
|
+
# DEBUGレベルの標準出力を行う
|
31
|
+
#
|
32
|
+
# @param [String] messages メッセージ
|
33
|
+
#
|
34
|
+
def debug(*messages)
|
35
|
+
return if LEVEL < LEVELS[:debug]
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
output('DEBUG', *messages)
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
#
|
41
|
+
# INFOレベルの標準出力を行う
|
42
|
+
#
|
43
|
+
# @param [String] messages メッセージ
|
44
|
+
#
|
45
|
+
def info(*messages)
|
46
|
+
return if LEVEL < LEVELS[:info]
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
output('INFO', *messages)
|
49
|
+
end
|
50
50
|
|
51
|
-
|
51
|
+
private
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
@@ -2,171 +2,172 @@
|
|
2
2
|
|
3
3
|
require_relative '../result/result'
|
4
4
|
|
5
|
-
# TODO: outputモジュール内にする
|
6
|
-
|
7
5
|
# :nodoc:
|
8
6
|
module Zakuro
|
9
|
-
#
|
10
|
-
|
11
|
-
#
|
12
|
-
module Response
|
7
|
+
# :nodoc:
|
8
|
+
module Output
|
13
9
|
#
|
14
|
-
#
|
10
|
+
# Response 返却値
|
15
11
|
#
|
16
|
-
module
|
12
|
+
module Response
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# SingleDay 1日データ
|
19
15
|
#
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
29
64
|
|
30
65
|
#
|
31
|
-
#
|
66
|
+
# 年データを保存する
|
32
67
|
#
|
33
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
|
+
#
|
34
89
|
# @param [Month] month 月情報(各暦のデータ型)
|
35
90
|
# @param [Western::Calendar] date 年月日情報(西暦)
|
36
91
|
# @param [Integer] days 日数(月初日から指定日までの日数)
|
37
92
|
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
+
)
|
43
103
|
end
|
44
|
-
|
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
|
104
|
+
private_class_method :save_month
|
64
105
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
private_class_method :save_year
|
85
|
-
|
86
|
-
#
|
87
|
-
# 月データを保存する
|
88
|
-
#
|
89
|
-
# @param [Month] month 月情報(各暦のデータ型)
|
90
|
-
# @param [Western::Calendar] date 年月日情報(西暦)
|
91
|
-
# @param [Integer] days 日数(月初日から指定日までの日数)
|
92
|
-
#
|
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
|
-
)
|
103
|
-
end
|
104
|
-
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
|
105
125
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
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?
|
125
137
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
#
|
135
|
-
def self.save_solar_term(term:)
|
136
|
-
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
|
137
146
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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)
|
142
161
|
)
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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)
|
161
|
-
)
|
162
|
-
Result::Data::Day.new(
|
163
|
-
number: (days + 1),
|
164
|
-
zodiac_name: remainder.zodiac_name,
|
165
|
-
remainder: remainder,
|
166
|
-
western_date: date
|
167
|
-
)
|
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
|
168
170
|
end
|
169
|
-
private_class_method :save_day
|
170
171
|
end
|
171
172
|
end
|
172
173
|
end
|