zakuro 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +46 -17
  4. data/VERSION +1 -1
  5. data/doc/dropped_date.md +93 -0
  6. data/doc/error.md +45 -0
  7. data/doc/operation/transfer.rb +8 -8
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +49 -3
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  11. data/lib/zakuro/calculation/base/operated_year.rb +26 -24
  12. data/lib/zakuro/calculation/base/year.rb +7 -7
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
  14. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  15. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  16. data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +44 -37
  17. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  19. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  20. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +50 -64
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +156 -0
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  27. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +73 -0
  28. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
  29. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  30. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  31. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  32. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  33. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  34. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  35. data/lib/zakuro/calculation/monthly/month.rb +55 -16
  36. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  37. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  38. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  39. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  40. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  41. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +45 -29
  42. data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
  43. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  44. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  45. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  46. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  47. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  48. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  49. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  50. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  51. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  52. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  53. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  54. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  55. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  56. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  57. data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +33 -12
  58. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  59. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  60. data/lib/zakuro/calculation/summary/japan/range.rb +179 -0
  61. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  62. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
  63. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  64. data/lib/zakuro/calculation/summary/western/range.rb +127 -0
  65. data/lib/zakuro/calculation/summary/western/single.rb +115 -0
  66. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
  67. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
  68. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  69. data/lib/zakuro/calculation/type/optional.rb +46 -0
  70. data/lib/zakuro/condition.rb +143 -94
  71. data/lib/zakuro/context/context.rb +44 -0
  72. data/lib/zakuro/context/option.rb +119 -0
  73. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  74. data/lib/zakuro/era/japan/calendar.rb +35 -33
  75. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +93 -74
  76. data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
  77. data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
  78. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
  79. data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
  80. data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
  81. data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
  82. data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
  83. data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
  84. data/lib/zakuro/era/japan/gengou.rb +28 -41
  85. data/lib/zakuro/era/japan/version.rb +18 -16
  86. data/lib/zakuro/era/western/calendar.rb +104 -88
  87. data/lib/zakuro/exception/case/pattern.rb +71 -0
  88. data/lib/zakuro/exception/case/preset.rb +51 -0
  89. data/lib/zakuro/exception/case/template.rb +48 -0
  90. data/lib/zakuro/exception/cause.rb +28 -0
  91. data/lib/zakuro/exception/exception.rb +39 -0
  92. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  93. data/lib/zakuro/gateway/locale/date.rb +127 -0
  94. data/lib/zakuro/gateway/locale/range.rb +67 -0
  95. data/lib/zakuro/gateway/range.rb +99 -0
  96. data/lib/zakuro/gateway/single.rb +81 -0
  97. data/lib/zakuro/merchant.rb +67 -33
  98. data/lib/zakuro/operation/month/parser.rb +252 -249
  99. data/lib/zakuro/operation/month/type.rb +44 -35
  100. data/lib/zakuro/operation/month/validator.rb +182 -178
  101. data/lib/zakuro/operation/operation.rb +38 -36
  102. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  103. data/lib/zakuro/output/logger.rb +17 -3
  104. data/lib/zakuro/output/response.rb +107 -141
  105. data/lib/zakuro/result/data/day.rb +43 -0
  106. data/lib/zakuro/result/data/gengou.rb +35 -0
  107. data/lib/zakuro/result/data/month.rb +63 -0
  108. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  109. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  110. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  111. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  112. data/lib/zakuro/result/data/single_day.rb +56 -0
  113. data/lib/zakuro/result/data/solar_term.rb +35 -0
  114. data/lib/zakuro/result/data/year.rb +45 -0
  115. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  116. data/lib/zakuro/result/operation/month/history.rb +54 -0
  117. data/lib/zakuro/result/operation/month.rb +31 -0
  118. data/lib/zakuro/result/operation.rb +22 -97
  119. data/lib/zakuro/result/result.rb +6 -4
  120. data/lib/zakuro/tools/stringifier.rb +67 -42
  121. data/lib/zakuro/tools/typeconv.rb +17 -15
  122. data/lib/zakuro/tools/typeof.rb +15 -13
  123. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  124. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  125. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  126. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  127. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  128. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  129. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  130. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  131. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  132. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  133. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  134. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  135. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  136. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  137. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  138. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  139. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  140. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  141. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  142. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  143. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  144. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  145. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  146. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  147. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  148. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  149. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  150. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  151. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  152. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  153. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  154. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  155. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  156. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  157. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  158. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  159. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  160. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  161. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  162. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  163. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  164. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  165. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  166. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  167. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  168. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  169. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  170. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  171. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  172. metadata +68 -16
  173. data/lib/zakuro/calculation/range/operated_range.rb +0 -193
  174. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
  175. data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
  176. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  177. data/lib/zakuro/calculation/summary/range.rb +0 -120
  178. data/lib/zakuro/calculation/summary/single.rb +0 -110
  179. data/lib/zakuro/result/data.rb +0 -187
  180. data/lib/zakuro/version/context.rb +0 -44
  181. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ #
