Class: Lutaml::Xsd::Validation::Facets::MaxExclusiveFacetValidator

Inherits:
FacetValidator
  • Object
show all
Defined in:
lib/lutaml/xsd/validation/facets/max_exclusive_facet_validator.rb

Overview

Validates values against XSD maxExclusive facet

The maxExclusive facet specifies the maximum value (exclusive) for numeric types.

Examples:

Validating maximum exclusive

facet = Lutaml::Xsd::MaxExclusive.new(value: "100")
validator = MaxExclusiveFacetValidator.new(facet)
validator.valid?("100")  # => false (100 == 100)
validator.valid?("99")   # => true (99 < 100)
validator.valid?("150")  # => false (150 > 100)
validator.error_message("150")
# => "Value 150 is not less than maximum exclusive value 100"

Instance Attribute Summary

Attributes inherited from FacetValidator

#facet

Instance Method Summary collapse

Methods inherited from FacetValidator

#facet_value, #initialize

Constructor Details

This class inherits a constructor from Lutaml::Xsd::Validation::Facets::FacetValidator

Instance Method Details

#error_message(value) ⇒ String

Generate error message for maximum exclusive violation

Parameters:

  • value (String, Numeric)

    The invalid value

Returns:

  • (String)

    Error message describing the violation



43
44
45
46
# File 'lib/lutaml/xsd/validation/facets/max_exclusive_facet_validator.rb', line 43

def error_message(value)
  "Value #{value} is not less than maximum exclusive value " \
    "#{facet_value}"
end

#valid?(value) ⇒ Boolean

Validate value is < maximum

Parameters:

  • value (String, Numeric)

    The value to validate

Returns:

  • (Boolean)

    true if value < maximum, false otherwise



28
29
30
31
32
33
34
35
36
37
# File 'lib/lutaml/xsd/validation/facets/max_exclusive_facet_validator.rb', line 28

def valid?(value)
  return false if value.nil?

  numeric_value = to_numeric(value)
  max_value = to_numeric(facet_value)

  return false unless numeric_value && max_value

  numeric_value < max_value
end