Class: Lutaml::Model::Type::Float

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

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

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

.default_xsd_typeString

XSD type for Float

Returns:



27
28
29
# File 'lib/lutaml/model/type/float.rb', line 27

def self.default_xsd_type
  "xs:float"
end

.serialize(value) ⇒ Object



18
19
20
21
22
# File 'lib/lutaml/model/type/float.rb', line 18

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

  cast(value)
end