Class: Lutaml::Xsd::Validation::Facets::MaxLengthFacetValidator
- Inherits:
-
FacetValidator
- Object
- FacetValidator
- Lutaml::Xsd::Validation::Facets::MaxLengthFacetValidator
- Defined in:
- lib/lutaml/xsd/validation/facets/max_length_facet_validator.rb
Overview
Validates values against XSD maxLength facet
The maxLength facet specifies the maximum length of a value. For strings, it’s the maximum number of characters. For lists, it’s the maximum number of items.
Instance Attribute Summary
Attributes inherited from FacetValidator
Instance Method Summary collapse
-
#error_message(value) ⇒ String
Generate error message for maximum length violation.
-
#valid?(value) ⇒ Boolean
Validate value meets maximum length.
Methods inherited from FacetValidator
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 length violation
41 42 43 44 45 |
# File 'lib/lutaml/xsd/validation/facets/max_length_facet_validator.rb', line 41 def (value) actual_length = value.nil? ? 0 : to_string(value).length "Value length #{actual_length} exceeds maximum " \ "length #{facet_value}" end |
#valid?(value) ⇒ Boolean
Validate value meets maximum length
28 29 30 31 32 33 34 35 |
# File 'lib/lutaml/xsd/validation/facets/max_length_facet_validator.rb', line 28 def valid?(value) return false if value.nil? max_length = to_integer(facet_value) return false unless max_length to_string(value).length <= max_length end |