Class: Lutaml::Xsd::Validation::BaseTypes::StringValidator

Inherits:
BaseTypeValidator show all
Defined in:
lib/lutaml/xsd/validation/base_types/string_validator.rb

Overview

Validates XSD string type

The string type represents character strings in XML. All values are valid strings unless additional facets restrict them.

Examples:

Validating string values

validator = StringValidator.new
validator.valid?("hello")      # => true
validator.valid?("123")        # => true
validator.valid?("")           # => true
validator.valid?(nil)          # => false

Instance Method Summary collapse

Methods inherited from BaseTypeValidator

for, registered?, #type_name

Instance Method Details

#error_message(value) ⇒ String

Generate error message for invalid string

Parameters:

  • value (Object)

    The invalid value

Returns:

  • (String)

    Error message



34
35
36
# File 'lib/lutaml/xsd/validation/base_types/string_validator.rb', line 34

def error_message(value)
  "Value '#{value}' is not a valid string (cannot be nil)"
end

#valid?(value) ⇒ Boolean

Validate value is a valid string

Parameters:

  • value (Object)

    The value to validate

Returns:

  • (Boolean)

    true if value can be represented as string



26
27
28
# File 'lib/lutaml/xsd/validation/base_types/string_validator.rb', line 26

def valid?(value)
  !value.nil?
end