def match(self, tag_functions, logic_bool='and'):
"""Return True if a tag matches all or any of the functions.
:param tag_functions: list of (function, value, logical_not)
:param logic_bool: (str) Apply a logical "and" or a logical "or" between the functions.
:returns: (bool)
- function: a function in python with 2 arguments: tag/value
- value: the expected value for the tag
- logical_not: boolean
:Example: Search if a tag is exactly matching "R":
>>> l.match([(exact, "R", False)])
:Example: Search if a tag is starting with "p" or starting with "t":
>>> l.match([(startswith, "p", False),
>>> (startswith, "t", False), ], logic_bool="or")
"""
is_matching = False
for tag, score in self.__tags:
matches = list()
for func, value, logical_not in tag_functions:
if logical_not is True:
matches.append(not func(tag, value))
else:
matches.append(func(tag, value))
if logic_bool == 'and':
is_matching = all(matches)
else:
is_matching = any(matches)
if is_matching is True:
return True
return is_matching