Class: Lutaml::Xsd::Validation::BaseTypes::DecimalValidator
- Inherits:
-
BaseTypeValidator
- Object
- BaseTypeValidator
- Lutaml::Xsd::Validation::BaseTypes::DecimalValidator
- Defined in:
- lib/lutaml/xsd/validation/base_types/decimal_validator.rb
Overview
Validates XSD decimal type
The decimal type represents arbitrary-precision decimal numbers. Valid values include integers and decimals with optional sign.
Constant Summary collapse
- DECIMAL_PATTERN =
Pattern for valid decimal format Using possessive quantifiers to prevent polynomial backtracking
/^[+-]?(?>\d++\.?\d*|\.\d+)$/
Instance Method Summary collapse
-
#error_message(value) ⇒ String
Generate error message for invalid decimal.
-
#valid?(value) ⇒ Boolean
Validate value is a valid decimal.
Methods inherited from BaseTypeValidator
Instance Method Details
#error_message(value) ⇒ String
Generate error message for invalid decimal
54 55 56 |
# File 'lib/lutaml/xsd/validation/base_types/decimal_validator.rb', line 54 def (value) "Value '#{value}' is not a valid decimal number" end |
#valid?(value) ⇒ Boolean
Validate value is a valid decimal
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lutaml/xsd/validation/base_types/decimal_validator.rb', line 33 def valid?(value) return false if value.nil? return true if value.is_a?(Numeric) str = to_string(value).strip return false if str.empty? # Check pattern first for performance return false unless str.match?(DECIMAL_PATTERN) # Verify it can be parsed as Float Float(str) true rescue ArgumentError, TypeError false end |