zakuro 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -13
  3. data/VERSION +1 -1
  4. data/doc/dropped_date.md +93 -0
  5. data/doc/error.md +45 -0
  6. data/doc/operation/csv/month.csv +100 -79
  7. data/doc/operation/operation.xlsx +0 -0
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +5 -5
  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/abstract_scroll.rb +38 -29
  17. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
  18. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
  19. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
  26. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
  27. data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
  28. data/lib/zakuro/calculation/era/version/version.rb +12 -10
  29. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
  30. data/lib/zakuro/calculation/monthly/const.rb +18 -0
  31. data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
  32. data/lib/zakuro/calculation/monthly/month.rb +17 -17
  33. data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
  34. data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
  35. data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
  36. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  37. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  38. data/lib/zakuro/calculation/range/abstract_full_range.rb +40 -25
  39. data/lib/zakuro/calculation/range/abstract_operation_range.rb +111 -109
  40. data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
  41. data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
  42. data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
  43. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  44. data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
  45. data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
  46. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
  47. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
  48. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
  49. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
  50. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
  51. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
  52. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
  53. data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
  54. data/lib/zakuro/calculation/summary/internal/month.rb +32 -11
  55. data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
  56. data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
  57. data/lib/zakuro/calculation/summary/japan/range.rb +145 -118
  58. data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
  59. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +57 -50
  60. data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
  61. data/lib/zakuro/calculation/summary/western/range.rb +95 -92
  62. data/lib/zakuro/calculation/summary/western/single.rb +78 -76
  63. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -119
  64. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +63 -56
  65. data/lib/zakuro/calculation/type/old_float.rb +2 -2
  66. data/lib/zakuro/calculation/type/optional.rb +46 -0
  67. data/lib/zakuro/condition.rb +142 -92
  68. data/lib/zakuro/context/context.rb +44 -0
  69. data/lib/zakuro/context/option.rb +119 -0
  70. data/lib/zakuro/context/version_class_resolver.rb +112 -0
  71. data/lib/zakuro/era/japan/calendar.rb +35 -33
  72. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +8 -4
  73. data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
  74. data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
  75. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
  76. data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
  77. data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -34
  78. data/lib/zakuro/era/japan/gengou/resource/type.rb +45 -37
  79. data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
  80. data/lib/zakuro/era/japan/gengou.rb +28 -26
  81. data/lib/zakuro/era/japan/version.rb +18 -16
  82. data/lib/zakuro/era/western/calendar.rb +104 -88
  83. data/lib/zakuro/exception/case/pattern.rb +39 -3
  84. data/lib/zakuro/exception/case/preset.rb +2 -2
  85. data/lib/zakuro/exception/exception.rb +17 -15
  86. data/lib/zakuro/exception/zakuro_error.rb +19 -1
  87. data/lib/zakuro/gateway/locale/date.rb +2 -2
  88. data/lib/zakuro/gateway/locale/range.rb +3 -3
  89. data/lib/zakuro/gateway/range.rb +3 -3
  90. data/lib/zakuro/gateway/single.rb +14 -3
  91. data/lib/zakuro/merchant.rb +79 -9
  92. data/lib/zakuro/operation/month/parser.rb +252 -249
  93. data/lib/zakuro/operation/month/type.rb +17 -8
  94. data/lib/zakuro/operation/month/validator.rb +148 -144
  95. data/lib/zakuro/operation/operation.rb +38 -36
  96. data/lib/zakuro/operation/yaml/month.yaml +955 -281
  97. data/lib/zakuro/output/response.rb +107 -141
  98. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  99. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  100. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  101. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  102. data/lib/zakuro/result/data/single_day.rb +9 -1
  103. data/lib/zakuro/result/operation/month/annotation.rb +2 -2
  104. data/lib/zakuro/result/operation/month/history.rb +2 -2
  105. data/lib/zakuro/result/operation/month.rb +31 -0
  106. data/lib/zakuro/result/operation.rb +39 -0
  107. data/lib/zakuro/result/result.rb +3 -3
  108. data/lib/zakuro/tools/stringifier.rb +67 -42
  109. data/lib/zakuro/tools/typeconv.rb +17 -15
  110. data/lib/zakuro/tools/typeof.rb +15 -13
  111. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  112. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
  113. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  114. data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
  115. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
  116. data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
  117. data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
  118. data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
  119. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
  120. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
  121. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
  122. data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
  123. data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
  124. data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
  125. data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
  126. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
  127. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  128. data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
  129. data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
  130. data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
  131. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  132. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
  133. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  134. data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
  135. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
  136. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
  137. data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
  138. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
  139. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
  140. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
  141. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
  142. data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
  143. data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
  144. data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
  145. data/lib/zakuro/version/senmyou/const/remainder.rb +7 -1
  146. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  147. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
  148. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  149. data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
  150. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
  151. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
  152. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
  153. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
  154. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
  155. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
  156. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
  157. data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
  158. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
  159. data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
  160. metadata +27 -7
  161. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
  162. data/lib/zakuro/result/operation/month/bundle.rb +0 -36
  163. data/lib/zakuro/result/operation/operation.rb +0 -44
  164. data/lib/zakuro/version/context.rb +0 -44
  165. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -23,134 +23,132 @@ module Zakuro
