Passed
Branch master (17b603)
by P.R.
01:31
created

etlt.cleaner.MoneyCleaner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 75 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 33
loc 44
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A MoneyCleaner.clean() 27 27 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"""
2
ETLT
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8 1
import re
9
10
11 1 View Code Duplication
class MoneyCleaner:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
    """
13
    Utility class for converting numbers to numbers with decimal points.
14
    """
15
16
    # ------------------------------------------------------------------------------------------------------------------
17 1
    @staticmethod
18 1
    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]{1,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]{1,2}$', amount):
35
            # Assume amount is in 1,123.12 format (Engels).
36 1
            return amount.replace(',', '').replace(' ', '')
37
38 1
        if re.search(r'[0-9](,[0-9]{1,2}$)', amount):
39
            # Assume amount is in 123,12 or in 123,1 format (Dutch).
40 1
            return amount.replace(',', '.')
41
42
        # Format of amount is not recognized. Return amount.
43 1
        return amount
44
45
# ----------------------------------------------------------------------------------------------------------------------
46