snakelet.utilities.conversion   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
A camel() 0 6 1
A snake() 0 6 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Conversion.encode() 0 6 1
A Conversion.__init__() 0 5 2
1
import re
2
3
4
def snake(string: str):
5
    """
6
    :param string:
7
    :return:
8
    """
9
    return re.sub("([A-Z])", "_\\1", string).lower().lstrip("_")
10
11
12
def camel(string: str):
13
    """
14
    :param string:
15
    :return:
16
    """
17
    return "".join(map(str.capitalize, string.split("_")))
18
19
20
class Conversion:
21
    cases = {
22
        'snake': snake,
23
        'camel': camel
24
    }
25
26
    def __init__(self, case: str = None):
27
        """
28
        :param case:
29
        """
30
        self.case = self.cases['snake' if not case or case not in self.cases else case]
31
32
    def encode(self, data: str):
33
        """
34
        :param data:
35
        :return:
36
        """
37
        return self.case(data)
38