Class: Lutaml::Model::Type::String

Inherits:
Value
  • Object
show all
Defined in:
lib/lutaml/model/type/string.rb

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, serialize, #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

Performance-optimized cast with short-circuit for already-correct types



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lutaml/model/type/string.rb', line 8

def self.cast(value, options = {})
  return nil if value.nil?
  return value if Utils.uninitialized?(value)
  # Short-circuit: return immediately if already a String with no options
  # Use identity check for EMPTY_OPTIONS (faster than .empty?)
  if value.is_a?(::String) && options.equal?(EMPTY_OPTIONS)
    return value
  end

  value = value.to_s
  unless options.equal?(EMPTY_OPTIONS)
    Model::Services::Type::Validator::String.validate!(value,
                                                       options)
  end
  value
end

.default_xsd_typeString

Default XSD type for String

Returns:



28
29
30
# File 'lib/lutaml/model/type/string.rb', line 28

def self.default_xsd_type
  "xs:string"
end