23
23
  # * もし元号が存在しない期間があれば、空の元号を生成する
24
24
  #
25
25
  module EmptyLink
26
- #
27
- # 空元号で満たす
28
- #
29
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
30
- # @param [Western::Calendar] start_date 開始日
31
- # @param [Western::Calendar] last_date 終了日
32
- #
33
- def self.fill(counters:, start_date: Western::Calendar.new,
34
- last_date: Western::Calendar.new)
35
- if counters.size.zero?
36
- counters.push(
26
+ class << self
27
+ #
28
+ # 空元号で満たす
29
+ #
30
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] last_date 終了日
33
+ #
34
+ def fill(counters:, start_date: Western::Calendar.new,
35
+ last_date: Western::Calendar.new)
36
+ if counters.size.zero?
37
+ counters.push(
38
+ create_empty_counter(
39
+ start_date: start_date.clone,
40
+ last_date: last_date.clone
41
+ )
42
+ )
43
+ return counters
44
+ end
45
+
46
+ fill_both_ends(counters: counters, start_date: start_date, last_date: last_date)
47
+
48
+ fill_middle(counters: counters)
49
+ end
50
+
51
+ private
52
+
53
+ #
54
+ # リストの両端を空元号で満たす
55
+ #
56
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
57
+ # @param [Western::Calendar] start_date 開始日
58
+ # @param [Western::Calendar] last_date 終了日
59
+ #
60
+ def fill_both_ends(counters:, start_date: Western::Calendar.new,
61
+ last_date: Western::Calendar.new)
62
+ fill_by_start(counters: counters, start_date: start_date)
63
+
64
+ fill_by_last(counters: counters, last_date: last_date)
65
+ end
66
+
67
+ #
68
+ # 先頭要素の手前を空元号で満たす
69
+ #
70
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
71
+ # @param [Western::Calendar] start_date 開始日
72
+ #
73
+ def fill_by_start(counters:, start_date:)
74
+ return unless start_date < counters[0].start_date
75
+
76
+ counters.unshift(
37
77
  create_empty_counter(
38
78
  start_date: start_date.clone,
79
+ last_date: counters[0].start_date.clone - 1
80
+ )
81
+ )
82
+ end
83
+
84
+ #
85
+ # 最終要素の手前を空元号で満たす
86
+ #
87
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
88
+ # @param [Western::Calendar] last_date 終了日
89
+ #
90
+ def fill_by_last(counters:, last_date:)
91
+ return unless last_date > counters[-1].last_date
92
+
93
+ counters.push(
94
+ create_empty_counter(
95
+ start_date: counters[-1].last_date.clone + 1,
39
96
  last_date: last_date.clone
40
97
  )
41
98
  )
42
- return counters
43
99
  end
44
100
 
45
- fill_both_ends(counters: counters, start_date: start_date, last_date: last_date)
101
+ #
102
+ # 元号間を空元号で満たす
103
+ #
104
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
105
+ #
106
+ def fill_middle(counters:)
107
+ return if counters.size.zero?
46
108
 
47
- fill_middle(counters: counters)
48
- end
109
+ size = counters.size - 1
110
+ (0..size).reverse_each do |index|
111
+ break if index <= 0
49
112
 
