zakuro 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/VERSION +1 -1
  4. data/lib/zakuro/calculation/base/gengou.rb +5 -5
  5. data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
  6. data/lib/zakuro/calculation/base/operated_year.rb +23 -21
  7. data/lib/zakuro/calculation/base/year.rb +3 -3
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
  9. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
  10. data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
  11. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
  12. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  13. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
  22. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  23. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  24. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  25. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  26. data/lib/zakuro/calculation/monthly/initialized_month.rb +39 -37
  27. data/lib/zakuro/calculation/monthly/month.rb +15 -15
  28. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  29. data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
  30. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  31. data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
  32. data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
  33. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  34. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  35. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  36. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  37. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  38. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  39. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  40. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +5 -5
  41. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  42. data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
  43. data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
  44. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  45. data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
  46. data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
  47. data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
  48. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
  49. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  50. data/lib/zakuro/calculation/summary/western/range.rb +95 -92
  51. data/lib/zakuro/calculation/summary/western/single.rb +78 -76
  52. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -124
  53. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
  54. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  55. data/lib/zakuro/condition.rb +121 -111
  56. data/lib/zakuro/context/context.rb +1 -1
  57. data/lib/zakuro/context/option.rb +31 -29
  58. data/lib/zakuro/context/version_class_resolver.rb +26 -24
  59. data/lib/zakuro/era/japan/calendar.rb +35 -33
  60. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -4
  61. data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
  62. data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
  63. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
  64. data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
  65. data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -36
  66. data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -37
  67. data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
  68. data/lib/zakuro/era/japan/gengou.rb +28 -26
  69. data/lib/zakuro/era/japan/version.rb +18 -16
  70. data/lib/zakuro/era/western/calendar.rb +102 -90
  71. data/lib/zakuro/exception/case/preset.rb +2 -2
  72. data/lib/zakuro/exception/exception.rb +15 -13
  73. data/lib/zakuro/exception/zakuro_error.rb +1 -1
  74. data/lib/zakuro/gateway/locale/date.rb +2 -2
  75. data/lib/zakuro/gateway/locale/range.rb +3 -3
  76. data/lib/zakuro/gateway/range.rb +1 -1
  77. data/lib/zakuro/gateway/single.rb +13 -2
  78. data/lib/zakuro/merchant.rb +1 -1
  79. data/lib/zakuro/operation/month/parser.rb +252 -251
  80. data/lib/zakuro/operation/month/type.rb +17 -8
  81. data/lib/zakuro/operation/month/validator.rb +148 -144
  82. data/lib/zakuro/operation/operation.rb +38 -36
  83. data/lib/zakuro/output/response.rb +112 -113
  84. data/lib/zakuro/result/operation/month/annotation.rb +2 -2
  85. data/lib/zakuro/result/operation/month/history.rb +2 -2
  86. data/lib/zakuro/result/operation/month.rb +31 -0
  87. data/lib/zakuro/result/operation.rb +39 -0
  88. data/lib/zakuro/result/result.rb +3 -3
  89. data/lib/zakuro/tools/stringifier.rb +66 -64
  90. data/lib/zakuro/tools/typeconv.rb +17 -15
  91. data/lib/zakuro/tools/typeof.rb +15 -13
  92. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  93. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  94. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
  95. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  96. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
  97. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  98. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  99. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  100. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  101. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  102. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  103. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  104. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  105. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  106. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  107. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  108. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  109. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  110. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  111. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
  112. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  113. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
  114. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  115. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  116. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  117. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  118. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  119. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  120. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  121. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  122. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  123. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
  124. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  125. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
  126. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  127. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  128. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  129. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  130. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  131. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  132. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  133. metadata +12 -9
  134. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
  135. data/lib/zakuro/result/operation/bundle.rb +0 -44
  136. data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -14,126 +14,125 @@ module Zakuro
14
14
  # SingleDay 1日データ
15
15
  #
16
16
  module SingleDay
