Passed
Push — main ( 9d548b...bc1b05 )
by Frederik
01:24
created

luckywood.string.String.decode_to_url()   A

Complexity

Conditions 2

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 27
rs 9.352
c 0
b 0
f 0
cc 2
nop 1
1
"""
0 ignored issues
show
Documentation introduced by
Empty module docstring
Loading history...
2
3
"""
4
5
__author__ = "Glücks GmbH - Frederik Glücks"
6
__email__ = "[email protected]"
7
__copyright__ = "Copyright 2020, Glücks GmbH"
8
9
10
# Generic/Built-in Imports
11
import re
12
from typing import Dict
13
14
15
class String:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
16
17
    @staticmethod
18
    def decode_to_url(raw_string: str) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
19
        url_string = raw_string.lower()
20
21
        decode_chars: Dict[str, str] = {
22
            ", ": "_",
23
            "+": "_",
24
            "/": "_",
25
            " ": "_",
26
            "ä": "ae",
27
            "ü": "ue",
28
            "ö": "oe",
29
            "ß": "ss",
30
            ",": ".",
31
            "é": "e",
32
            "&": "",
33
            "(": "",
34
            ")": ""
35
        }
36
37
        for char in decode_chars:
38
            url_string = url_string.replace(char, decode_chars[char])
39
40
        url_string = re.sub(r"([^a-z0-9_\-.]*)", "", url_string)
41
        url_string = re.sub(r"([_]+)", "_", url_string)
42
43
        return url_string
44