WhitespaceCleaner.clean()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 1
dl 0
loc 12
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
from typing import Optional
2
3
4
class WhitespaceCleaner:
5
    """
6
    Utility class for cleaning whitespace from strings.
7
    """
8
9
    # ------------------------------------------------------------------------------------------------------------------
10
    @staticmethod
11
    def clean(string: Optional[str]) -> Optional[str]:
12
        """
13
        Prunes whitespace from a string.
14
15
        :param string: The string.
16
        """
17
        # Return empty input immediately.
18
        if not string:
19
            return string
20
21
        return string.replace('  ', ' ').strip()
22
23
# ----------------------------------------------------------------------------------------------------------------------
24