Completed
Push — master ( 00dd46...452f18 )
by P.R.
01:48
created

RegularExpressionCondition.scheme()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
"""
2
ETLT
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8 1
import re
9
10 1
from etlt.condition.SimpleCondition import SimpleCondition
11
12
13 1
class RegularExpressionCondition(SimpleCondition):
14
    """
15
    A regular expression condition matches a field in the row against a regular expression expression.
16
    """
17
18
    # ------------------------------------------------------------------------------------------------------------------
19 1
    def match(self, row):
20
        """
21
        Returns True if the field matches the regular expression of this simple condition. Returns False otherwise.
22
23
        :param dict row: The row.
24
25
        :rtype: bool
26
        """
27 1
        if re.search(self._expression, row[self._field]):
28 1
            return True
29
30 1
        return False
31
32
    # ------------------------------------------------------------------------------------------------------------------
33 1
    @property
34
    def scheme(self):
35
        """
36
        Returns 're'.
37
38
        :rtype: str
39
        """
40 1
        return 're'
41
42
# ----------------------------------------------------------------------------------------------------------------------
43