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
@@ -9,146 +9,167 @@ module Zakuro
9
9
  # :nodoc:
10
10
  module Japan
11
11
  # :nodoc:
12
- module Alignment
13
- #
14
- # Line 行
15
- #
16
- class Line
17
- # @return [Array<LinearGengou>] 元号
18
- attr_reader :list
19
-
12
+ module Gengou
13
+ # :nodoc:
14
+ module Alignment
20
15
  #
21
- # 初期化
16
+ # Line 行
22
17
  #
23
- def initialize
24
- @list = []
25
- end
18
+ class Line
19
+ # @return [Array<LinearGengou>] 元号
20
+ attr_reader :list
26
21
 
27
- #
28
- # 追加する
29
- #
30
- # 下記のパターンが存在し、戻り値は重複分となる
31
- #
32
- # 1. 完全に範囲外(開始日より前)
33
- # [@list]: |-------|-------|
34
- # [list]: |---|
35
- # 2. 前半のみ範囲外
36
- # [@list]: |-------|-------|
37
- # [list]: |------|
38
- # 3. 範囲内
39
- # [@list]: |-------|-------|
40
- # [list]: |------|
41
- # 4. 後半のみ範囲外
42
- # [@list]: |-------|-------|
43
- # [list]: |------|
44
- # 5. 完全に範囲外(開始日より後)
45
- # [@list]: |-------|-------|
46
- # [list]: |----|
47
- # 6. 両端が範囲外
48
- # [@list]: |-------|-------|
49
- # [list]: |--------------------|
50
- #
51
- # @param [Array<LinearGengou>] list 元号
52
- #
53
- # @return [Array<LinearGengou>] 未登録元号
54
- #
55
- def push(list: [])
56
- rest = rest(list: list)
57
-
58
- insert(list: list)
59
-
60
- rest
61
- end
62
-
63
- #
64
- # 範囲内の元号を取得する
65
- #
66
- # @param [Western::Calendar] start_date 開始日
67
- # @param [Western::Calendar] last_date 終了日
68
- #
69
- # @return [Array<LinearGengou>] 元号
70
- #
71
- def get(start_date:, last_date:)
72
- result = []
73
- @list.each do |gengou|
74
- next if gengou.out?(start_date: start_date, last_date: last_date)
75
-
76
- # 1日でも範囲内であれば対象とみなす
77
- result.push(gengou)
22
+ #
23
+ # 初期化
24
+ #
25
+ def initialize
26
+ @list = []
78
27
  end
79
28
 
80
- result
81
- end
82
-
83
- private
29
+ #
30
+ # 追加する
31
+ #
32
+ # 下記のパターンが存在し、戻り値は重複分となる
33
+ #
34
+ # 1. 完全に範囲外(開始日より前)
35
+ # [@list]: |-------|-------|
36
+ # [list]: |---|
37
+ # 2. 前半のみ範囲外
38
+ # [@list]: |-------|-------|
39
+ # [list]: |------|
40
+ # 3. 範囲内
41
+ # [@list]: |-------|-------|
42
+ # [list]: |------|
43
+ # 4. 後半のみ範囲外
44
+ # [@list]: |-------|-------|
45
+ # [list]: |------|
46
+ # 5. 完全に範囲外(開始日より後)
47
+ # [@list]: |-------|-------|
48
+ # [list]: |----|
49
+ # 6. 両端が範囲外
50
+ # [@list]: |-------|-------|
51
+ # [list]: |--------------------|
52
+ #
53
+ # @param [Array<LinearGengou>] list 元号
54
+ #
55
+ # @return [Array<LinearGengou>] 未登録元号
56
+ #
57
+ def push(list: [])
58
+ rest = rest(list: list)
59
+
60
+ insert(list: list)
61
+
62
+ rest
63
+ end
84
64
 
85
- #
86
- # 重複分(空きがないため追加できない範囲の元号)を返す
87
- #
88
- # @param [Array<LinearGengou>] list 元号
89
- #
90
- # @return [Array<LinearGengou>] 重複分元号
91
- #
92
- def rest(list: [])
93
- result = []
65
+ #
66
+ # 範囲内の元号を取得する
67
+ #
68
+ # @param [Western::Calendar] start_date 開始日
69
+ # @param [Western::Calendar] last_date 終了日
70
+ #
71
+ # @return [Array<LinearGengou>] 元号
72
+ #
73
+ def get(start_date:, last_date:)
74
+ result = []
75
+ list.each do |gengou|
76
+ next if gengou.out?(start_date: start_date, last_date: last_date)
77
+
78
+ # 1日でも範囲内であれば対象とみなす
79
+ result.push(gengou)
80
+ end
81
+
82
+ result
83
+ end
94
84
 
