Skip to main content

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

AttributeTypeDescription
messagestring = "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.
codestring = "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

NameTypeDescription
limit_valueanyThe step size that the value must be a multiple of.
messagestring = NoneAn optional custom error message to override the default.
offsetany = NoneAn optional starting point from which the step size multiples are calculated.

Signature

def StepValueValidator(
limit_value: any,
message: string = null,
offset: any = null
)

Parameters

NameTypeDescription
limit_valueanyThe step size increment that values must be a multiple of.
messagestring = nullAn optional custom error message to override the default validation failure text.
offsetany = nullThe 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

NameTypeDescription
aanyThe cleaned input value to be checked.
banyThe step size (limit_value) used as the divisor for the remainder check.

Returns

TypeDescription
booleanReturns True if the value is NOT a multiple of the step size (indicating a validation failure), and False otherwise.