Class: Lutaml::Model::Type::Uri

Inherits:
String show all
Defined in:
lib/lutaml/model/type/uri.rb

Overview

URI type for xs:anyURI

Validates and handles URI values.

Examples:

Using URI type

attribute :homepage, :uri

Constant Summary

Constants inherited from Value

Value::EMPTY_OPTIONS

Instance Attribute Summary

Attributes inherited from Value

#value

Class Method Summary collapse

Methods inherited from Value

format_type_serializer_for, from_format, #initialize, #initialized?, register_format_to_from_methods, register_format_type_serializer, #to_s

Methods included from Xml::Type::Configurable

included

Methods included from UninitializedClassGuard

#cast, #serialize

Constructor Details

This class inherits a constructor from Lutaml::Model::Type::Value

Class Method Details

.cast(value, _options = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/lutaml/model/type/uri.rb', line 15

def self.cast(value, _options = {})
  return nil if value.nil?
  return value if Utils.uninitialized?(value)
  return value if value.is_a?(::URI)
  return value if value.is_a?(::String)

  value.to_s
end

.default_xsd_typeString

XSD type for Uri

Returns:



34
35
36
# File 'lib/lutaml/model/type/uri.rb', line 34

def self.default_xsd_type
  "xs:anyURI"
end

.serialize(value) ⇒ Object



24
25
26
27
28
29
# File 'lib/lutaml/model/type/uri.rb', line 24

def self.serialize(value)
  return nil if value.nil?
  return value.to_s if value.is_a?(::URI)

  value.to_s
end

.valid_uri?(value) ⇒ Boolean

Validate URI format

Parameters:

  • value (String)

    the URI to validate

Returns:

  • (Boolean)

    true if valid URI format



42
43
44
45
46
47
# File 'lib/lutaml/model/type/uri.rb', line 42

def self.valid_uri?(value)
  ::URI.parse(value.to_s)
  true
rescue ::URI::InvalidURIError
  false
end