17
- #
18
- # 1日データを生成する
19
- #
20
- # @param [Calculation::Base::Year] year 年情報(各暦のデータ型)
21
- # @param [Calculation::Monthly::Month] month 月情報(各暦のデータ型)
22
- # @param [Calculation::Base::Day] day 日情報
23
- # @param [Hash<String, Result::Data::Option::AbstractOption>] options オプション
24
- #
25
- # @return [Result::Data::SingleDay] 1日データ
26
- #
27
- def self.create(year:, month:, day:, options: {})
28
- Result::Data::SingleDay.new(
29
- year: save_year(year: year, month: month, day: day),
30
- month: save_month(month: month, day: day),
31
- day: save_day(day: day),
32
- options: options
33
- )
34
- end
35
-
36
- #
37
- # 年データを保存する
38
- #
39
- # @param [Calculation::Base::Year] year 年情報(各暦のデータ型)
40
- # @param [Calculation::Monthly::Month] month 月情報(各暦のデータ型)
41
- # @param [Calculation::Base::Day] day 日情報
42
- #
43
- # @return [Result::Year] 年データ
44
- #
45
- def self.save_year(year:, month:, day:)
46
- gengou = month.gengou
47
- date = day.western_date
48
- first = gengou.match_first_line(date: date)
49
- second = gengou.match_second_line(date: date)
50
- Result::Data::Year.new(
51
- first_gengou:
52
- Result::Data::Gengou.new(name: first.name, number: first.year),
53
- second_gengou:
54
- Result::Data::Gengou.new(name: second.name, number: second.year),
55
- zodiac_name: year.zodiac_name, total_days: year.total_days
56
- )
57
- end
58
- private_class_method :save_year
17
+ class << self
18
+ #
19
+ # 1日データを生成する
20
+ #
21
+ # @param [Calculation::Base::Year] year 年情報(各暦のデータ型)
22
+ # @param [Calculation::Monthly::Month] month 月情報(各暦のデータ型)
23
+ # @param [Calculation::Base::Day] day 日情報
24
+ # @param [Hash<String, Result::Data::Option::AbstractOption>] options オプション
25
+ #
26
+ # @return [Result::Data::SingleDay] 1日データ
27
+ #
28
+ def create(year:, month:, day:, options: {})
29
+ Result::Data::SingleDay.new(
30
+ year: save_year(year: year, month: month, day: day),
31
+ month: save_month(month: month, day: day),
32
+ day: save_day(day: day),
33
+ options: options
34
+ )
35
+ end
59
36
 
60
- #
61
- # 月データを保存する
62
- #
63
- # @param [Calculation::Monthly::Month] month 月情報(各暦のデータ型)
64
- # @param [Calculation::Base::Day] day 日情報
65
- #
66
- # @return [Result::Month] 月データ
67
- #
68
- def self.save_month(month:, day:)
69
- Result::Data::Month.new(
70
- number: month.number, leaped: month.leaped?, days_name: month.days_name,
71
- first_day: save_first_day(remainder: month.remainder,
72
- date: day.western_date, days: day.number - 1),
73
- odd_solar_terms: save_solar_term(term: month.odd_term),
74
- even_solar_terms: save_solar_term(term: month.even_term)
75
- )
76
- end
77
- private_class_method :save_month
37
+ private
78
38
 
79
- #
80
- # 月初日データを保存する
81
- #
82
- # @param [Cycle::AbstractRemainder] remainder 大余小余情報
83
- # @param [Western::Calendar] date 年月日情報(西暦)
84
- # @param [Integer] days 日数(月初日から指定日までの日数)
85
- #
86
- # @return [Result::Day] 日データ
87
- #
88
- def self.save_first_day(remainder:, date:, days:)
89
- western_date = date.clone - days
90
- Result::Data::Day.new(
91
- number: 1,
92
- zodiac_name: remainder.zodiac_name,
93
- remainder: remainder,
94
- western_date: western_date
95
- )
96
- end
97
- private_class_method :save_first_day
39
+ #
40
+ # 年データを保存する
41
+ #
42
+ # @param [Calculation::Base::Year] year 年情報(各暦のデータ型)
43
+ # @param [Calculation::Monthly::Month] month 月情報(各暦のデータ型)
44
+ # @param [Calculation::Base::Day] day 日情報
45
+ #
46
+ # @return [Result::Year] 年データ
47
+ #
48
+ def save_year(year:, month:, day:)
49
+ gengou = month.gengou
50
+ date = day.western_date
51
+ first = gengou.match_first_line(date: date)
52
+ second = gengou.match_second_line(date: date)
53
+ Result::Data::Year.new(
54
+ first_gengou:
55
+ Result::Data::Gengou.new(name: first.name, number: first.year),
56
+ second_gengou:
57
+ Result::Data::Gengou.new(name: second.name, number: second.year),
58
+ zodiac_name: year.zodiac_name, total_days: year.total_days
59
+ )
60
+ end
98
61
 
