Compare
Processor making comparisons between objects and data types.
Classes:
|
Compares an item or object with another item, object or a given set of expected values to find a match. |
- class musify.processors.compare.Comparer(condition, expected=None, field=None, reference_required=False)
Bases:
DynamicProcessor,HashableCompares an item or object with another item, object or a given set of expected values to find a match.
- Parameters:
condition (
str) – The condition to match on e.g. Is, LessThan, InRange, Contains.expected (
GenericAlias[Any] |None(default:None)) – Optional list of expected values to match on. Types of the values in this list are automatically converted to the type of the item field’s value.field (
Field|None(default:None)) – The field to match on.reference_required (
bool(default:False)) – When True, a reference object of typeTmust be passed to thecomparemethod. When False, reference files given to thecomparemethod will be ignored. An exception will be raised if this is True and reference object is not passed.
Attributes:
String representation of the current condition name of this object
A list of expected values used for most conditions
The
Fieldrepresenting the property to extract the comparison value from when anMusifyItemis givenWhether to raise an exception when
compare()is called and a reference object is not provided.Methods:
compare(item[, reference])Compare a
itemto areferenceor, if noreferenceis given, to this object's list ofexpectedvaluesas_dict()Return a dictionary representation of the key attributes of this object.
- property condition: str
String representation of the current condition name of this object
- property expected: list[Any] | None
A list of expected values used for most conditions
-
field:
Field|None The
Fieldrepresenting the property to extract the comparison value from when anMusifyItemis given
- reference_required
Whether to raise an exception when
compare()is called and a reference object is not provided.
- compare(item, reference=None)
Compare a
itemto areferenceor, if noreferenceis given, to this object’s list ofexpectedvalues- Returns:
bool– True if a match is found, False otherwise.- Raises:
LocalProcessorError – If no reference given and no expected values set for this comparer.
- as_dict()
Return a dictionary representation of the key attributes of this object.
- The results of this function are used to produce the following:
A JSON representation of the object when calling
json()The string representation of the object when calling str() on the object
The representation of the object when calling repr() on the object