6
+ # Result 演算結果
7
+ #
8
+ module Result
9
+ #
10
+ # データ部
11
+ #
12
+ module Data
13
+ #
14
+ # SolarTerm 二十四節気
15
+ #
16
+ class SolarTerm
17
+ # @return [Integer] 連番
18
+ attr_reader :index
19
+ # @return [String] 大余小余
20
+ attr_reader :remainder
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Integer] index 連番
26
+ # @param [String] remainder 大余小余
27
+ #
28
+ def initialize(index:, remainder:)
29
+ @index = index
30
+ @remainder = remainder
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './gengou'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Result 演算結果
9
+ #
10
+ module Result
11
+ #
12
+ # データ部
13
+ #
14
+ module Data
15
+ #
16
+ # Year 年
17
+ #
18
+ class Year
19
+ # @return [Gengou] 元号(1行目)
20
+ attr_reader :first_gengou
21
+ # @return [Gengou] 元号(2行目)
22
+ attr_reader :second_gengou
23
+ # @return [String] 十干十二支
24
+ attr_reader :zodiac_name
25
+ # @return [Integer] 日数
26
+ attr_reader :total_days
27
+
28
+ #
29
+ # 初期化
30
+ #
31
+ # @param [Gengou] first_gengou 元号(1行目)
32
+ # @param [Gengou] second_gengou 元号(2行目)
33
+ # @param [String] zodiac_name 十干十二支
34
+ # @param [Integer] total_days 日数
35
+ #
36
+ def initialize(first_gengou:, second_gengou:, zodiac_name:, total_days:)
37
+ @first_gengou = first_gengou
38
+ @second_gengou = second_gengou
39
+ @zodiac_name = zodiac_name
40
+ @total_days = total_days
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ #
6
+ # Result 演算結果
7
+ #
8
+ module Result
9
+ #
10
+ # 運用情報
11
+ #
12
+ class Operation
13
+ #
14
+ # Month 運用情報(月)
15
+ #
16
+ class Month
17
+ #
18
+ # Annotation 注釈
19
+ #
20
+ class Annotation
21
+ # @return [String] 注釈内容
22
+ attr_reader :description
23
+ # @return [String] 注釈補記
24
+ attr_reader :note
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [String] description 注釈内容
30
+ # @param [<Type>] note 注釈補記
31
+ #
32
+ def initialize(description:, note:)
33
+ @description = description
34
+ @note = note
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './annotation'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Result 演算結果
9
+ #
10
+ module Result
11
+ #
12
+ # 運用情報
13
+ #
14
+ class Operation
15
+ #
16
+ # Month 運用情報(月)
17
+ #
18
+ class Month
19
+ #
20
+ # History 月別履歴情報
21
+ #
22
+ class History
23
+ # @return [String] ID
24
+ attr_reader :id
25
+ # @return [String] 月初日の西暦日
26
+ attr_reader :western_date
27
+ # @return [Integer] 原文頁数
28
+ attr_reader :page
29
+ # @return [Integer] 原文注釈番号
30
+ attr_reader :number
31
+ # @return [Array<Annotation>] 注釈
32
+ attr_reader :annotations
33
+
34
+ #
35
+ # 初期化
36
+ #
37
+ # @param [String] id ID
38
+ # @param [String] western_date 月初日の西暦日
39
+ # @param [Integer] page 原文頁数
40
+ # @param [Integer] number 原文注釈番号
41
+ # @param [Array<Annotation>] annotations 注釈
42
+ #
43
+ def initialize(id: '', western_date: '', page: -1, number: -1, annotations: [])
44
+ @id = id
45
+ @western_date = western_date
46
+ @page = page
47
+ @number = number
48
+ @annotations = annotations
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './month/history'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Result 演算結果
9
+ #
10
+ module Result
11
+ #
12
+ # 運用情報
13
+ #
14
+ class Operation
15
+ #
16
+ # Month 運用情報(月)
17
+ #
18
+ class Month
19
+ # @return [History] 月別履歴情報(当月)
20
+ attr_reader :current
21
+ # @return [History] 月別履歴情報(影響を与えた月)
22
+ attr_reader :parent
23
+
24
+ def initialize(current: History.new, parent: History.new)
25
+ @current = current
26
+ @parent = parent
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './data/single_day'
4
+
5
+ require_relative './operation/month'
6
+
3
7
  # :nodoc:
4
8
  module Zakuro
5
9
  #
@@ -7,107 +11,28 @@ module Zakuro
7
11
  #
8
12
  module Result
9
13
  #
10
- # 運用情報
14
+ # Operation 運用情報
11
15
  #
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
16
+ class Operation
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
38
24
 
39
25
  #
40
- # Month 運用情報(月)
26
+ # 初期化
41
27
  #
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
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
111
36
  end
112
37
  end
113
38
  end
@@ -2,10 +2,12 @@
2
2
 
3
3
  require 'json'
4
4
 
5
- require_relative './core'
6
- require_relative './data'
5
+ require_relative './data/single_day'
6
+
7
7
  require_relative './operation'
8
8
 
9
+ require_relative './core'
10
+
9
11
  # :nodoc:
10
12
  module Zakuro
11
13
  #
@@ -18,14 +20,14 @@ module Zakuro
18
20
  class Single < Core
19
21
  # @return [Data::SingleDay] 1日
20
22
  attr_reader :data
21
- # @return [Operation::Bundle] 運用情報
23
+ # @return [Operation] 運用情報
22
24
  attr_reader :operation
23
25
 
24
26
  #
25
27
  # 初期化
26
28
  #
27
29
  # @param [Data::SingleDay] data 1日
28
- # @param [Operation::Bundle] operation 運用情報
30
+ # @param [Operation] operation 運用情報
29
31
  #
30
32
  def initialize(data:, operation:)
31
33
  super
@@ -12,58 +12,83 @@ module Zakuro
12
12
  # Stringifier 文字列処理
13
13
  #
14
14
  module Stringifier
15
- #
16
- # 対象インスタンスをハッシュ化する
17
- #
18
- # @param [Object] obj 対象インスタンス
19
- # @param [String] class_prefix インスタンス内でハッシュ変換するクラスのプレフィックス
20
- #
21
- # @return [Hash<String, Objcet>] ハッシュ
22
- #
23
- def self.to_h(obj:, class_prefix:, formatted: true)
24
- hash = {}
25
- obj.instance_variables.each do |var|
26
- key = var.to_s.delete('@')
27
- hash[key] = value_to_hash(
28
- obj: obj.instance_variable_get(var), class_prefix: class_prefix, formatted: formatted
29
- )
15
+ class << self
16
+ #
17
+ # 対象インスタンスをハッシュ化する
18
+ #
19
+ # @param [Object] obj 対象インスタンス
20
+ # @param [String] class_prefix インスタンス内でハッシュ変換するクラスのプレフィックス
21
+ # @param [True, False] formatted 整形有無
22
+ #
23
+ # @return [Hash<String, Objcet>] ハッシュ
24
+ #
25
+ def to_h(obj:, class_prefix:, formatted: true)
26
+ hash = {}
27
+ obj.instance_variables.each do |var|
28
+ key = var.to_s.delete('@')
29
+ hash[key] = value_to_hash(
30
+ obj: obj.instance_variable_get(var), class_prefix: class_prefix, formatted: formatted
31
+ )
32
+ end
33
+ hash
30
34
  end
31
- hash
32
- end
33
35
 
34
- # :reek:TooManyStatements { max_statements: 7 }
36
+ private
35
37
 
36
- #
37
- # 対象インスタンスをハッシュ化する(再帰処理)
38
- #
39
- # @param [Object] obj 対象インスタンス
40
- # @param [String] class_prefix インスタンス内でハッシュ変換するクラスのプレフィックス
41
- #
42
- # @return [Hash<String, Objcet>] ハッシュ
43
- #
44
- def self.value_to_hash(obj:, class_prefix:, formatted:)
45
- return obj unless obj
38
+ #
39
+ # 対象インスタンスをハッシュ化する(再帰処理)
40
+ #
41
+ # @param [Object] obj 対象インスタンス
42
+ # @param [String] class_prefix インスタンス内でハッシュ変換するクラスのプレフィックス
43
+ # @param [True, False] formatted 整形有無
44
+ #
45
+ # @return [Hash<String, Objcet>] ハッシュ
46
+ #
47
+ def value_to_hash(obj:, class_prefix:, formatted:)
48
+ return obj unless obj
46
49
 
