| Total Complexity | 12 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # pyre-strict |
||
|
|
|||
| 2 | |||
| 3 | from re import compile as compile_regex |
||
| 4 | from typing import List, Any |
||
| 5 | |||
| 6 | import iso4217parse |
||
| 7 | |||
| 8 | |||
| 9 | class PaymentText: |
||
| 10 | text: str = '' |
||
| 11 | |||
| 12 | def __init__(self, text: str) -> None: |
||
| 13 | self.text = text |
||
| 14 | |||
| 15 | def __repr__(self) -> str: |
||
| 16 | return self.text |
||
| 17 | |||
| 18 | def clean(self) -> None: |
||
| 19 | parts: List[str] = self.text.split() |
||
| 20 | |||
| 21 | pattern = compile_regex(r'\*\d{4}') |
||
| 22 | |||
| 23 | try: |
||
| 24 | if pattern.match(parts[0]): |
||
|
1 ignored issue
–
show
|
|||
| 25 | del parts[0] |
||
| 26 | except IndexError: |
||
| 27 | return |
||
| 28 | |||
| 29 | pattern = compile_regex(r'\d{2}\.\d{2}') |
||
| 30 | |||
| 31 | if pattern.match(parts[0]): |
||
| 32 | del parts[0] |
||
| 33 | |||
| 34 | currency: Any = iso4217parse.by_alpha3(parts[0]) |
||
| 35 | |||
| 36 | if isinstance(currency, iso4217parse.Currency): |
||
|
1 ignored issue
–
show
|
|||
| 37 | del parts[0] |
||
| 38 | del parts[0] |
||
| 39 | |||
| 40 | pattern = compile_regex(r'\d{1}\.\d{4}') |
||
| 41 | |||
| 42 | if pattern.match(parts[-1]): |
||
| 43 | del parts[-1] |
||
| 44 | del parts[-1] |
||
| 45 | |||
| 46 | pattern = compile_regex(r'\d{2}\.\d{2}\.\d{2}') |
||
| 47 | |||
| 48 | if pattern.match(parts[-1]): |
||
| 49 | del parts[-1] |
||
| 50 | |||
| 51 | pattern = compile_regex(r'.+:') |
||
| 52 | |||
| 53 | if pattern.match(parts[-1]): |
||
| 54 | del parts[-1] |
||
| 55 | |||
| 56 | pattern = compile_regex(r'\d+,\d{2}') |
||
| 57 | |||
| 58 | if pattern.match(parts[-1]): |
||
| 59 | del parts[-1] |
||
| 60 | |||
| 61 | currency: Any = iso4217parse.by_alpha3(parts[-1]) |
||
| 62 | if isinstance(currency, iso4217parse.Currency): |
||
| 63 | del parts[-1] |
||
| 64 | |||
| 65 | text = ' '.join(parts) |
||
| 66 | |||
| 67 | self.text = text |
||
| 68 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.