You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
887 B
25 lines
887 B
from luscenje_struktur.restriction import Restriction
|
|
|
|
class RestrictionGroup:
|
|
def __init__(self, restrictions_tag, system_type, group_type='and'):
|
|
self.restrictions = [Restriction(el, system_type) 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'")
|