95
- @list.each do |gengou|
96
- result |= and!(rest: list, other: gengou)
85
+ #
86
+ # 範囲内の元号を取得する(元号名)
87
+ #
88
+ # @param [String] name 元号名
89
+ #
90
+ # @return [Array<LinearGengou>] 元号
91
+ #
92
+ def get_by_name(name:)
93
+ result = []
94
+ list.each do |gengou|
95
+ result.push(gengou) if gengou.name == name
96
+ end
97
+
98
+ result
97
99
  end
98
100
 
99
- Division.connect(list: result)
100
- end
101
+ private
101
102
 
102
- #
103
- # 空き範囲に元号を登録する
104
- #
105
- # @param [Array<LinearGengou>] list 元号
106
- #
107
- def insert(list: [])
108
- surplus_result = list.clone
109
- @list.each do |gengou|
110
- surplus_result = not!(surplus: surplus_result, other: gengou)
111
- end
103
+ #
104
+ # 重複分(空きがないため追加できない範囲の元号)を返す
105
+ #
106
+ # @param [Array<LinearGengou>] list 元号
107
+ #
108
+ # @return [Array<LinearGengou>] 重複分元号
109
+ #
110
+ def rest(list: [])
111
+ result = []
112
112
 
113
- surplus_result = Division.connect(list: surplus_result)
113
+ inner_list = @list
114
+ inner_list.each do |gengou|
115
+ result |= and!(rest: list, other: gengou)
116
+ end
114
117
 
115
- surplus_result.each do |gengou|
116
- @list.push(gengou)
118
+ Division.connect(list: result)
117
119
  end
118
- end
119
120
 
120
- #
121
- # 重複した範囲を返す
122
- #
123
- # @param [Array<LinearGengou>] rest 残り元号
124
- # @param [LinearGengou] other 比較元号
125
- #
126
- # @return [Array<LinearGengou>] 重複分
127
- #
128
- def and!(rest:, other:)
129
- result = []
130
- rest.each do |gengou|
131
- result |= Division.match(this: gengou, other: other)
121
+ #
122
+ # 空き範囲に元号を登録する
123
+ #
124
+ # @param [Array<LinearGengou>] list 元号
125
+ #
126
+ def insert(list: [])
127
+ inner_list = @list
128
+ surplus_result = list.clone
129
+ inner_list.each do |gengou|
130
+ surplus_result = not!(surplus: surplus_result, other: gengou)
131
+ end
132
+
133
+ surplus_result = Division.connect(list: surplus_result)
134
+
135
+ surplus_result.each do |gengou|
136
+ inner_list.push(gengou)
137
+ end
132
138
  end
133
139
 
134
- result
135
- end
136
-
137
- #
138
- # 範囲が重複しない差分を返す
139
- #
140
- # @param [Array<LinearGengou>] surplus 積元号
141
- # @param [LinearGengou] other 比較元号
142
- #
143
- # @return [Array<LinearGengou>] 差分
144
- #
145
- def not!(surplus:, other:)
146
- result = []
147
- surplus.each do |gengou|
148
- result |= Division.mismatch(this: gengou, other: other)
140
+ #
141
+ # 重複した範囲を返す
142
+ #
143
+ # @param [Array<LinearGengou>] rest 残り元号
144
+ # @param [LinearGengou] other 比較元号
145
+ #
146
+ # @return [Array<LinearGengou>] 重複分
147
+ #
148
+ def and!(rest:, other:)
149
+ result = []
150
+ rest.each do |gengou|
151
+ result |= Division.match(this: gengou, other: other)
152
+ end
153
+
154
+ result
149
155
  end
150
156
 
151
- result
157
+ #
158
+ # 範囲が重複しない差分を返す
159
+ #
160
+ # @param [Array<LinearGengou>] surplus 積元号
161
+ # @param [LinearGengou] other 比較元号
162
+ #
163
+ # @return [Array<LinearGengou>] 差分
164
+ #
165
+ def not!(surplus:, other:)
166
+ result = []
167
+ surplus.each do |gengou|
168
+ result |= Division.mismatch(this: gengou, other: other)
169
+ end
170
+
171
+ result
172
+ end
152
173
  end
153
174
  end
154
175
  end
@@ -9,174 +9,183 @@ module Zakuro
9
9
  # :nodoc:
10
10
  module Japan
11
11
  # :nodoc:
12
- module Alignment
13
- #
14
- # LinearGengou 直列元号
15
- #
16
- class LinearGengou
17
- INVALID_YEAR = -1
18
-
19
- # @return [Western::Calendar] 開始日
20
- attr_reader :start_date
21
- # @return [Western::Calendar] 終了日
22
- attr_reader :last_date
23
- # @return [Gengou] 元号
24
- attr_reader :gengou
25
-
26
- #
27
- # 初期化
28
- #
29
- # @param [Western::Calendar] start_date 開始日
30
- # @param [Western::Calendar] last_date 終了日
31
- # @param [Resource::Gengou] gengou 元号
32
- #
33
- def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
34
- gengou: Resource::Gengou.new)
35
- @gengou = gengou
36
- @start_date = start_date.invalid? ? native_start_date : start_date
37
- @last_date = last_date.invalid? ? native_last_date : last_date
38
- end
39
-
40
- #
41
- # 元号名を取得する
42
- #
43
- # @return [String] 元号名
44
- #
45
- def name
46
- @gengou.name
47
- end
48
-
49
- #
50
- # 不正か
51
- #
52
- # @return [True] 不正
53
- # @return [False] 不正なし
54
- #
55
- def invalid?
56
- @gengou.invalid?
57
- end
58
-
59
- #
60
- # 範囲内か
61
- #
62
- # @param [Western::Calendar] date 西暦日
63
- #
64
- # @return [True] 範囲内
65
- # @return [False] 範囲外
66
- #
67
- def include?(date: Western::Calendar.new)
68
- return false if invalid?
69
-
70
- return false if @start_date.invalid?
71
-
72
- return false if @last_date.invalid?
73
-
74
- return false if date < @start_date
75
-
76
- return false if date > @last_date
77
-
78
- true
79
- end
80
-
81
- #
82
- # 完全に範囲内か
83
- #
84
- # @param [Western::Calendar] start_date 開始日
85
- # @param [Western::Calendar] last_date 終了日
86
- #
87
- # @return [True] 範囲内
88
- # @return [False] 範囲外あり
89
- #
90
- def in?(start_date:, last_date:)
91
- @start_date <= start_date && last_date <= @last_date
92
- end
93
-
94
- #
95
- # 完全に範囲外か
96
- #
97
- # @param [Western::Calendar] start_date 開始日
98
- # @param [Western::Calendar] last_date 終了日
99
- #
100
- # @return [True] 範囲外
101
- # @return [False] 範囲内あり
102
- #
103
- def out?(start_date:, last_date:)
104
- # 範囲より前
105
- return true if start_date < @start_date && last_date < @start_date
106
-
107
- # 範囲より後
108
- return true if @last_date < start_date && @last_date < last_date
109
-
110
- false
111
- end
112
-
113
- #
114
- # 完全に範囲を超えているか
115
- #
116
- # @param [Western::Calendar] start_date 開始日
117
- # @param [Western::Calendar] last_date 終了日
118
- #
119
- # @return [True] 完全超過
120
- # @return [True] 完全超過せず
121
- #
122
- def covered?(start_date:, last_date:)
123
- start_date < @start_date && @last_date < last_date
124
- end
125
-
126
- #
127
- # 元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?
128
- #
129
- # @return [True] 存在する
130
- # @return [False] 存在しない
131
- #
132
- def changed?
133
- return true if change_start_date?
134
-
135
- return true if change_last_date?
136
-
137
- false
138
- end
139
-
140
- #
141
- # 開始日が設定された開始日と異なるか(行が変更されているか)
142
- #
143
- # @return [True] 異なる
144
- # @return [False] 同一
145
- #
146
- def change_start_date?
147
- return false if invalid?
148
-
149
- @start_date != native_start_date
150
- end
151
-
152
- #
153
- # 終了日が設定された終了日と異なるか(行が変更されているか)
154
- #
155
- # @return [True] 異なる
156
- # @return [False] 同一
157
- #
158
- def change_last_date?
159
- return false if invalid?
160
-
161
- @last_date != native_last_date
162
- end
163
-
164
- #
165
- # 設定された元号の開始日を取得する
166
- #
167
- # @return [Western::Calendar]設定された元号の開始日
168
- #
169
- def native_start_date
170
- @gengou.both_start_date.western
171
- end
172
-
173
- #
174
- # 設定された元号の終了日を取得する
175
- #
176
- # @return [Western::Calendar] 設定された元号の終了日
177
- #
178
- def native_last_date
179
- @gengou.last_date
12
+ module Gengou
13
+ # :nodoc:
14
+ module Alignment
15
+ #
16
+ # LinearGengou 直列元号
17
+ #
18
+ class LinearGengou
19
+ INVALID_YEAR = -1
20
+
21
+ # @return [Western::Calendar] 開始日
22
+ attr_reader :start_date
23
+ # @return [Western::Calendar] 終了日
24
+ attr_reader :last_date
25
+ # @return [Gengou] 元号
26
+ attr_reader :gengou
27
+
28
+ #
29
+ # 初期化
30
+ #
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] last_date 終了日
33
+ # @param [Resource::Gengou] gengou 元号
34
+ #
35
+ def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
36
+ gengou: Resource::Gengou.new)
37
+ @gengou = gengou
38
+ @start_date = start_date.invalid? ? native_start_date : start_date
39
+ @last_date = last_date.invalid? ? native_last_date : last_date
40
+ end
41
+
42
+ #
43
+ # 元号名を取得する
44
+ #
45
+ # @return [String] 元号名
46
+ #
47
+ def name
48
+ gengou.name
49
+ end
50
+
51
+ #
52
+ # 不正か
53
+ #
54
+ # @return [True] 不正
55
+ # @return [False] 不正なし
56
+ #
57
+ def invalid?
58
+ gengou.invalid?
59
+ end
60
+
61
+ #
62
+ # 範囲内か
63
+ #
64
+ # @param [Western::Calendar] date 西暦日
65
+ #
66
+ # @return [True] 範囲内
67
+ # @return [False] 範囲外
68
+ #
69
+ def include?(date: Western::Calendar.new)
70
+ return false if invalid?
71
+
72
+ return false if start_date.invalid?
73
+
74
+ return false if last_date.invalid?
75
+
76
+ return false if date < start_date
77
+
78
+ return false if date > last_date
79
+
80
+ true
81
+ end
82
+
83
+ #
84
+ # 完全に範囲内か
85
+ #
86
+ # @param [Western::Calendar] start_date 開始日
87
+ # @param [Western::Calendar] last_date 終了日
88
+ #
89
+ # @return [True] 範囲内
90
+ # @return [False] 範囲外あり
91
+ #
92
+ def in?(start_date:, last_date:)
93
+ inner_start_date = @start_date
94
+ inner_last_date = @last_date
95
+ inner_start_date <= start_date && last_date <= inner_last_date
96
+ end
97
+
98
+ #
99
+ # 完全に範囲外か
100
+ #
101
+ # @param [Western::Calendar] start_date 開始日
102
+ # @param [Western::Calendar] last_date 終了日
103
+ #
104
+ # @return [True] 範囲外
105
+ # @return [False] 範囲内あり
106
+ #
107
+ def out?(start_date:, last_date:)
108
+ inner_start_date = @start_date
109
+ inner_last_date = @last_date
110
+ # 範囲より前
111
+ return true if start_date < inner_start_date && last_date < inner_start_date
112
+
113
+ # 範囲より後
114
+ return true if inner_last_date < start_date && inner_last_date < last_date
115
+
116
+ false
117
+ end
118
+
119
+ #
120
+ # 完全に範囲を超えているか
121
+ #
122
+ # @param [Western::Calendar] start_date 開始日
123
+ # @param [Western::Calendar] last_date 終了日
124
+ #
125
+ # @return [True] 完全超過
126
+ # @return [True] 完全超過せず
127
+ #
128
+ def covered?(start_date:, last_date:)
129
+ inner_start_date = @start_date
130
+ inner_last_date = @last_date
131
+ start_date < inner_start_date && inner_last_date < last_date
132
+ end
133
+
134
+ #
135
+ # 元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?
136
+ #
137
+ # @return [True] 存在する
138
+ # @return [False] 存在しない
139
+ #
140
+ def changed?
141
+ return true if change_start_date?
142
+
143
+ return true if change_last_date?
144
+
145
+ false
146
+ end
147
+
148
+ #
149
+ # 開始日が設定された開始日と異なるか(行が変更されているか)
150
+ #
151
+ # @return [True] 異なる
152
+ # @return [False] 同一
153
+ #
154
+ def change_start_date?
155
+ return false if invalid?
156
+
157
+ start_date != native_start_date
158
+ end
159
+
160
+ #
161
+ # 終了日が設定された終了日と異なるか(行が変更されているか)
162
+ #
163
+ # @return [True] 異なる
164
+ # @return [False] 同一
165
+ #
166
+ def change_last_date?
167
+ return false if invalid?
168
+
169
+ last_date != native_last_date
170
+ end
171
+
172
+ #
173
+ # 設定された元号の開始日を取得する
174
+ #
175
+ # @return [Western::Calendar]設定された元号の開始日
176
+ #
177
+ def native_start_date
178
+ gengou.both_start_date.western
179
+ end
180
+
181
+ #
182
+ # 設定された元号の終了日を取得する
183
+ #
184
+ # @return [Western::Calendar] 設定された元号の終了日
185
+ #
186
+ def native_last_date
187
+ gengou.last_date
188
+ end
180
189
  end
181
190
  end
182
191
  end