47
- # 日付をフォーマットする
48
- return obj.format if formatted && Tools::Typeof.time?(obj: obj)
50
+ # 日付をフォーマットする
51
+ return obj.format if formatted && Tools::Typeof.time?(obj: obj)
52
+
53
+ # 同じモジュール内のオブジェクトは再帰する
54
+ if obj.class.name.start_with?(class_prefix)
55
+ return to_h(obj: obj, class_prefix: class_prefix, formatted: formatted)
56
+ end
49
57
 
50
- # 同じモジュール内のオブジェクトは再帰する
51
- if obj.class.name.start_with?(class_prefix)
52
- return to_h(obj: obj, class_prefix: class_prefix, formatted: formatted)
58
+ general_value_to_hash(obj: obj, class_prefix: class_prefix, formatted: formatted)
53
59
  end
54
60
 
55
- # 配列は要素一つずつで再帰する
56
- if obj.is_a?(Array)
57
- arr = []
58
- obj.each do |item|
59
- arr.push(to_h(obj: item, class_prefix: class_prefix, formatted: formatted))
61
+ #
62
+ # ライブラリを問わない標準的な値をハッシュ化する(再帰処理)
63
+ #
64
+ # @param [Object] obj 対象インスタンス
65
+ # @param [String] class_prefix インスタンス内でハッシュ変換するクラスのプレフィックス
66
+ # @param [True, False] formatted 整形有無
67
+ #
68
+ # @return [Objcet] ハッシュ変換可能な値
69
+ #
70
+ def general_value_to_hash(obj:, class_prefix:, formatted:)
71
+ # 配列は要素一つずつで再帰する
72
+ if obj.is_a?(Array)
73
+ arr = []
74
+ obj.each do |item|
75
+ arr.push(to_h(obj: item, class_prefix: class_prefix, formatted: formatted))
76
+ end
77
+ return arr
78
+ end
79
+
80
+ # ハッシュはキーごとに再帰する
81
+ if obj.is_a?(Hash)
82
+ hash = {}
83
+ obj.each do |key, value|
84
+ hash[key] = to_h(obj: value, class_prefix: class_prefix, formatted: formatted)
85
+ end
86
+ return hash
60
87
  end
61
- return arr
62
- end
63
88
 
64
- obj
89
+ obj
90
+ end
65
91
  end
66
- private_class_method :value_to_hash
67
92
  end
68
93
  end
69
94
  end
@@ -16,22 +16,24 @@ module Zakuro
16
16
  module Typeconv
17
17
  LOGGER = Output::Logger.new(location: 'Typeconv')
18
18
 
19
- #
20
- # 文字列を10進数で数値化する
21
- #
22
- # @param [String] text 対象文字列
23
- # @param [Integer] default デフォルト数値
24
- #
25
- # @return [Integer] 数値
26
- #
27
- def self.to_i(text:, default:)
28
- begin
29
- return Integer(text, 10)
30
- rescue StandardError => e
31
- LOGGER.debug(e)
32
- end
19
+ class << self
20
+ #
21
+ # 文字列を10進数で数値化する
22
+ #
23
+ # @param [String] text 対象文字列
24
+ # @param [Integer] default デフォルト数値
25
+ #
26
+ # @return [Integer] 数値
27
+ #
28
+ def to_i(text:, default:)
29
+ begin
30
+ return Integer(text, 10)
31
+ rescue StandardError => e
32
+ LOGGER.debug(e)
33
+ end
33
34
 
34
- default
35
+ default
36
+ end
35
37
  end
36
38
  end
37
39
  end
@@ -14,22 +14,24 @@ module Zakuro
14
14
  # Typeof 型判定
15
15
  #
16
16
  module Typeof
