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
Compares 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 typeT
must be passed to thecompare
method. When False, reference files given to thecompare
method 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
Field
representing the property to extract the comparison value from when anMusifyItem
is givenWhether to raise an exception when
compare()
is called and a reference object is not provided.Methods:
compare
(item[, reference])Compare a
item
to areference
or, if noreference
is given, to this object's list ofexpected
valuesas_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
Field
representing the property to extract the comparison value from when anMusifyItem
is 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
item
to areference
or, if noreference
is given, to this object’s list ofexpected
values- 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