StepValueValidator
This class validates that a given value is a multiple of a specified step size, optionally starting from a defined offset. It extends the base validation framework to ensure numerical consistency and raises a validation error with descriptive parameters if the value does not align with the required increments. The validator supports custom error messages and uses high-precision comparison to handle floating-point remainders.
Attributes
| Attribute | Type | Description |
|---|---|---|
| message | string = "Ensure this value is a multiple of step size %(limit_value)s." | The error message template used when the validated value is not a multiple of the step size. |
| code | string = "step_size" | The specific error code identifier used to categorize the validation failure. |
Constructor
Signature
def StepValueValidator(
limit_value: any,
message: string = None,
offset: any = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| limit_value | any | The step size that the value must be a multiple of. |
| message | string = None | An optional custom error message to override the default. |
| offset | any = None | An optional starting point from which the step size multiples are calculated. |
Signature
def StepValueValidator(
limit_value: any,
message: string = null,
offset: any = null
)
Parameters
| Name | Type | Description |
|---|---|---|
| limit_value | any | The step size increment that values must be a multiple of. |
| message | string = null | An optional custom error message to override the default validation failure text. |
| offset | any = null | The starting numeric value from which steps are calculated; if provided, valid values follow the sequence offset + (n * limit_value). |
Methods
compare()
@classmethod
def compare(
a: any,
b: any
) - > boolean
Performs the mathematical check to determine if the difference between the input value and the offset is a multiple of the step size.
Parameters
| Name | Type | Description |
|---|---|---|
| a | any | The cleaned input value to be checked. |
| b | any | The step size (limit_value) used as the divisor for the remainder check. |
Returns
| Type | Description |
|---|---|
boolean | Returns True if the value is NOT a multiple of the step size (indicating a validation failure), and False otherwise. |