Class: Lutaml::Model::Type::Boolean

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

def self.cast(value, _options = {})
  return nil if value.nil?
  return value if Utils.uninitialized?(value)
  return true if value == true || value.to_s.match?(/^(true|t|yes|y|1)$/i)
  return false if value == false || value.to_s.match?(/^(false|f|no|n|0)$/i)

  value
end

.default_xsd_typeString

Default XSD type for Boolean

Returns:



25
26
27
# File 'lib/lutaml/model/type/boolean.rb', line 25

def self.default_xsd_type
  "xs:boolean"
end

.serialize(value) ⇒ Object



16
17
18
19
20
# File 'lib/lutaml/model/type/boolean.rb', line 16

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

  !!value
end