Total Complexity | 11 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 95.65% |
Changes | 0 |
1 | 1 | import logging |
|
2 | 1 | from enum import Enum |
|
3 | |||
4 | 1 | logger = logging.getLogger(__name__) |
|
5 | |||
6 | |||
7 | 1 | class Code: |
|
8 | 1 | def __init__(self, code, description): |
|
9 | 1 | self.code = code |
|
10 | 1 | self.description = description |
|
11 | |||
12 | 1 | def __str__(self): |
|
13 | 1 | if self.description is None: |
|
14 | 1 | return self.code |
|
15 | 1 | if isinstance(self.description, list): |
|
16 | 1 | return str(self.code) + " - " + "; ".join(self.description) |
|
17 | 1 | return str(self.code) + " - " + str(self.description) |
|
18 | |||
19 | def __repr__(self): |
||
20 | # return '%s.%s(%s)' % (self.__class__.__module__, |
||
21 | # self.__class__.__qualname__, |
||
22 | # f'{repr(self.code)}, {repr(self.description)}') |
||
23 | |||
24 | return '%s(%s)' % ( |
||
25 | self.__class__.__qualname__, |
||
26 | f'{repr(self.code)}, {repr(self.description)}' |
||
27 | ) |
||
28 | |||
29 | 1 | def __eq__(self, other): |
|
30 | 1 | if isinstance(other, Code): |
|
31 | 1 | return self.code == other.code |
|
32 | 1 | if isinstance(other, str) or isinstance(other, int): |
|
33 | 1 | return self.code == other |
|
34 | 1 | if isinstance(other, Enum): |
|
35 | 1 | return self.code == other.value |
|
36 | return NotImplemented |
||
37 | |||
38 | 1 | def __hash__(self): |
|
39 | 1 | return self.code.__hash__() |
|
40 | |||
42 |