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
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../../../era/western/calendar'
4
- require_relative './reserve/range'
5
- require_relative './reserve/list'
4
+ require_relative './reserve/dated_range'
6
5
 
7
6
  # :nodoc:
8
7
  module Zakuro
@@ -15,26 +14,28 @@ module Zakuro
15
14
  # 元号に基づき計算範囲を予約する
16
15
  #
17
16
  module Reserve
18
- #
19
- # 予約結果を取得する
20
- #
21
- # * 開始日・終了日から計算する範囲を求める
22
- # * 開始日・終了日の範囲内にある元号全てが対象となる
23
- # * 元号に応じて計算範囲は変化する
24
- # * 元号の開始日(改元日)が開始日よりも前であれば、結果開始日は前者になる
25
- # * 元号の終了日(改元前日)が終了日よりも後であれば、結果終了日は前者になる
26
- # * 南北朝のように複数元号に属する場合、より広い範囲の元号に合わせる
27
- # * 属する元号よりもさらに範囲を広げる場合がある
28
- # * 開始日が最初の元号の改元後30日以内の場合、さらに前の元号まで対象にする
29
- # * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
30
- #
31
- # @param [Western::Calendar] start_date 開始日
32
- # @param [Western::Calendar] last_date 終了日
33
- #
34
- # @return [Range] 予約済み計算範囲
35
- #
36
- def self.get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
37
- Range.new(start_date: start_date, last_date: last_date)
17
+ class << self
18
+ #
19
+ # 予約結果を取得する
20
+ #
21
+ # * 開始日・終了日から計算する範囲を求める
22
+ # * 開始日・終了日の範囲内にある元号全てが対象となる
23
+ # * 元号に応じて計算範囲は変化する
24
+ # * 元号の開始日(改元日)が開始日よりも前であれば、結果開始日は前者になる
25
+ # * 元号の終了日(改元前日)が終了日よりも後であれば、結果終了日は前者になる
26
+ # * 南北朝のように複数元号に属する場合、より広い範囲の元号に合わせる
27
+ # * 属する元号よりもさらに範囲を広げる場合がある
28
+ # * 開始日が最初の元号の改元後30日以内の場合、さらに前の元号まで対象にする
29
+ # * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
30
+ #
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] last_date 終了日
33
+ #
34
+ # @return [Range] 予約済み計算範囲
35
+ #
36
+ def get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
37
+ DatedRange.new(start_date: start_date, last_date: last_date)
38
+ end
38
39
  end
39
40
  end
40
41
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './abstract_scroll'
4
+ require_relative './internal/reserve/named_range'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Gengou
12
+ # NamedScroll
13
+ #
14
+ # 元号スクロール
15
+ #
16
+ class NamedScroll < AbstractScroll
17
+ #
18
+ # 初期化
19
+ #
20
+ # @param [String] start_name 開始元号名
21
+ # @param [String] last_name 終了元号名
22
+ #
23
+ def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME)
24
+ range = Reserve::NamedRange.new(start_name: start_name, last_name: last_name)
25
+ super(range: range)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -13,37 +13,54 @@ module Zakuro
13
13
  # 暦検索
14
14
  #
15
15
  module Crawler
16
- #
17
- # 暦の範囲を取得する
18
- #
19
- # @param [Integer] start_year 開始西暦年
20
- # @param [Integer] last_year 終了西暦年
21
- #
22
- # @return [Array<Range>] 暦の範囲
23
- #
24
- def self.get(start_year:, last_year:)
25
- ranges = Japan::Version.ranges_with_year(start_year: start_year, last_year: last_year)
26
-
27
- result = []
28
-
29
- ranges.each do |range|
30
- next unless range.released
16
+ class << self
17
+ #
18
+ # 暦の範囲を取得する
19
+ #
20
+ # @param [Integer] start_year 開始西暦年
21
+ # @param [Integer] last_year 終了西暦年
22
+ #
23
+ # @return [Array<Range>] 暦の範囲
24
+ #
25
+ def get(start_year:, last_year:)
26
+ ranges = Japan::Version.ranges_with_year(start_year: start_year, last_year: last_year)
31
27
 
28
+ result = []
29
+
30
+ ranges.each do |range|
31
+ next unless range.released
32
+
33
+ narrowed_range = narrow(range: range, start_year: start_year, last_year: last_year)
34
+
35
+ result.push(narrowed_range)
36
+ end
37
+
38
+ result
39
+ end
40
+
41
+ private
42
+
43
+ #
44
+ # 範囲を開始年・終了年に合わせて狭める
45
+ #
46
+ # @param [Range] range 範囲
47
+ # @param [Integer] start_year 開始西暦年
48
+ # @param [Integer] last_year 終了西暦年
49
+ #
50
+ # @return [Range] 範囲
51
+ #
52
+ def narrow(range:, start_year:, last_year:)
32
53
  range_start_year = range.start_year
