Class: Lutaml::Model::Type::Base64Binary

Inherits:
String
  • Object
show all
Defined in:
lib/lutaml/model/type/base64_binary.rb

Overview

Base64Binary type for xs:base64Binary

Handles base64 encoding/decoding of binary data

Examples:

Using Base64Binary type

attribute :attachment, :base64_binary

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
# File 'lib/lutaml/model/type/base64_binary.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?(::String)

  value.to_s
end

.decode(encoded) ⇒ String

Decode base64 to binary data

Parameters:

  • encoded (String)

    base64 encoded string

Returns:

  • (String)

    decoded binary data



50
51
52
53
54
# File 'lib/lutaml/model/type/base64_binary.rb', line 50

def self.decode(encoded)
  return nil if encoded.nil?

  Base64.strict_decode64(encoded)
end

.default_xsd_typeString

XSD type for Base64Binary

Returns:

  • (String)

    xs:base64Binary



32
33
34
# File 'lib/lutaml/model/type/base64_binary.rb', line 32

def self.default_xsd_type
  "xs:base64Binary"
end

.encode(data) ⇒ String

Encode binary data to base64

Parameters:

  • data (String)

    binary data to encode

Returns:

  • (String)

    base64 encoded string



40
41
42
43
44
# File 'lib/lutaml/model/type/base64_binary.rb', line 40

def self.encode(data)
  return nil if data.nil?

  Base64.strict_encode64(data)
end

.serialize(value) ⇒ Object



23
24
25
26
27
# File 'lib/lutaml/model/type/base64_binary.rb', line 23

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

  value.to_s
end