zakuro 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +85 -43
  3. data/doc/operation.md +25 -0
  4. data/doc/operation/csv/month.csv +202 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/doc/operation/transfer.rb +73 -0
  7. data/lib/zakuro/era/japan/gengou.rb +106 -0
  8. data/lib/zakuro/era/japan/gengou/parser.rb +169 -0
  9. data/lib/zakuro/era/japan/gengou/type.rb +178 -0
  10. data/lib/zakuro/era/japan/gengou/validator.rb +234 -0
  11. data/lib/zakuro/era/japan/reki.rb +91 -0
  12. data/lib/zakuro/era/{gengou → japan/yaml}/set-001-until-south.yaml +0 -0
  13. data/lib/zakuro/era/{gengou → japan/yaml}/set-002-from-north.yaml +0 -0
  14. data/lib/zakuro/era/{gengou → japan/yaml}/set-003-modern.yaml +0 -0
  15. data/lib/zakuro/era/western.rb +1 -1
  16. data/lib/zakuro/operation/month/parser.rb +277 -0
  17. data/lib/zakuro/operation/month/type.rb +452 -0
  18. data/lib/zakuro/operation/month/validator.rb +498 -0
  19. data/lib/zakuro/operation/operation.rb +45 -0
  20. data/lib/zakuro/operation/yaml/month.yaml +6452 -0
  21. data/lib/zakuro/output/error.rb +2 -0
  22. data/lib/zakuro/output/logger.rb +2 -0
  23. data/lib/zakuro/output/response.rb +17 -15
  24. data/lib/zakuro/result/core.rb +52 -0
  25. data/lib/zakuro/result/data.rb +187 -0
  26. data/lib/zakuro/result/operation.rb +86 -0
  27. data/lib/zakuro/result/result.rb +37 -0
  28. data/lib/zakuro/{output → tools}/stringifier.rb +14 -7
  29. data/lib/zakuro/tools/typeof.rb +33 -0
  30. data/lib/zakuro/version.rb +1 -1
  31. data/lib/zakuro/version/senmyou/base/era.rb +1 -1
  32. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +1 -1
  33. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +13 -1
  34. data/lib/zakuro/version/senmyou/base/solar_term.rb +10 -0
  35. data/lib/zakuro/version/senmyou/monthly/first_day.rb +44 -0
  36. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +48 -0
  37. data/lib/zakuro/version/senmyou/monthly/month.rb +127 -68
  38. data/lib/zakuro/version/senmyou/monthly/month_label.rb +87 -0
  39. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +167 -0
  40. data/lib/zakuro/version/senmyou/{summary → range}/annual_range.rb +20 -23
  41. data/lib/zakuro/version/senmyou/{summary → range}/full_range.rb +102 -2
  42. data/lib/zakuro/version/senmyou/range/operated_range.rb +105 -0
  43. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +163 -0
  44. data/lib/zakuro/version/senmyou/senmyou.rb +2 -2
  45. data/lib/zakuro/version/senmyou/{summary/specifier.rb → specifier/single_day_specifier.rb} +13 -14
  46. data/lib/zakuro/version/senmyou/stella/solar_average.rb +3 -7
  47. data/lib/zakuro/version/senmyou/summary/single.rb +71 -0
  48. data/lib/zakuro/version_factory.rb +1 -1
  49. metadata +35 -11
  50. data/lib/zakuro/era/japan.rb +0 -664
  51. data/lib/zakuro/output/result.rb +0 -225
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # TODO: outputモジュール内にする
4
+
3
5
  # :nodoc:
4
6
  module Zakuro
5
7
  #
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # TODO: outputモジュール内にする
4
+
3
5
  # :nodoc:
4
6
  module Zakuro
5
7
  #
@@ -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)
@@ -71,11 +73,11 @@ module Zakuro
71
73
  multi_gengou = year.multi_gengou
72
74
  first = multi_gengou.first_line
73
75
  second = multi_gengou.second_line
74
- Result::Year.new(
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),
80
+ Result::Data::Gengou.new(name: second.name, number: second.year),
79
81
  zodiac_name: year.zodiac_name, total_days: year.total_days
80
82
  )
81
83
  end
@@ -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, days_name: month.days_name,
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.format,
119
- western_date: western_date.format
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.format
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.format,
164
- western_date: date.format
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,86 @@
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] 月別履歴情報
21
+ attr_reader :month
22
+ # @return [Data::SingleDay] 計算値
23
+ attr_reader :original
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [True, False] operated 運用有無
29
+ # @param [Month] 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
+ class Month
43
+ # @return [Integer] 原文頁数
44
+ attr_reader :page
45
+ # @return [Integer] 原文注釈番号
46
+ attr_reader :number
47
+ # @return [Array<Zakuro::Result::Operation::Annotation>] 注釈
48
+ attr_reader :annotations
49
+
50
+ #
51
+ # 初期化
52
+ #
53
+ # @param [Integer] page 原文頁数
54
+ # @param [Integer] number 原文注釈番号
55
+ # @param [Array<Zakuro::Result::Operation::Annotation>] annotations 注釈
56
+ #
57
+ def initialize(page: -1, number: -1, annotations: [])
58
+ @page = page
59
+ @number = number
60
+ @annotations = annotations
61
+ end
62
+ end
63
+
64
+ #
65
+ # Annotation 注釈
66
+ #
67
+ class Annotation
68
+ # @return [String] 注釈内容
69
+ attr_reader :description
70
+ # @return [String] 注釈補記
71
+ attr_reader :note
72
+
73
+ #
74
+ # 初期化
75
+ #
76
+ # @param [String] description 注釈内容
77
+ # @param [<Type>] note 注釈補記
78
+ #
79
+ def initialize(description:, note:)
80
+ @description = description
81
+ @note = note
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ require_relative './core'
6
+ require_relative './data'
7
+ require_relative './operation'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ #
12
+ # Result 演算結果
13
+ #
14
+ module Result
15
+ #
16
+ # Single 1日検索結果
17
+ #
18
+ class Single < Core
19
+ # @return [Data::SingleDay] 1日
20
+ attr_reader :data
21
+ # @return [Operation::Bundle] 運用情報
22
+ attr_reader :operation
23
+
24
+ #
25
+ # 初期化
26
+ #
27
+ # @param [Data::SingleDay] data 1日
28
+ # @param [Operation::Bundle] operation 運用情報
29
+ #
30
+ def initialize(data:, operation:)
31
+ super
32
+ @data = data
33
+ @operation = operation
34
+ end
35
+ end
36
+ end
37
+ end