Total Complexity | 3 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 1 | import re |
|
2 | from typing import Any, Dict |
||
3 | 1 | ||
4 | from etlt.condition.SimpleCondition import SimpleCondition |
||
5 | |||
6 | 1 | ||
7 | class RegularExpressionCondition(SimpleCondition): |
||
8 | """ |
||
9 | A regular expression condition matches a field in the row against a regular expression expression. |
||
10 | """ |
||
11 | |||
12 | 1 | # ------------------------------------------------------------------------------------------------------------------ |
|
13 | def match(self, row: Dict[str, Any]) -> bool: |
||
14 | """ |
||
15 | Returns True if the field matches the regular expression of this simple condition. Returns False otherwise. |
||
16 | |||
17 | :param row: The row. |
||
18 | """ |
||
19 | if re.search(self._expression, row[self._field]): |
||
20 | 1 | return True |
|
21 | 1 | ||
22 | return False |
||
23 | 1 | ||
24 | # ------------------------------------------------------------------------------------------------------------------ |
||
25 | @property |
||
26 | 1 | def scheme(self) -> str: |
|
27 | 1 | """ |
|
28 | Returns 're'. |
||
29 | """ |
||
30 | return 're' |
||
31 | |||
33 |