Class: Lutaml::Model::Type::Symbol

Inherits:
Value
  • Object
show all
Defined in:
lib/lutaml/model/type/symbol.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, #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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lutaml/model/type/symbol.rb', line 7

def self.cast(value, options = {})
  return nil if value.nil?
  return value if Utils.uninitialized?(value)
  return nil if value.respond_to?(:empty?) && value.empty?

  # Convert to string for validation and unwrapping
  str_value = if value.is_a?(::Symbol)
                # Already a symbol, convert to string for validation
                value.to_s
              elsif value.is_a?(::String)
                # Unwrap if needed, then validate
                unwrap_symbol_string(value)
              else
                # Other types - convert to string
                value.to_s
              end

  # Use identity check for EMPTY_OPTIONS (faster than .empty?)
  unless options.equal?(EMPTY_OPTIONS)
    Model::Services::Type::Validator::Symbol.validate!(str_value,
                                                       options)
  end

  # Convert to symbol after validation passes
  str_value.to_sym
end

.default_xsd_typeString

XSD type for Symbol

Symbols are serialized as strings in XSD

Returns:



54
55
56
# File 'lib/lutaml/model/type/symbol.rb', line 54

def self.default_xsd_type
  "xs:string"
end

.serialize(value) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lutaml/model/type/symbol.rb', line 34

def self.serialize(value)
  return nil if value.nil?
  return value if Utils.uninitialized?(value)

  # If it's already a symbol, return it
  return value if value.is_a?(::Symbol)

  # If it's a string, convert and unwrap if needed
  if value.is_a?(::String)
    return unwrap_symbol_string(value).to_sym
  end

  # For other types, convert to symbol
  value.to_sym
end