def att(self, **kwargs):
"""Apply functions on attributes of references of files of the object.
Each argument is made of a function name and its expected value.
Each function can be prefixed with 'not_', like in the next example.
The given value is a tuple with (identifier, value) of the attribute.
:Example:
>>> f.att(equals=("age", "14"))
:param kwargs: logic_bool/any sppasAttCompare() method.
:returns: (sppasDataSet) Set of FileName() instances
"""
comparator = sppasRefAttributeCompare()
sppasBaseFilters.test_args(comparator, **kwargs)
logic_bool = sppasBaseFilters.fix_logic_bool(**kwargs)
att_fct_values = sppasBaseFilters.fix_function_values(comparator, **kwargs)
att_functions = sppasBaseFilters.fix_functions(comparator, **kwargs)
data = sppasBaseSet()
for fp in self.obj.get_paths():
for fr in fp:
matches = [False] * len(att_functions)
for ref in fr.get_references():
for i, a in enumerate(att_functions):
func, value, logical_not = a
for att in ref:
mm = False
try:
searched = sppasRefAttribute(value[0], value[1], att.get_value_type())
if att.get_id() == searched.get_id():
if logical_not is True:
mm = not func(att, searched.get_typed_value())
else:
mm = func(att, searched.get_typed_value())
if mm is True:
matches[i] = True
break
except ValueError:
continue
if logic_bool == 'and':
is_matching = all(matches)
else:
is_matching = any(matches)
if is_matching is True:
for fn in fr:
data.append(fn, att_fct_values)
return data