Total Complexity | 3 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 1 | import re |
|
2 | 1 | import inspect |
|
3 | |||
4 | 1 | def get_service_subject_identifier(service_subject): |
|
5 | """Get the snake_case identifier of the service_subject |
||
6 | |||
7 | :param service_subject: Service subject |
||
8 | :type service_subject: mixed |
||
9 | :return: snake case name of the service subject |
||
10 | :rtype: str |
||
11 | """ |
||
12 | 1 | if inspect.isclass(service_subject) is True: |
|
13 | 1 | subject_name = service_subject.__name__ |
|
14 | else: |
||
15 | 1 | subject_name = service_subject.__class__.__name__ |
|
16 | 1 | return convert_camel_to_snake(subject_name) |
|
17 | |||
18 | 1 | def convert_camel_to_snake(value): |
|
19 | """Convert string from CamelCase to snake_case |
||
20 | |||
21 | :param value: CamelCase value |
||
22 | :type value: str |
||
23 | :return: snake_case converted value |
||
24 | :rtype: str |
||
25 | """ |
||
26 | s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', value) |
||
27 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() |