1 | <?php |
||
13 | class GeezConverter extends Converter |
||
14 | { |
||
15 | /** |
||
16 | * Convert an ascii number like <b>1, 21, 3456</b> to |
||
17 | * geez number <b>፩, ፳፩, ፴፬፻፶፮</b>. |
||
18 | * |
||
19 | * @param int $ascii_number |
||
20 | * |
||
21 | * @throws NotAnIntegerArgumentException if the number is not an integer |
||
22 | * |
||
23 | * @return string |
||
24 | */ |
||
25 | 99 | public function convert($ascii_number) |
|
37 | |||
38 | /** |
||
39 | * - Validate the number |
||
40 | * - Convert the number to a string |
||
41 | * - Get the length of the number |
||
42 | * - Prepend a space if the length is odd. |
||
43 | * |
||
44 | * @param $ascii_number |
||
45 | * |
||
46 | * @throws \Geezify\Exception\NotAnIntegerArgumentException |
||
47 | * |
||
48 | * @return array the $number and the $length |
||
49 | */ |
||
50 | 99 | protected function prepareForConversion($ascii_number) |
|
66 | |||
67 | /** |
||
68 | * Validate if the number is ascii number. |
||
69 | * |
||
70 | * @param $ascii_number |
||
71 | * |
||
72 | * @throws NotAnIntegerArgumentException |
||
73 | * |
||
74 | * @return int |
||
75 | */ |
||
76 | 99 | protected function validateAsciiNumber($ascii_number) |
|
84 | |||
85 | /** |
||
86 | * Prepend space if the length of the number is odd. |
||
87 | * |
||
88 | * @param $ascii_number |
||
89 | * @param $length |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 91 | protected function prependSpaceIfLengthIsEven($ascii_number, $length) |
|
101 | |||
102 | /** |
||
103 | * Is a number odd? |
||
104 | * |
||
105 | * @param $ascii_number |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | 91 | protected function isOdd($ascii_number) |
|
113 | |||
114 | /** |
||
115 | * Is a number even? |
||
116 | * |
||
117 | * @param $number |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | 91 | protected function isEven($number) |
|
125 | |||
126 | /** |
||
127 | * Parse each two character block. |
||
128 | * |
||
129 | * @param $number |
||
130 | * @param $index |
||
131 | * @param $length |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 91 | protected function parseEachTwoCharactersBlock($number, $index, $length) |
|
145 | |||
146 | /** |
||
147 | * Fetch the two character (00-99) block and convert it to geez. |
||
148 | * |
||
149 | * @param $number |
||
150 | * @param $index |
||
151 | * |
||
152 | * @return string geez two character block |
||
153 | */ |
||
154 | 91 | protected function getGeezNumberOfTheBlock($number, $index) |
|
164 | |||
165 | /** |
||
166 | * Fetch two characters from the $number starting from $index. |
||
167 | * |
||
168 | * @param $number string the whole ascii number |
||
169 | * @param $index integer the starting position |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | 91 | protected function getBlock($number, $index) |
|
177 | |||
178 | /** |
||
179 | * The ቤት of the block. |
||
180 | * |
||
181 | * @param $length integer the length of the ascii number |
||
182 | * @param $index integer the character index |
||
183 | * |
||
184 | * @return int |
||
185 | */ |
||
186 | 91 | protected function getBet($length, $index) |
|
194 | |||
195 | /** |
||
196 | * Get the separator depending on the bet. |
||
197 | * |
||
198 | * @param $bet |
||
199 | * |
||
200 | * @return string return ፻,፼ or empty character |
||
201 | */ |
||
202 | 91 | protected function getGeezSeparator($bet) |
|
212 | |||
213 | /** |
||
214 | * Combines the block and the separator. |
||
215 | * |
||
216 | * @param string $geez_number |
||
217 | * @param string $separator |
||
218 | * @param int $index of the block |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | 91 | protected function combineBlockAndSeparator( |
|
237 | |||
238 | /** |
||
239 | * Returns true if the block is empty and the separator is 100. |
||
240 | * |
||
241 | * @param string $block |
||
242 | * @param string $separator |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | 91 | protected function shouldRemoveGeezSeparator($block, $separator) |
|
252 | |||
253 | /** |
||
254 | * Returns true if the ascii number is 100 or |
||
255 | * if the ascii number is the leading 10000. |
||
256 | * |
||
257 | * @param $block |
||
258 | * @param $separator |
||
259 | * @param $index |
||
260 | * |
||
261 | * @return bool |
||
262 | */ |
||
263 | 91 | protected function shouldRemoveGeezNumberBlock($block, $separator, $index) |
|
269 | |||
270 | /** |
||
271 | * Returns true if the number is 100. |
||
272 | * |
||
273 | * @param $block |
||
274 | * @param $separator |
||
275 | * |
||
276 | * @return bool |
||
277 | */ |
||
278 | 91 | protected function isOneHundred($block, $separator) |
|
284 | |||
285 | /** |
||
286 | * Returns true if the number is the leading 10000. |
||
287 | * |
||
288 | * @param $block |
||
289 | * @param $separator |
||
290 | * @param $index |
||
291 | * |
||
292 | * @return bool |
||
293 | */ |
||
294 | 91 | protected function isLeadingTenThousand($block, $separator, $index) |
|
301 | } |
||
302 |