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
@@ -12,9 +12,9 @@ module Zakuro
12
12
  LEVELS = {
13
13
  none: -1,
14
14
  debug: 0,
15
- info: 1
16
- # warn : 2,
17
- # error : 3,
15
+ info: 1,
16
+ warn: 2,
17
+ error: 3
18
18
  }.freeze
19
19
 
20
20
  LEVEL = LEVELS[:none]
@@ -48,6 +48,20 @@ module Zakuro
48
48
  output('INFO', *messages)
49
49
  end
50
50
 
51
+ #
52
+ # ERRORレベルの標準出力を行う
53
+ #
54
+ # @param [Error] error 例外
55
+ # @param [String] messages メッセージ
56
+ #
57
+ def error(error, *messages)
58
+ return if LEVEL < LEVELS[:error]
59
+
60
+ output('ERROR', *messages)
61
+ output('ERROR', error.message)
62
+ output('ERROR', *error.backtrace)
63
+ end
64
+
51
65
  private
52
66
 
53
67
  #
@@ -14,159 +14,125 @@ module Zakuro
14
14
  # SingleDay 1日データ
15
15
  #
16
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
-
17
+ class << self
30
18
  #
31
- # 初期化
19
+ # 1日データを生成する
32
20
  #
33
- # @param [Year] year 年情報(各暦のデータ型)
34
- # @param [Month] month 月情報(各暦のデータ型)
35
- # @param [Western::Calendar] date 年月日情報(西暦)
36
- # @param [Integer] days 日数(月初日から指定日までの日数)
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 オプション
37
25
  #
38
- def initialize(year:, month:, date:, days:)
39
- @year = year
40
- @month = month
41
- @date = date
42
- @days = days
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
+ )
43
35
  end
44
- end
45
36
 
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, month: month, date: date),
60
- month: save_month(month: month, date: date, days: days),
61
- day: save_day(month: month, date: date, days: days)
62
- )
63
- end
37
+ private
64
38
 
65
- #
66
- # 年データを保存する
67
- #
68
- # @param [Year] year 年情報(各暦のデータ型)
69
- #
70
- # @return [Result::Year] 年データ
71
- #
72
- def self.save_year(year:, month:, date:)
73
- gengou = month.gengou
74
- first = gengou.match_first_line(date: date)
75
- second = gengou.match_second_line(date: date)
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
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
85
61
 
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
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
105
79
 
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
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
96
+ )
97
+ end
98
+
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?
125
110
 
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?
111
+ [
112
+ Result::Data::SolarTerm.new(
113
+ index: term.index,
114
+ remainder: term.remainder
115
+ )
116
+ ]
117
+ end
137
118
 
138
- [
139
- Result::Data::SolarTerm.new(
140
- index: term.index,
141
- remainder: term.remainder
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
142
133
  )
143
- ]
144
- end
145
- private_class_method :save_solar_term
146
-
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)
161
- )
162
- Result::Data::Day.new(
163
- number: (days + 1),
164
- zodiac_name: remainder.zodiac_name,
165
- remainder: remainder,
166
- western_date: date
167
- )
134
+ end
168
135
  end
169
- private_class_method :save_day
170
136
  end
171
137
  end
172
138
  end
