snakelet.utilities.conversion.camel()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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