50
- #
51
- # リストの両端を空元号で満たす
52
- #
53
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
54
- # @param [Western::Calendar] start_date 開始日
55
- # @param [Western::Calendar] last_date 終了日
56
- #
57
- def self.fill_both_ends(counters:, start_date: Western::Calendar.new,
58
- last_date: Western::Calendar.new)
59
- fill_by_start(counters: counters, start_date: start_date)
60
-
61
- fill_by_last(counters: counters, last_date: last_date)
62
- end
63
- private_class_method :fill_both_ends
64
-
65
- #
66
- # 先頭要素の手前を空元号で満たす
67
- #
68
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
69
- # @param [Western::Calendar] start_date 開始日
70
- #
71
- def self.fill_by_start(counters:, start_date:)
72
- return unless start_date < counters[0].start_date
73
-
74
- counters.unshift(
75
- create_empty_counter(
76
- start_date: start_date.clone,
77
- last_date: counters[0].start_date.clone - 1
78
- )
79
- )
80
- end
81
- private_class_method :fill_by_start
82
-
83
- #
84
- # 最終要素の手前を空元号で満たす
85
- #
86
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
87
- # @param [Western::Calendar] last_date 終了日
88
- #
89
- def self.fill_by_last(counters:, last_date:)
90
- return unless last_date > counters[-1].last_date
91
-
92
- counters.push(
93
- create_empty_counter(
94
- start_date: counters[-1].last_date.clone + 1,
95
- last_date: last_date.clone
96
- )
97
- )
98
- end
99
- private_class_method :fill_by_last
113
+ insert(counters: counters, index: index)
114
+ end
115
+ end
100
116
 
101
- #
102
- # 元号間を空元号で満たす
103
- #
104
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
105
- #
106
- def self.fill_middle(counters:)
107
- return if counters.size.zero?
117
+ #
118
+ # 対象要素に空元号を追加する
119
+ #
120
+ # @param [Array<Gengou::Counter>] counters 加算元号リスト
121
+ # @param [Integer] index 要素番号
122
+ #
123
+ def insert(counters:, index:)
124
+ before_last_date = counters[index - 1].last_date.clone
125
+ current_start_date = counters[index].start_date.clone
108
126
 
109
- size = counters.size - 1
110
- (0..size).reverse_each do |index|
111
- break if index <= 0
127
+ return if (before_last_date.clone + 1) == current_start_date
112
128
 
113
- insert(counters: counters, index: index)
129
+ counters.insert(
130
+ index,
131
+ create_empty_counter(
132
+ start_date: before_last_date + 1, last_date: current_start_date - 1
133
+ )
134
+ )
114
135
  end
