zakuro 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -43
- 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 +73 -0
- data/lib/zakuro/era/japan/gengou.rb +106 -0
- data/lib/zakuro/era/japan/gengou/parser.rb +169 -0
- data/lib/zakuro/era/japan/gengou/type.rb +178 -0
- data/lib/zakuro/era/japan/gengou/validator.rb +234 -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/operation/month/parser.rb +277 -0
- data/lib/zakuro/operation/month/type.rb +452 -0
- data/lib/zakuro/operation/month/validator.rb +498 -0
- data/lib/zakuro/operation/operation.rb +45 -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 +17 -15
- data/lib/zakuro/result/core.rb +52 -0
- data/lib/zakuro/result/data.rb +187 -0
- data/lib/zakuro/result/operation.rb +86 -0
- data/lib/zakuro/result/result.rb +37 -0
- data/lib/zakuro/{output → tools}/stringifier.rb +14 -7
- data/lib/zakuro/tools/typeof.rb +33 -0
- data/lib/zakuro/version.rb +1 -1
- data/lib/zakuro/version/senmyou/base/era.rb +1 -1
- data/lib/zakuro/version/senmyou/base/multi_gengou.rb +1 -1
- data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +13 -1
- data/lib/zakuro/version/senmyou/base/solar_term.rb +10 -0
- 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/month.rb +127 -68
- 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 → range}/annual_range.rb +20 -23
- data/lib/zakuro/version/senmyou/{summary → range}/full_range.rb +102 -2
- data/lib/zakuro/version/senmyou/range/operated_range.rb +105 -0
- data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +163 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +2 -2
- data/lib/zakuro/version/senmyou/{summary/specifier.rb → specifier/single_day_specifier.rb} +13 -14
- data/lib/zakuro/version/senmyou/stella/solar_average.rb +3 -7
- data/lib/zakuro/version/senmyou/summary/single.rb +71 -0
- data/lib/zakuro/version_factory.rb +1 -1
- metadata +35 -11
- data/lib/zakuro/era/japan.rb +0 -664
- data/lib/zakuro/output/result.rb +0 -225
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './typeof'
|
4
|
+
|
3
5
|
# :nodoc:
|
4
6
|
module Zakuro
|
5
7
|
#
|
6
|
-
#
|
8
|
+
# Tools 汎用メソッド群
|
7
9
|
#
|
8
|
-
module
|
10
|
+
module Tools
|
9
11
|
#
|
10
12
|
# Stringifier 文字列処理
|
11
13
|
#
|
@@ -18,11 +20,13 @@ module Zakuro
|
|
18
20
|
#
|
19
21
|
# @return [Hash<String, Objcet>] ハッシュ
|
20
22
|
#
|
21
|
-
def self.to_h(obj:, class_prefix:)
|
23
|
+
def self.to_h(obj:, class_prefix:, formatted: true)
|
22
24
|
hash = {}
|
23
25
|
obj.instance_variables.each do |var|
|
24
26
|
key = var.to_s.delete('@')
|
25
|
-
hash[key] = value_to_hash(
|
27
|
+
hash[key] = value_to_hash(
|
28
|
+
obj: obj.instance_variable_get(var), class_prefix: class_prefix, formatted: formatted
|
29
|
+
)
|
26
30
|
end
|
27
31
|
hash
|
28
32
|
end
|
@@ -37,19 +41,22 @@ module Zakuro
|
|
37
41
|
#
|
38
42
|
# @return [Hash<String, Objcet>] ハッシュ
|
39
43
|
#
|
40
|
-
def self.value_to_hash(obj:, class_prefix:)
|
44
|
+
def self.value_to_hash(obj:, class_prefix:, formatted:)
|
41
45
|
return obj if obj.nil?
|
42
46
|
|
47
|
+
# 日付をフォーマットする
|
48
|
+
return obj.format if formatted && Tools::Typeof.time?(obj: obj)
|
49
|
+
|
43
50
|
# 同じモジュール内のオブジェクトは再帰する
|
44
51
|
if obj.class.name.start_with?(class_prefix)
|
45
|
-
return to_h(obj: obj, class_prefix: class_prefix)
|
52
|
+
return to_h(obj: obj, class_prefix: class_prefix, formatted: formatted)
|
46
53
|
end
|
47
54
|
|
48
55
|
# 配列は要素一つずつで再帰する
|
49
56
|
if obj.is_a?(Array)
|
50
57
|
arr = []
|
51
58
|
obj.each do |item|
|
52
|
-
arr.push(to_h(obj: item, class_prefix: class_prefix))
|
59
|
+
arr.push(to_h(obj: item, class_prefix: class_prefix, formatted: formatted))
|
53
60
|
end
|
54
61
|
return arr
|
55
62
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../cycle/abstract_remainder'
|
4
|
+
require_relative '../era/western'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
#
|
9
|
+
# Tools 汎用メソッド群
|
10
|
+
#
|
11
|
+
module Tools
|
12
|
+
#
|
13
|
+
# Typeof 型判定
|
14
|
+
#
|
15
|
+
module Typeof
|
16
|
+
#
|
17
|
+
# 時間を表す型か
|
18
|
+
#
|
19
|
+
# @param [Object] obj 引数
|
20
|
+
#
|
21
|
+
# @return [True] 時間型である
|
22
|
+
# @return [False] 時間型ではない
|
23
|
+
#
|
24
|
+
def self.time?(obj:)
|
25
|
+
return true if obj.is_a?(Western::Calendar)
|
26
|
+
|
27
|
+
return true if obj.is_a?(Cycle::AbstractRemainder)
|
28
|
+
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/zakuro/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative './era'
|
4
4
|
require_relative './multi_gengou'
|
5
5
|
|
6
|
-
require_relative '../../../era/japan'
|
6
|
+
require_relative '../../../era/japan/gengou'
|
7
7
|
|
8
8
|
# :nodoc:
|
9
9
|
module Zakuro
|
@@ -200,6 +200,18 @@ module Zakuro
|
|
200
200
|
|
201
201
|
condition.call(first_date, second_date)
|
202
202
|
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# ディープコピー
|
206
|
+
#
|
207
|
+
# @param [MultiGengou] obj 自身
|
208
|
+
#
|
209
|
+
def initialize_copy(obj)
|
210
|
+
@oldest_date = obj.oldest_date.clone
|
211
|
+
@current_date = obj.current_date.clone
|
212
|
+
@newest_date = obj.newest_date.clone
|
213
|
+
@multi_gengou = obj.multi_gengou.clone
|
214
|
+
end
|
203
215
|
end
|
204
216
|
end
|
205
217
|
end
|
@@ -61,6 +61,16 @@ module Zakuro
|
|
61
61
|
def invalid?
|
62
62
|
(@index == -1 || @remainder.invalid?)
|
63
63
|
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# データなしかを検証する
|
67
|
+
#
|
68
|
+
# @return [True] データなし
|
69
|
+
# @return [False] データあり
|
70
|
+
#
|
71
|
+
def empty?
|
72
|
+
(@index == -1 && @remainder.invalid?)
|
73
|
+
end
|
64
74
|
end
|
65
75
|
end
|
66
76
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../era/western'
|
4
|
+
|
5
|
+
# TODO: moduleでMonthly とする(全暦むけに共通化したあと)
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Senmyou
|
11
|
+
#
|
12
|
+
# FirstDay 月初日(朔日)
|
13
|
+
#
|
14
|
+
class FirstDay
|
15
|
+
# @return [Western::Calendar] 西暦日
|
16
|
+
attr_reader :western_date
|
17
|
+
# @return [Remainder] 大余小余
|
18
|
+
attr_reader :remainder
|
19
|
+
|
20
|
+
#
|
21
|
+
# 初期化
|
22
|
+
#
|
23
|
+
# @param [Remainder] remainder 西暦日
|
24
|
+
# @param [Western::Calendar] western_date 大余小余
|
25
|
+
#
|
26
|
+
def initialize(western_date: Western::Calendar.new, remainder: Remainder.new)
|
27
|
+
# 西暦日
|
28
|
+
@western_date = western_date
|
29
|
+
# 大余小余
|
30
|
+
@remainder = remainder
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# ディープコピー
|
35
|
+
#
|
36
|
+
# @param [FirstDay] obj 自身
|
37
|
+
#
|
38
|
+
def initialize_copy(obj)
|
39
|
+
@western_date = obj.western_date.clone
|
40
|
+
@remainder = obj.remainder.clone
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './month'
|
4
|
+
|
5
|
+
# TODO: moduleでMonthly とする(全暦むけに共通化したあと)
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Senmyou
|
11
|
+
#
|
12
|
+
# InitializedMonth 初期月情報
|
13
|
+
#
|
14
|
+
class InitializedMonth < Month
|
15
|
+
# @return [True] 昨年の月
|
16
|
+
# @return [False] 今年の月
|
17
|
+
# @note 冬至基準で1年データを作成するため昨年の11月-12月である可能性がある
|
18
|
+
attr_reader :is_last_year
|
19
|
+
# @return [Integer] 月齢(朔月、上弦、望月、下弦)
|
20
|
+
attr_reader :phase_index
|
21
|
+
|
22
|
+
# :reek:ControlParameter and :reek:BooleanParameter
|
23
|
+
|
24
|
+
#
|
25
|
+
# 初期化
|
26
|
+
#
|
27
|
+
# @param [MonthLabel] month_label 月表示名
|
28
|
+
# @param [Array<SolarTerm>] solar_terms 二十四節気
|
29
|
+
# @param [FirstDay] first_day 月初日(朔日)
|
30
|
+
# @param [True, False] is_last_year 昨年の月/今年の月
|
31
|
+
# @param [Integer] phase_index 月齢(朔月、上弦、望月、下弦)
|
32
|
+
#
|
33
|
+
def initialize(month_label: MonthLabel.new, solar_terms: [], first_day: FirstDay.new,
|
34
|
+
is_last_year: false, phase_index: -1)
|
35
|
+
super(month_label: month_label, solar_terms: solar_terms, first_day: first_day)
|
36
|
+
@is_last_year = is_last_year
|
37
|
+
@phase_index = phase_index
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# 一ヶ月戻す
|
42
|
+
#
|
43
|
+
def back_to_last_month
|
44
|
+
@is_last_year = true if month_label.back_to_last_month
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './first_day'
|
4
|
+
require_relative './month_label'
|
5
|
+
|
6
|
+
# TODO: moduleでMonthly とする(全暦むけに共通化したあと)
|
7
|
+
|
3
8
|
# :nodoc:
|
4
9
|
module Zakuro
|
5
10
|
# :nodoc:
|
@@ -8,63 +13,62 @@ module Zakuro
|
|
8
13
|
# Month 月情報
|
9
14
|
#
|
10
15
|
class Month
|
11
|
-
# @return [
|
12
|
-
|
13
|
-
# @
|
14
|
-
|
15
|
-
# @return [
|
16
|
-
|
17
|
-
attr_accessor :is_many_days
|
18
|
-
# @return [Integer] 月(xx月のxx)
|
19
|
-
attr_accessor :number
|
20
|
-
# @return [True] 閏月
|
21
|
-
# @return [False] 平月
|
22
|
-
attr_accessor :leaped
|
23
|
-
# @return [SolarTerm] 二十四節気(中気)
|
24
|
-
attr_accessor :even_term
|
25
|
-
# @return [SolarTerm] 二十四節気(節気)
|
26
|
-
attr_accessor :odd_term
|
27
|
-
# @return [Remainder] 月初日の大余小余
|
28
|
-
attr_reader :remainder
|
29
|
-
# @return [String] 月齢(朔月、上弦、望月、下弦)
|
30
|
-
attr_reader :phase_index
|
31
|
-
|
32
|
-
# rubocop:disable Metrics/ParameterLists
|
33
|
-
# :reek:BooleanParametere
|
16
|
+
# @return [MonthLabel] 月表示名
|
17
|
+
attr_reader :month_label
|
18
|
+
# @return [FirstDay] 月初日(朔日)
|
19
|
+
attr_reader :first_day
|
20
|
+
# @return [Array<SolarTerm>] 二十四節気
|
21
|
+
attr_reader :solar_terms
|
34
22
|
|
35
23
|
#
|
36
24
|
# 初期化
|
37
25
|
#
|
38
|
-
# @param [
|
39
|
-
# @param [
|
40
|
-
# @param [
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@
|
64
|
-
|
65
|
-
|
26
|
+
# @param [MonthLabel] month_label 月表示名
|
27
|
+
# @param [FirstDay] first_day 月初日(朔日)
|
28
|
+
# @param [Array<SolarTerm>] solar_terms 二十四節気
|
29
|
+
#
|
30
|
+
def initialize(month_label: MonthLabel.new, first_day: FirstDay.new, solar_terms: [])
|
31
|
+
@month_label = month_label
|
32
|
+
@first_day = first_day
|
33
|
+
@solar_terms = solar_terms
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# 中気なしは閏月とする
|
38
|
+
#
|
39
|
+
def eval_leaped
|
40
|
+
leaped = even_term.invalid?
|
41
|
+
|
42
|
+
@month_label = MonthLabel.new(number: number, is_many_days: many_days?, leaped: leaped)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# 月初日の西暦日を返す
|
47
|
+
#
|
48
|
+
# @return [Western::Calendar] 西暦日
|
49
|
+
#
|
50
|
+
def western_date
|
51
|
+
@first_day.western_date
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# 月初日の大余小余を返す
|
56
|
+
#
|
57
|
+
# @return [Remainder] 大余小余
|
58
|
+
#
|
59
|
+
def remainder
|
60
|
+
@first_day.remainder
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# 月の大小を返す
|
65
|
+
#
|
66
|
+
# @return [True] 大の月(30日)
|
67
|
+
# @return [False] 小の月(29日)
|
68
|
+
#
|
69
|
+
def many_days?
|
70
|
+
@month_label.is_many_days
|
66
71
|
end
|
67
|
-
# rubocop:enable Metrics/ParameterLists
|
68
72
|
|
69
73
|
#
|
70
74
|
# 月の日数を返す
|
@@ -72,7 +76,7 @@ module Zakuro
|
|
72
76
|
# @return [Integer] 日数
|
73
77
|
#
|
74
78
|
def days
|
75
|
-
@
|
79
|
+
@month_label.days
|
76
80
|
end
|
77
81
|
|
78
82
|
#
|
@@ -81,19 +85,39 @@ module Zakuro
|
|
81
85
|
# @return [String] 月の名前(大小)
|
82
86
|
#
|
83
87
|
def days_name
|
84
|
-
@
|
88
|
+
@month_label.days_name
|
85
89
|
end
|
86
90
|
|
87
91
|
#
|
88
|
-
#
|
92
|
+
# 月を返す
|
89
93
|
#
|
90
|
-
# @
|
94
|
+
# @return [Integer] 月(xx月のxx)
|
91
95
|
#
|
92
|
-
|
93
|
-
|
96
|
+
def number
|
97
|
+
@month_label.number
|
98
|
+
end
|
99
|
+
|
94
100
|
#
|
95
|
-
|
96
|
-
|
101
|
+
# 閏を返す
|
102
|
+
#
|
103
|
+
# @return [True] 閏月
|
104
|
+
# @return [False] 平月
|
105
|
+
#
|
106
|
+
def leaped?
|
107
|
+
@month_label.leaped
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# 次月の大余から月の日数を定める
|
112
|
+
#
|
113
|
+
# @param [Integer] next_month_day 次月の大余
|
114
|
+
#
|
115
|
+
def eval_many_days(next_month_day:)
|
116
|
+
is_many_days = remainder.same_remainder_divided_by_ten?(other: next_month_day)
|
117
|
+
|
118
|
+
@month_label = MonthLabel.new(
|
119
|
+
number: number, is_many_days: is_many_days, leaped: leaped?
|
120
|
+
)
|
97
121
|
end
|
98
122
|
|
99
123
|
#
|
@@ -103,19 +127,54 @@ module Zakuro
|
|
103
127
|
# @return [False] 設定あり
|
104
128
|
#
|
105
129
|
def empty_solar_term?
|
106
|
-
@
|
130
|
+
@solar_terms.empty?
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# 中気を返す
|
135
|
+
#
|
136
|
+
# @return [SolarTerm] 中気
|
137
|
+
#
|
138
|
+
def even_term
|
139
|
+
@solar_terms.each do |term|
|
140
|
+
return term if term.index.even?
|
141
|
+
end
|
142
|
+
|
143
|
+
SolarTerm.new
|
144
|
+
end
|
145
|
+
|
146
|
+
#
|
147
|
+
# 節気を返す
|
148
|
+
#
|
149
|
+
# @return [SolarTerm] 節気
|
150
|
+
#
|
151
|
+
def odd_term
|
152
|
+
@solar_terms.each do |term|
|
153
|
+
return term if term.index.odd?
|
154
|
+
end
|
155
|
+
|
156
|
+
SolarTerm.new
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# 二十四節気を追加する
|
161
|
+
#
|
162
|
+
# @param [SolarTerm] term 二十四節気
|
163
|
+
#
|
164
|
+
def add_term(term:)
|
165
|
+
@solar_terms.push(term)
|
107
166
|
end
|
108
167
|
|
109
168
|
#
|
110
|
-
#
|
169
|
+
# 同一の月情報かを検証する
|
111
170
|
#
|
112
|
-
# @
|
171
|
+
# @param [Month] other 他の月情報
|
113
172
|
#
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
173
|
+
# @return [True] 同一の月
|
174
|
+
# @return [False] 異なる月
|
175
|
+
#
|
176
|
+
def same?(other:)
|
177
|
+
number == other.number && leaped? == other.leaped?
|
119
178
|
end
|
120
179
|
end
|
121
180
|
end
|