33
54
  range_start_year = start_year if start_year > range.start_year
34
55
 
35
56
  range_last_year = range.last_year
36
57
  range_last_year = last_year if last_year < range.last_year
37
58
 
38
- result.push(
39
- Range.new(
40
- name: range.name, start_date: range.start_date.clone,
41
- start_year: range_start_year, last_year: range_last_year
42
- )
59
+ Range.new(
60
+ name: range.name, start_date: range.start_date.clone,
61
+ start_year: range_start_year, last_year: range_last_year
43
62
  )
44
63
  end
45
-
46
- result
47
64
  end
48
65
  end
49
66
  end
@@ -8,16 +8,18 @@ module Zakuro
8
8
  module Calculation
9
9
  # :nodoc:
10
10
  module Version
11
- #
12
- # 暦の範囲を取得する
13
- #
14
- # @param [Integer] start_year 開始西暦年
15
- # @param [Integer] last_year 終了西暦年
16
- #
17
- # @return [Array<Range>] 暦の範囲
18
- #
19
- def self.get(start_year:, last_year:)
20
- Crawler.get(start_year: start_year, last_year: last_year)
11
+ class << self
12
+ #
13
+ # 暦の範囲を取得する
14
+ #
15
+ # @param [Integer] start_year 開始西暦年
16
+ # @param [Integer] last_year 終了西暦年
17
+ #
18
+ # @return [Array<Range>] 暦の範囲
19
+ #
20
+ def get(start_year:, last_year:)
21
+ Crawler.get(start_year: start_year, last_year: last_year)
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative '../../output/logger'
4
4
 
5
+ require_relative './const'
6
+
5
7
  # :nodoc:
6
8
  module Zakuro
7
9
  # :nodoc:
@@ -16,8 +18,10 @@ module Zakuro
16
18
  LOGGER = Output::Logger.new(location: 'lunar_phase')
17
19
 
18
20
  # @return [Array<String>] 月内の弦
19
- PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
21
+ PHASE_INDEXES = Const::PHASE_INDEXES
20
22
 
23
+ # @return [Cycle::AbstractRemainder] 弦
24
+ attr_reader :quarter
21
25
  # @return [Cycle::AbstractRemainder] 経
22
26
  attr_reader :average_remainder
23
27
  # @return [Solar::AbstractLocation] 入定気
@@ -30,14 +34,14 @@ module Zakuro
30
34
  #
31
35
  # 初期化
32
36
  #
33
- # @param [Cycle::AbstractRemainder] quater
37
+ # @param [Cycle::AbstractRemainder] quarter
34
38
  # @param [Solar::AbstractLocation] average_remainder 経
35
39
  # @param [Solar::AbstractLocation] solar_location 入定気
36
40
  # @param [Lunar::AbstractLocation] lunar_location 入暦
37
41
  #
38
- def initialize(quater:, average_remainder:, solar_location:, lunar_location:)
42
+ def initialize(quarter:, average_remainder:, solar_location:, lunar_location:)
39
43
  # 弦
40
- @quarter = quater
44
+ @quarter = quarter
41
45
  # 経
42
46
  @average_remainder = average_remainder
43
47
  # 入定気
@@ -87,7 +91,7 @@ module Zakuro
87
91
  #
88
92
  def next_index
89
93
  @index += 1
90
- @index = 0 if @index >= PHASE_INDEXES.size
94
+ @index = 0 if index >= PHASE_INDEXES.size
91
95
  @index
92
96
  end
93
97
 
@@ -98,7 +102,7 @@ module Zakuro
98
102
  # @return [False] 朔月ではない
99
103
  #
100
104
  def first_phase?
101
- @index.zero?
105
+ index.zero?
102
106
  end
103
107
 
104
108
  #
@@ -157,9 +161,9 @@ module Zakuro
157
161
  end
158
162
 
159
163
  def add_quarter_moon_size
160
- @average_remainder.add!(@quarter)
161
- @solar_location.add_quarter
162
- @lunar_location.add_quarter
164
+ average_remainder.add!(quarter)
165
+ solar_location.add_quarter
166
+ lunar_location.add_quarter
163
167
 
164
168
  next_index
165
169
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Monthly
9
+ #
10
+ # Const 定数
11
+ #
12
+ module Const
13
+ # @return [Array<String>] 月内の弦
14
+ PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
15
+ end
16
+ end
17
+ end
18
+ end
@@ -25,7 +25,7 @@ module Zakuro
25
25
  #
26
26
  # 初期化
27
27
  #
28
- # @param [Context] context 暦コンテキスト
28
+ # @param [Context::Context] context 暦コンテキスト
29
29
  # @param [MonthLabel] month_label 月表示名
30
30
  # @param [Array<SolarTerm>] solar_terms 二十四節気
31
31
  # @param [FirstDay] first_day 月初日(朔日)
@@ -67,43 +67,6 @@ module Zakuro
67
67
  )
