parent
6dd97838b4
commit
c63a9d47da
@ -0,0 +1,24 @@
|
|||||||
|
from luscenje_struktur.restriction import Restriction
|
||||||
|
|
||||||
|
class RestrictionGroup:
|
||||||
|
def __init__(self, restrictions_tag, group_type='and'):
|
||||||
|
self.restrictions = [Restriction(el) for el in restrictions_tag]
|
||||||
|
self.group_type = group_type
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
for restriction in self.restrictions:
|
||||||
|
yield restriction
|
||||||
|
|
||||||
|
def match(self, word):
|
||||||
|
if self.group_type == 'or':
|
||||||
|
for restr in self.restrictions:
|
||||||
|
if restr.match(word): # match either
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
elif self.group_type == 'and':
|
||||||
|
for restr in self.restrictions:
|
||||||
|
if not restr.match(word): # match and
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise Exception("Unsupported group_type - it may only be 'and' or 'or'")
|
Loading…
Reference in new issue