115
- end
116
- private_class_method :fill_middle
117
-
118
- #
119
- # 対象要素に空元号を追加する
120
- #
121
- # @param [Array<Gengou::Counter>] counters 加算元号リスト
122
- # @param [Integer] index 要素番号
123
- #
124
- def self.insert(counters:, index:)
125
- before_last_date = counters[index - 1].last_date.clone
126
- current_start_date = counters[index].start_date.clone
127
-
128
- return if (before_last_date.clone + 1) == current_start_date
129
-
130
- counters.insert(
131
- index,
132
- create_empty_counter(
133
- start_date: before_last_date + 1, last_date: current_start_date - 1
136
+
137
+ #
138
+ # 空元号を生成する
139
+ #
140
+ # @param [Western::Calendar] start_date 西暦開始日
141
+ # @param [Western::Calendar] last_date 西暦終了日
142
+ #
143
+ # @return [Gengou::Counter] 加算元号(空元号)
144
+ #
145
+ def create_empty_counter(start_date:, last_date:)
146
+ Gengou::Counter.new(
147
+ gengou: Japan::Gengou::Resource::Gengou.new,
148
+ start_date: start_date, last_date: last_date
134
149
  )
135
- )
136
- end
137
- private_class_method :insert
138
-
139
- #
140
- # 空元号を生成する
141
- #
142
- # @param [Western::Calendar] start_date 西暦開始日
143
- # @param [Western::Calendar] last_date 西暦終了日
144
- #
145
- # @return [Gengou::Counter] 加算元号(空元号)
146
- #
147
- def self.create_empty_counter(start_date:, last_date:)
148
- Gengou::Counter.new(
149
- gengou: Japan::Gengou::Resource::Gengou.new,
150
- start_date: start_date, last_date: last_date
151
- )
150
+ end
152
151
  end
153
- private_class_method :create_empty_counter
154
152
  end
155
153
  end
156
154
  end
@@ -31,7 +31,7 @@ module Zakuro
31
31
  @last_date = Western::Calendar.new
32
32
 
33
33
  locate(start_name: start_name, last_name: last_name)
34
- super(index: @index, start_date: @start_date, last_date: @last_date)
34
+ super(index: index, start_date: start_date, last_date: last_date)
35
35
  end
36
36
 
37
37
  private
@@ -71,12 +71,12 @@ module Zakuro
71
71
  def choise_start_date(date:)
72
72
  return if date.invalid?
73
73
 
74
- if @start_date.invalid?
74
+ if start_date.invalid?
75
75
  @start_date = date
76
76
  return
77
77
  end
78
78
 
79
- return if date > @start_date
79
+ return if date > start_date
80
80
 
81
81
  @start_date = date
82
82
  end
@@ -89,12 +89,12 @@ module Zakuro
89
89
  def choise_last_date(date:)
90
90
  return if date.invalid?
91
91
 
92
- if @last_date.invalid?
92
+ if last_date.invalid?
93
93
  @last_date = date
94
94
  return
95
95
  end
96
96
 
97
- return if date < @last_date
97
+ return if date < last_date
98
98
 
99
99
  @last_date = date
100
100
  end
@@ -107,7 +107,7 @@ module Zakuro
107
107
  # @return [Array<Japan::Alignment::LinearGengou>] 元号
108
108
  #
109
109
  def line_by_name(name:)
110
- Japan::Gengou.line_by_name(line: @index, name: name)
110
+ Japan::Gengou.line_by_name(line: index, name: name)
111
111
  end
112
112
 
113
113
  #
@@ -53,20 +53,18 @@ module Zakuro
53
53
  # @return [List] 最新の元号
54
54
  #
55
55
  def newest_list
56
- return @first_list if @first_list.invalid?
56
+ return first_list if invalid_list?
57
57
 
58
- return @first_list if @second_list.invalid?
58
+ first_western_date = first_list.western_last_date
59
+ second_western_date = second_list.western_last_date
59
60
 
60
- first_western_date = @first_list.western_last_date
61
- second_western_date = @second_list.western_last_date
61
+ return first_list if first_western_date.invalid?
62
62
 
63
- return @first_list if first_western_date.invalid?
63
+ return first_list if second_western_date.invalid?
64
64
 
65
- return @first_list if second_western_date.invalid?
65
+ return first_list if first_western_date > second_western_date
66
66
 
67
- return @first_list if first_western_date > second_western_date
68
-
69
- @second_list
67
+ second_list
70
68
  end
71
69
  end
72
70
  end
@@ -14,26 +14,28 @@ module Zakuro
14
14
  # 元号に基づき計算範囲を予約する
15
15
  #
16
16
  module Reserve
17
- #
18
- # 予約結果を取得する
19
- #
20
- # * 開始日・終了日から計算する範囲を求める
21
- # * 開始日・終了日の範囲内にある元号全てが対象となる
22
- # * 元号に応じて計算範囲は変化する
23
- # * 元号の開始日(改元日)が開始日よりも前であれば、結果開始日は前者になる
24
- # * 元号の終了日(改元前日)が終了日よりも後であれば、結果終了日は前者になる
25
- # * 南北朝のように複数元号に属する場合、より広い範囲の元号に合わせる
26
- # * 属する元号よりもさらに範囲を広げる場合がある
27
- # * 開始日が最初の元号の改元後30日以内の場合、さらに前の元号まで対象にする
28
- # * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
29
- #
30
- # @param [Western::Calendar] start_date 開始日
31
- # @param [Western::Calendar] last_date 終了日
32
- #
33
- # @return [Range] 予約済み計算範囲
34
- #
35
- def self.get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
36
- DatedRange.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
37
39
  end
38
40
  end
39
41
  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