68
68
  end
69
69
 
70
- #
71
- # 中気の連番に合わせて月を返す
72
- #
73
- # @example
74
- # 20: 9月
75
- # 22: 10月
76
- # 0: 11月
77
- # 2: 12月
78
- # 4: 1月
79
- #
80
- # @param [Integer] index 中気番号
81
- #
82
- # @return [Integer] 月
83
- #
84
- def self.month_number_by_even_term_index(index)
85
- half_index = index / 2
86
-
87
- # 11月、12月
88
- return half_index + 11 if half_index < 2
89
-
90
- # 1月~10月
91
- half_index - 1
92
- end
93
-
94
- #
95
- # 節気の連番に合わせて月を返す
96
- #
97
- # @param [Integer] index 節気番号
98
- #
99
- # @return [Integer] 月
100
- #
101
- def self.month_number_by_odd_term_index(index)
102
- even_index = index - 1
103
-
104
- month_number_by_even_term_index(even_index)
105
- end
106
-
107
70
  #
108
71
  # 一ヶ月戻す
109
72
  #
@@ -119,6 +82,45 @@ module Zakuro
119
82
  def solar_term_size
120
83
  solar_terms.size
121
84
  end
85
+
86
+ class << self
87
+ #
88
+ # 中気の連番に合わせて月を返す
89
+ #
90
+ # @example
91
+ # 20: 9月
92
+ # 22: 10月
93
+ # 0: 11月
94
+ # 2: 12月
95
+ # 4: 1月
96
+ #
97
+ # @param [Integer] index 中気番号
98
+ #
99
+ # @return [Integer] 月
100
+ #
101
+ def month_number_by_even_term_index(index)
102
+ half_index = index / 2
103
+
104
+ # 11月、12月
105
+ return half_index + 11 if half_index < 2
106
+
107
+ # 1月~10月
108
+ half_index - 1
109
+ end
110
+
111
+ #
112
+ # 節気の連番に合わせて月を返す
113
+ #
114
+ # @param [Integer] index 節気番号
115
+ #
116
+ # @return [Integer] 月
117
+ #
118
+ def month_number_by_odd_term_index(index)
119
+ even_index = index - 1
120
+
121
+ month_number_by_even_term_index(even_index)
122
+ end
123
+ end
122
124
  end
123
125
  end
124
126
  end
@@ -14,7 +14,7 @@ module Zakuro
14
14
  # Month 月情報
15
15
  #
16
16
  class Month
17
- # @return [Context] 暦コンテキスト
17
+ # @return [Context::Context] 暦コンテキスト
18
18
  attr_reader :context
19
19
  # @return [MonthLabel] 月表示名
20
20
  attr_reader :month_label
@@ -28,14 +28,14 @@ module Zakuro
28
28
  #
29
29
  # 初期化
30
30
  #
31
- # @param [Context] context 暦コンテキスト
31
+ # @param [Context::Context] context 暦コンテキスト
32
32
  # @param [MonthLabel] month_label 月表示名
33
33
  # @param [FirstDay] first_day 月初日(朔日)
34
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
35
35
  # @param [Base::Gengou] gengou 元号
36
36
  #
37
- def initialize(context: Context.new, month_label: MonthLabel.new, first_day: FirstDay.new,
38
- solar_terms: [], gengou: Base::Gengou.new)
37
+ def initialize(context: Context::Context.new, month_label: MonthLabel.new,
38
+ first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new)
39
39
  @context = context
40
40
  @month_label = month_label
41
41
  @first_day = first_day
@@ -50,7 +50,7 @@ module Zakuro
50
50
  # @return [False] 不正なし
51
51
  #
52
52
  def invalid?
53
- @context.invalid?
53
+ context.invalid?
54
54
  end
55
55
 
56
56
  #
@@ -68,7 +68,7 @@ module Zakuro
68
68
  # @return [Western::Calendar] 西暦日
69
69
  #
70
70
  def western_date
71
- @first_day.western_date
71
+ first_day.western_date
72
72
  end
73
73
 
74
74
  #
@@ -77,7 +77,7 @@ module Zakuro
77
77
  # @return [Remainder] 大余小余
78
78
  #
79
79
  def remainder
80
- @first_day.remainder
80
+ first_day.remainder
81
81
  end
82
82
 
83
83
  #
@@ -87,7 +87,7 @@ module Zakuro
87
87
  # @return [False] 小の月(29日)
88
88
  #
89
89
  def many_days?