17
- #
18
- # 時間を表す型か
19
- #
20
- # @param [Object] obj 引数
21
- #
22
- # @return [True] 時間型である
23
- # @return [False] 時間型ではない
24
- #
25
- def self.time?(obj:)
26
- return true if obj.is_a?(Japan::Calendar)
17
+ class << self
18
+ #
19
+ # 時間を表す型か
20
+ #
21
+ # @param [Object] obj 引数
22
+ #
23
+ # @return [True] 時間型である
24
+ # @return [False] 時間型ではない
25
+ #
26
+ def time?(obj:)
27
+ return true if obj.is_a?(Japan::Calendar)
27
28
 
28
- return true if obj.is_a?(Western::Calendar)
29
+ return true if obj.is_a?(Western::Calendar)
29
30
 
30
- return true if obj.is_a?(Calculation::Cycle::AbstractRemainder)
31
+ return true if obj.is_a?(Calculation::Cycle::AbstractRemainder)
31
32
 
32
- false
33
+ false
34
+ end
33
35
  end
34
36
  end
35
37
  end
@@ -29,7 +29,7 @@ module Zakuro
29
29
  # @param [Integer] total 繰り上げなしの小余
30
30
  #
31
31
  def initialize(day: -1, minute: -1, second: -1, total: -1)
32
- super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
32
+ super(base_day: Const::Number::Cycle::DAY, base_minute: MINUTE,
33
33
  day: day, minute: minute, second: second, total: total)
34
34
  end
35
35
 
@@ -63,7 +63,7 @@ module Zakuro
63
63
  # @param [Integer] total 繰り上げなしの小余
64
64
  #
65
65
  def initialize(day: -1, minute: -1, second: -1, total: -1)
66
- super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
66
+ super(base_day: Const::Number::Cycle::DAY, base_minute: MINUTE,
67
67
  day: day, minute: minute, second: second, total: total)
68
68
  end
69
69
 
@@ -35,7 +35,7 @@ module Zakuro
35
35
  lunar_age = Origin::LunarAge.get(western_year: western_year)
36
36
 
37
37
  super(
38
- quater: QUARTER,
38
+ quarter: QUARTER,
39
39
  average_remainder: Origin::AverageNovember.get(western_year: western_year),
40
40
  solar_location: Solar::Location.new(lunar_age: lunar_age),
41
41
  lunar_location: Lunar::Location.new(
@@ -55,13 +55,13 @@ module Zakuro
55
55
  # @return [Remainder] 定朔
56
56
  #
57
57
  def current_remainder
58
- # debug("@average_remainder.format: #{@average_remainder.format(form: '%d-%d-%.5f')}")
58
+ # debug("average_remainder.format: #{average_remainder.format(form: '%d-%d-%.5f')}")
59
59
 
60
60
  sum = correction_value
61
- adjusted = @average_remainder.add(
61
+ adjusted = average_remainder.add(
62
62
  Cycle::Remainder.new(day: 0, minute: sum, second: 0)
63
63
  )
64
- # TODO: 大衍暦では進朔するか
64
+ # NOTE: 大衍暦では進朔しない
65
65
  # adjusted.up_on_new_moon!
66
66
 
67
67
  debug("result: #{adjusted.format}")
@@ -75,24 +75,22 @@ module Zakuro
75
75
  # @return [Integer] 太陽運動の補正値
76
76
  #
77
77
  def correction_solar_value
78
- @solar_location.run
79
- # debug("@solar_term.remainder: #{@solar_location.remainder.format(form: '%d-%d-%.5f')}")
80
- # debug("@solar_term.index: #{@solar_location.index}")
78
+ solar_location.run
79
+ # debug("solar_term.remainder: #{solar_location.remainder.format(form: '%d-%d-%.5f')}")
80
+ # debug("solar_term.index: #{solar_location.index}")
81
81
 
82
- Solar::Value.get(solar_location: @solar_location)
82
+ Solar::Value.get(solar_location: solar_location)
83
83
  end
84
84
 
85
- # :reek:TooManyStatements { max_statements: 6 }
86
-
87
85
  #
88
86
  # 月運動の補正値を得る
89
87
  #
90
88
  # @return [Integer] 月運動の補正値
91
89
  #
92
90
  def correction_moon_value
93
- @lunar_location.run
91
+ lunar_location.run
94
92
 
95
- remainder = @lunar_location.adjusted_remainder
93
+ remainder = lunar_location.adjusted_remainder
96
94
 
97
95
  # debug("[lunar]remainder.format: #{remainder.format(form: '%d-%d-%.5f')}")
98
96
  # debug("[lunar]remainder.day: #{remainder.day}")