Total Complexity | 6 |
Total Lines | 69 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | """ |
||
11 | class InListCondition(Condition): |
||
12 | """ |
||
13 | A list condition matches a single field against a list of values. |
||
14 | """ |
||
15 | |||
16 | # ------------------------------------------------------------------------------------------------------------------ |
||
17 | def __init__(self, field, values): |
||
18 | """ |
||
19 | Object contructor. |
||
20 | |||
21 | :param str field: The name of the field in the row that must be match against the expression. |
||
22 | :param list[str] values: The list of values. |
||
23 | """ |
||
24 | self._field = field |
||
25 | """ |
||
26 | The name of the field in the row that must be match against the list of values. |
||
27 | |||
28 | :type str: |
||
29 | """ |
||
30 | |||
31 | self._values = values |
||
32 | """ |
||
33 | The list of values. |
||
34 | |||
35 | :type list[str]: |
||
36 | """ |
||
37 | |||
38 | # ------------------------------------------------------------------------------------------------------------------ |
||
39 | @property |
||
40 | def field(self): |
||
41 | """ |
||
42 | Getter for field. |
||
43 | |||
44 | :rtype: str |
||
45 | """ |
||
46 | return self._field |
||
47 | |||
48 | # ------------------------------------------------------------------------------------------------------------------ |
||
49 | @property |
||
50 | def values(self): |
||
51 | """ |
||
52 | Getter for values. |
||
53 | |||
54 | :rtype: list[str] |
||
55 | """ |
||
56 | return self._values |
||
57 | |||
58 | # ------------------------------------------------------------------------------------------------------------------ |
||
59 | def populate_values(self, rows, field): |
||
60 | """ |
||
61 | Populates the filter values of this filter using list of rows. |
||
62 | |||
63 | :param list[dict[str,T]] rows: The row set. |
||
64 | :param str field: The field name. |
||
65 | """ |
||
66 | self._values.clear() |
||
67 | for row in rows: |
||
68 | self._values.append(row[field]) |
||
69 | |||
70 | # ------------------------------------------------------------------------------------------------------------------ |
||
71 | def match(self, row): |
||
72 | """ |
||
73 | Returns True if the field is in the list of values. Returns False otherwise. |
||
74 | |||
75 | :param dict row: The row. |
||
76 | |||
77 | :rtype: bool |
||
78 | """ |
||
79 | return row[self._field] in self._values |
||
80 | |||
82 |