| Total Complexity | 5 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | """ |
||
| 11 | 1 | class MoneyCleaner: |
|
| 12 | """ |
||
| 13 | Utility class for converting numbers to numbers with decimal points. |
||
| 14 | """ |
||
| 15 | |||
| 16 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 17 | 1 | @staticmethod |
|
| 18 | def clean(amount): |
||
| 19 | """ |
||
| 20 | Converts a number to a number with decimal point. |
||
| 21 | |||
| 22 | :param str amount: The input number. |
||
| 23 | |||
| 24 | :rtype str: |
||
| 25 | """ |
||
| 26 | # Return empty input immediately. |
||
| 27 | 1 | if not amount: |
|
| 28 | 1 | return amount |
|
| 29 | |||
| 30 | 1 | if re.search(r'[\. ][0-9]{3},[0-9]{2}$', amount): |
|
| 31 | # Assume amount is in 1.123,12 or 1 123,12 format (Dutch). |
||
| 32 | 1 | return amount.replace('.', '').replace(' ', '').replace(',', '.') |
|
| 33 | |||
| 34 | 1 | if re.search(r'[, ][0-9]{3}\.[0-9]{2}$', amount): |
|
| 35 | # Assume amount is in 1,123.12 or in 1 123.12 format (Engels). |
||
| 36 | 1 | return amount.replace(',', '').replace(' ', '') |
|
| 37 | |||
| 38 | 1 | if re.search(r'[0-9](,[0-9]{2}$)', amount): |
|
| 39 | # Assume amount is in 123,12 format (Dutch). |
||
| 40 | 1 | return amount.replace(',', '.') |
|
| 41 | |||
| 42 | # Format of amount is not recognized. Return amount. |
||
| 43 | 1 | return amount |
|
| 44 | |||
| 46 |