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