99
- #
100
- # 二十四節気データを保存する
101
- #
102
- # @note 今は宣明暦に合わせている。江戸期以降の暦には対応していない(複数の中気節気を指定できない)
103
- #
104
- # @param [SolarTerm] term 二十四節気情報(各暦のデータ型)
105
- #
106
- # @return [Array<Result::SolarTerm>] 二十四節気データ
107
- #
108
- def self.save_solar_term(term:)
109
- return [] if term.invalid?
62
+ #
63
+ # 月データを保存する
64
+ #
65
+ # @param [Calculation::Monthly::Month] month 月情報(各暦のデータ型)
66
+ # @param [Calculation::Base::Day] day 日情報
67
+ #
68
+ # @return [Result::Month] 月データ
69
+ #
70
+ def save_month(month:, day:)
71
+ Result::Data::Month.new(
72
+ number: month.number, leaped: month.leaped?, days_name: month.days_name,
73
+ first_day: save_first_day(remainder: month.remainder,
74
+ date: day.western_date, days: day.number - 1),
75
+ odd_solar_terms: save_solar_term(term: month.odd_term),
76
+ even_solar_terms: save_solar_term(term: month.even_term)
77
+ )
78
+ end
110
79
 
111
- [
112
- Result::Data::SolarTerm.new(
113
- index: term.index,
114
- remainder: term.remainder
80
+ #
81
+ # 月初日データを保存する
82
+ #
83
+ # @param [Cycle::AbstractRemainder] remainder 大余小余情報
84
+ # @param [Western::Calendar] date 年月日情報(西暦)
85
+ # @param [Integer] days 日数(月初日から指定日までの日数)
86
+ #
87
+ # @return [Result::Day] 日データ
88
+ #
89
+ def save_first_day(remainder:, date:, days:)
90
+ western_date = date.clone - days
91
+ Result::Data::Day.new(
92
+ number: 1,
93
+ zodiac_name: remainder.zodiac_name,
94
+ remainder: remainder,
95
+ western_date: western_date
115
96
  )
116
- ]
117
- end
118
- private_class_method :save_solar_term
97
+ end
119
98
 
120
- #
121
- # 日データを保存する
122
- #
123
- # @param [Calculation::Base::Day] day 日情報
124
- #
125
- # @return [Result::Day] 日データ
126
- #
127
- def self.save_day(day:)
128
- remainder = day.remainder
129
- Result::Data::Day.new(
130
- number: day.number,
131
- zodiac_name: remainder.zodiac_name,
132
- remainder: remainder,
133
- western_date: day.western_date
134
- )
99
+ #
100
+ # 二十四節気データを保存する
101
+ #
102
+ # @note 今は宣明暦に合わせている。江戸期以降の暦には対応していない(複数の中気節気を指定できない)
103
+ #
104
+ # @param [SolarTerm] term 二十四節気情報(各暦のデータ型)
105
+ #
106
+ # @return [Array<Result::SolarTerm>] 二十四節気データ
107
+ #
108
+ def save_solar_term(term:)
109
+ return [] if term.invalid?
110
+
111
+ [
112
+ Result::Data::SolarTerm.new(
113
+ index: term.index,
114
+ remainder: term.remainder
115
+ )
116
+ ]
117
+ end
118
+
119
+ #
120
+ # 日データを保存する
121
+ #
122
+ # @param [Calculation::Base::Day] day 日情報
123
+ #
124
+ # @return [Result::Day] 日データ
125
+ #
126
+ def save_day(day:)
127
+ remainder = day.remainder
128
+ Result::Data::Day.new(
129
+ number: day.number,
130
+ zodiac_name: remainder.zodiac_name,
131
+ remainder: remainder,
132
+ western_date: day.western_date
133
+ )
134
+ end
135
135
  end
136
- private_class_method :save_day
137
136
  end
138
137
  end
139
138
  end
@@ -9,11 +9,11 @@ module Zakuro
9
9
  #
10
10
  # 運用情報
11
11
  #
12
- module Operation
12
+ class Operation
13
13
  #
14
14
  # Month 運用情報(月)
15
15
  #
16
- module Month
16
+ class Month
17
17
  #
18
18
  # Annotation 注釈
19
19
  #
@@ -11,11 +11,11 @@ module Zakuro
11
11
  #
12
12
  # 運用情報
13
13
  #
14
- module Operation
14
+ class Operation
15
15
  #
16
16
  # Month 運用情報(月)
17
17
  #
18
- module Month
18
+ class Month
19
19
  #
20
20
  # History 月別履歴情報
21
21
  #
@@ -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
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './data/single_day'
4
+
5
+ require_relative './operation/month'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ #
10
+ # Result 演算結果
11
+ #
12
+ module Result
13
+ #
14
+ # Operation 運用情報
15
+ #
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
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
+ end
39
+ end
@@ -4,7 +4,7 @@ require 'json'
4
4
 
5
5
  require_relative './data/single_day'
6
6
 
7
- require_relative './operation/bundle'
7
+ require_relative './operation'
8
8
 
9
9
  require_relative './core'
10
10
 
@@ -20,14 +20,14 @@ module Zakuro
20
20
  class Single < Core
21
21
  # @return [Data::SingleDay] 1日
22
22
  attr_reader :data
23
- # @return [Operation::Bundle] 運用情報
23
+ # @return [Operation] 運用情報
24
24
  attr_reader :operation
25
25
 
26
26
  #
27
27
  # 初期化
28
28
  #
29
29
  # @param [Data::SingleDay] data 1日
30
- # @param [Operation::Bundle] operation 運用情報
30
+ # @param [Operation] operation 運用情報
31
31
  #
32
32
  def initialize(data:, operation:)
33
33
  super
@@ -12,81 +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
- # @param [True, False] formatted 整形有無
21
- #
22
- # @return [Hash<String, Objcet>] ハッシュ
23
- #
24
- def self.to_h(obj:, class_prefix:, formatted: true)
25
- hash = {}
26
- obj.instance_variables.each do |var|
27
- key = var.to_s.delete('@')
28
- hash[key] = value_to_hash(
29
- obj: obj.instance_variable_get(var), class_prefix: class_prefix, formatted: formatted
30
- )
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
31
34
  end
32
- hash
33
- end
34
35
 
35
- #
36
- # 対象インスタンスをハッシュ化する(再帰処理)
37
- #
38
- # @param [Object] obj 対象インスタンス
39
- # @param [String] class_prefix インスタンス内でハッシュ変換するクラスのプレフィックス
40
- # @param [True, False] formatted 整形有無
41
- #
42
- # @return [Hash<String, Objcet>] ハッシュ
43
- #
44
- def self.value_to_hash(obj:, class_prefix:, formatted:)
45
- return obj unless obj
36
+ private
46
37
 
47
- # 日付をフォーマットする
48
- return obj.format if formatted && Tools::Typeof.time?(obj: 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
49
49
 
50
- # 同じモジュール内のオブジェクトは再帰する
51
- if obj.class.name.start_with?(class_prefix)
52
- return to_h(obj: obj, class_prefix: class_prefix, formatted: formatted)
53
- end
54
-
55
- general_value_to_hash(obj: obj, class_prefix: class_prefix, formatted: formatted)
56
- end
57
- private_class_method :value_to_hash
50
+ # 日付をフォーマットする
51
+ return obj.format if formatted && Tools::Typeof.time?(obj: obj)
58
52
 
59
- #
60
- # ライブラリを問わない標準的な値をハッシュ化する(再帰処理)
61
- #
62
- # @param [Object] obj 対象インスタンス
63
- # @param [String] class_prefix インスタンス内でハッシュ変換するクラスのプレフィックス
64
- # @param [True, False] formatted 整形有無
65
- #
66
- # @return [Objcet] ハッシュ変換可能な値
67
- #
68
- def self.general_value_to_hash(obj:, class_prefix:, formatted:)
69
- # 配列は要素一つずつで再帰する
70
- if obj.is_a?(Array)
71
- arr = []
72
- obj.each do |item|
73
- arr.push(to_h(obj: item, class_prefix: class_prefix, formatted: formatted))
53
+ # 同じモジュール内のオブジェクトは再帰する
54
+ if obj.class.name.start_with?(class_prefix)
55
+ return to_h(obj: obj, class_prefix: class_prefix, formatted: formatted)
74
56
  end
75
- return arr
57
+
58
+ general_value_to_hash(obj: obj, class_prefix: class_prefix, formatted: formatted)
76
59
  end
77
60
 
78
- # ハッシュはキーごとに再帰する
79
- if obj.is_a?(Hash)
80
- hash = {}
81
- obj.each do |key, value|
82
- hash[key] = to_h(obj: value, 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
83
78
  end
84
- return hash
85
- end
86
79
 
87
- obj
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
87
+ end
88
+
89
+ obj
90
+ end
88
91
  end
89
- private_class_method :general_value_to_hash
90
92
  end
91
93
  end
92
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
@@ -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}")