90
- @month_label.is_many_days
90
+ month_label.is_many_days
91
91
  end
92
92
 
93
93
  #
@@ -96,7 +96,7 @@ module Zakuro
96
96
  # @return [Integer] 日数
97
97
  #
98
98
  def days
99
- @month_label.days
99
+ month_label.days
100
100
  end
101
101
 
102
102
  #
@@ -105,7 +105,7 @@ module Zakuro
105
105
  # @return [String] 月の名前(大小)
106
106
  #
107
107
  def days_name
108
- @month_label.days_name
108
+ month_label.days_name
109
109
  end
110
110
 
111
111
  #
@@ -114,7 +114,7 @@ module Zakuro
114
114
  # @return [Integer] 月(xx月のxx)
115
115
  #
116
116
  def number
117
- @month_label.number
117
+ month_label.number
118
118
  end
119
119
 
120
120
  #
@@ -124,7 +124,7 @@ module Zakuro
124
124
  # @return [False] 平月
125
125
  #
126
126
  def leaped?
127
- @month_label.leaped
127
+ month_label.leaped
128
128
  end
129
129
 
130
130
  #
@@ -147,7 +147,7 @@ module Zakuro
147
147
  # @return [False] 設定あり
148
148
  #
149
149
  def empty_solar_term?
150
- @solar_terms.empty?
150
+ solar_terms.empty?
151
151
  end
152
152
 
153
153
  #
@@ -156,7 +156,7 @@ module Zakuro
156
156
  # @return [SolarTerm] 中気
157
157
  #
158
158
  def even_term
159
- @solar_terms.each do |term|
159
+ solar_terms.each do |term|
160
160
  return term if term.index.even?
161
161
  end
162
162
 
@@ -169,7 +169,7 @@ module Zakuro
169
169
  # @return [SolarTerm] 節気
170
170
  #
171
171
  def odd_term
172
- @solar_terms.each do |term|
172
+ solar_terms.each do |term|
173
173
  return term if term.index.odd?
174
174
  end
175
175
 
@@ -182,7 +182,7 @@ module Zakuro
182
182
  # @param [SolarTerm] term 二十四節気
183
183
  #
184
184
  def add_term(term:)
185
- @solar_terms.push(term)
185
+ solar_terms.push(term)
186
186
  end
187
187
 
188
188
  #
@@ -228,6 +228,45 @@ module Zakuro
228
228
 
229
229
  true
230
230
  end
231
+
232
+ #
233
+ # 範囲内か
234
+ #
235
+ # @param [Japan::Calendar] date 日付
236
+ #
237
+ # @return [True] 範囲内
238
+ # @return [False] 範囲外
239
+ #
240
+ def include_by_japan_date?(date:)
241
+ return false if invalid?
242
+
243
+ linear_gengou = gengou.match_by_name(name: date.gengou)
244
+ return false if linear_gengou.invalid?
245
+
246
+ return false unless linear_gengou.name == date.gengou
247
+
248
+ return false unless linear_gengou.year == date.year
249
+
250
+ same_by_japan_date?(date: date)
251
+ end
252
+
253
+ private
254
+
255
+ #
256
+ # 同一の月情報かを検証する
257
+ #
258
+ # @param [Japan::Calendar] date 日付
259
+ #
260
+ # @return [True] 同一の月
261
+ # @return [False] 異なる月
262
+ #
263
+ def same_by_japan_date?(date: Japan::Calendar.new)
264
+ return false unless number == date.month
265
+
266
+ return false unless leaped? == date.leaped
267
+
268
+ true
269
+ end
231
270
  end
232
271
  end
233
272
  end
@@ -43,7 +43,7 @@ module Zakuro
43
43
  # @return [Integer] 日数
44
44
  #
45
45
  def days
46
- @is_many_days ? 30 : 29
46
+ is_many_days ? 30 : 29
47
47
  end
48
48
 
49
49
  #
@@ -52,7 +52,7 @@ module Zakuro
52
52
  # @return [String] 月の名前(大小)
53
53
  #
54
54
  def days_name
55
- @is_many_days ? '大' : '小'
55
+ is_many_days ? '大' : '小'
56
56
  end
57
57
 
58
58
  #
@@ -64,7 +64,7 @@ module Zakuro
64
64
  def back_to_last_month
65
65
  @number -= 1
66
66
 
67
- return false if @number.positive?
67
+ return false if number.positive?
68
68
 
69
69
  @number = 12
70
70
 
@@ -80,7 +80,7 @@ module Zakuro
80
80
  # @return [False] 異なる月
81
81
  #
82
82
  def same?(other:)
83
- @number == other.number && @leaped == other.leaped
83
+ number == other.number && leaped == other.leaped
84
84
  end
85
85
  end
86
86
  end