Class: Lutaml::Xsd::Validation::BaseTypes::AnyURIValidator

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

Overview

Validates XSD anyURI type

The anyURI type represents a Uniform Resource Identifier (URI) reference. This includes URLs, URNs, and relative URIs.

Examples:

Validating URI values

validator = AnyURIValidator.new
validator.valid?("https://example.com")           # => true
validator.valid?("http://example.com/path")       # => true
validator.valid?("ftp://ftp.example.com")         # => true
validator.valid?("mailto:[email protected]")       # => true
validator.valid?("urn:isbn:0-486-27557-4")        # => true
validator.valid?("../relative/path")              # => true
validator.valid?("not a uri with spaces")         # => 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 URI

Parameters:

  • value (Object)

    The invalid value

Returns:

  • (String)

    Error message



47
48
49
# File 'lib/lutaml/xsd/validation/base_types/any_uri_validator.rb', line 47

def error_message(value)
  "Value '#{value}' is not a valid URI"
end

#valid?(value) ⇒ Boolean

Validate value is a valid URI

Parameters:

  • value (Object)

    The value to validate

Returns:

  • (Boolean)

    true if value is a valid URI



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lutaml/xsd/validation/base_types/any_uri_validator.rb', line 29

def valid?(value)
  return false if value.nil?
  return true if value.is_a?(URI)

  str = to_string(value).strip
  return false if str.empty?

  # Try to parse as URI
  URI.parse(str)
  true
rescue URI::InvalidURIError
  false
end