@@ -0,0 +1,43 @@
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
+ # Day 日
15
+ #
16
+ class Day
17
+ # @return [Integer] 月初日から数えた日(M月d日のdに相当)
18
+ attr_reader :number
19
+ # @return [String] 十干十二支
20
+ attr_reader :zodiac_name
21
+ # @return [String] 大余小余
22
+ attr_reader :remainder
23
+ # @return [String] 年月日
24
+ attr_reader :western_date
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [Integer] number 月初日から数えた日(M月d日のdに相当)
30
+ # @param [String] zodiac_name 十干十二支
31
+ # @param [String] remainder 大余小余
32
+ # @param [String] western_date 年月日
33
+ #
34
+ def initialize(number:, zodiac_name:, remainder:, western_date:)
35
+ @number = number
36
+ @zodiac_name = zodiac_name
37
+ @remainder = remainder
38
+ @western_date = western_date
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -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
+ # Gengou 元号
15
+ #
16
+ class Gengou
17
+ # @return [String] 元号名
18
+ attr_reader :name
19
+ # @return [Integer] 元号年
20
+ attr_reader :number
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [String] name 元号名
26
+ # @param [Integer] number 元号年
27
+ #
28
+ def initialize(name: '', number: -1)
29
+ @name = name
30
+ @number = number
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './day'
4
+
5
+ require_relative './solar_term'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ #
10
+ # Result 演算結果
11
+ #
12
+ module Result
13
+ #
14
+ # データ部
15
+ #
16
+ module Data
17
+ # :reek:TooManyInstanceVariables { max_instance_variables: 6 }
18
+
19
+ #
20
+ # Month 月
21
+ #
22
+ class Month
23
+ # @return [Integer] 月順(1-12)
24
+ attr_reader :number
25
+ # @return [True] 閏月
26
+ # @return [False] 平月
27
+ attr_reader :leaped
28
+ # @return [String] 月の大小
29
+ attr_reader :days_name
30
+ # @return [Day] 月初日データ
31
+ attr_reader :first_day
32
+ # @return [SolarTerm] 二十四節気(節気)
33
+ attr_reader :odd_solar_terms
34
+ # @return [SolarTerm] 二十四節気(中気)
35
+ attr_reader :even_solar_terms
36
+
37
+ # rubocop:disable Metrics/ParameterLists
38
+ # :reek:LongParameterList { max_params: 6 }
39
+
40
+ #
41
+ # 初期化
42
+ #
43
+ # @param [Integer] number 月順(1-12)
44
+ # @param [True, False] leaped 閏月/平月
45
+ # @param [String] days_name 月の大小
46
+ # @param [Day] first_day 月初日データ
47
+ # @param [SolarTerm] odd_solar_terms 二十四節気(節気)
48
+ # @param [SolarTerm] even_solar_terms 二十四節気(中気)
49
+ #
50
+ def initialize(number:, leaped:, days_name:, first_day:,
51
+ odd_solar_terms:, even_solar_terms:)
52
+ @number = number
53
+ @leaped = leaped
54
+ @days_name = days_name
55
+ @first_day = first_day
56
+ @odd_solar_terms = odd_solar_terms
57
+ @even_solar_terms = even_solar_terms
58
+ end
59
+ # rubocop:enable Metrics/ParameterLists
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,37 @@
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
+ # Option オプション
15
+ #
16
+ module Option
17
+ #
18
+ # AbstractOption 抽象オプション結果
19
+ #
20
+ class AbstractOption
21
+ # @return [True] オプション値有
22
+ # @return [False] オプション値無
23
+ attr_reader :matched
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [True, False] matched オプション値有無
29
+ #
30
+ def initialize(matched: false)
31
+ @matched = matched
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './solar_term'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Result 演算結果
9
+ #
10
+ module Result
11
+ #
12
+ # データ部
13
+ #
14
+ module Data
15
+ #
16
+ # Option オプション
17
+ #
18
+ module Option
19
+ #
20
+ # DroppedDate 没日
21
+ #
22
+ module DroppedDate
23
+ #
24
+ # Calculation 演算値
25
+ #
26
+ class Calculation
27
+ # @return [String] 大余小余(没余)
28
+ attr_reader :remainder
29
+ # @return [SolarTerm] 二十四節気
30
+ attr_reader :solar_term
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [String] remainder 大余小余(没余)
36
+ # @param [SolarTerm] solar_term 二十四節気
37
+ #
38
+ def initialize(remainder: '', solar_term: SolarTerm.new)
39
+ @remainder = remainder
40
+ @solar_term = solar_term
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../abstract_option'
4
+
5
+ require_relative './calculation'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ #
10
+ # Result 演算結果
11
+ #
12
+ module Result
13
+ #
14
+ # データ部
15
+ #
16
+ module Data
17
+ #
18
+ # Option オプション
19
+ #
20
+ module Option
21
+ #
22
+ # DroppedDate 没日
23
+ #
24
+ module DroppedDate
25
+ #
26
+ # Option 没日集約
27
+ #
28
+ class Option < AbstractOption
29
+ # @return [Calculation] 演算値
30
+ attr_reader :calculation
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [True, False] matched オプション値有無
36
+ # @param [Calculation] calculation 演算値
37
+ #
38
+ def initialize(matched: false, calculation: Calculation.new)
39
+ super(matched: matched)
40
+ @calculation = calculation
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,48 @@
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
+ # Option オプション
15
+ #
16
+ module Option
17
+ #
18
+ # DroppedDate 没日
19
+ #
20
+ module DroppedDate
21
+ #
22
+ # SolarTerm 二十四節気
23
+ #
24
+ class SolarTerm
25
+ # @return [Interger] 不正連番
26
+ INVALID = -1
27
+
28
+ # @return [Integer] 連番
29
+ attr_reader :index
30
+ # @return [String] 大余小余
31
+ attr_reader :remainder
32
+
33
+ #
34
+ # 初期化
35
+ #
36
+ # @param [Integer] index 連番
37
+ # @param [String] remainder 大余小余
38
+ #
39
+ def initialize(index: INVALID, remainder: '')
40
+ @index = index
41
+ @remainder = remainder
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../core'
4
+
5
+ require_relative './option/abstract_option'
6
+
7
+ require_relative './option/dropped_date/option'
8
+
9
+ require_relative 'year'
10
+
11
+ require_relative 'month'
12
+
13
+ require_relative 'day'
14
+
15
+ # :nodoc:
16
+ module Zakuro
17
+ #
18
+ # Result 演算結果
19
+ #
20
+ module Result
21
+ #
22
+ # データ部
23
+ #
24
+ module Data
25
+ #
26
+ # SingleDay 1日
27
+ #
28
+ class SingleDay < Core
29
+ # @return [Year] 年
30
+ attr_reader :year
31
+ # @return [Month] 月
32
+ attr_reader :month
33
+ # @return [Day] 日
34
+ attr_reader :day
35
+ # @return [Hash<String, Option::AbstractOption>] オプション
36
+ attr_reader :options
37
+
38
+ #
39
+ # 初期化
40
+ #
41
+ # @param [Year] year 年
42
+ # @param [Month] month 月
43
+ # @param [Day] day 日
44
+ # @param [Hash<String, Option::AbstractOption>] options オプション
45
+ #
46
+ def initialize(year:, month:, day:, options: {})
47
+ super
48
+ @year = year
49
+ @month = month
50
+ @day = day
51
+ @options = options
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end