Class: Lutaml::Xsd::Validation::BaseTypes::BooleanValidator
- Inherits:
-
BaseTypeValidator
- Object
- BaseTypeValidator
- Lutaml::Xsd::Validation::BaseTypes::BooleanValidator
- Defined in:
- lib/lutaml/xsd/validation/base_types/boolean_validator.rb
Overview
Validates XSD boolean type
The boolean type accepts the following values:
- true, false (literal boolean values)
- "true", "false" (string representations)
- "1", "0" (numeric representations)
Constant Summary collapse
- VALID_VALUES =
%w[true false 1 0].freeze
Instance Method Summary collapse
-
#error_message(value) ⇒ String
Generate error message for invalid boolean.
-
#valid?(value) ⇒ Boolean
Validate value is a valid boolean.
Methods inherited from BaseTypeValidator
Instance Method Details
#error_message(value) ⇒ String
Generate error message for invalid boolean
44 45 46 47 |
# File 'lib/lutaml/xsd/validation/base_types/boolean_validator.rb', line 44 def (value) "Value '#{value}' is not a valid boolean. " \ "Expected: true, false, 1, or 0" end |
#valid?(value) ⇒ Boolean
Validate value is a valid boolean
33 34 35 36 37 38 |
# File 'lib/lutaml/xsd/validation/base_types/boolean_validator.rb', line 33 def valid?(value) return false if value.nil? return true if value.is_a?(TrueClass) || value.is_a?(FalseClass) VALID_VALUES.include?(to_string(value).downcase) end |