Class: Lutaml::Model::Type::HexBinary

Inherits:
String show all
Defined in:
lib/lutaml/model/type/hex_binary.rb

Overview

HexBinary type for xs:hexBinary

Handles hexadecimal encoding/decoding of binary data

Examples:

Using HexBinary type

attribute :checksum, :hex_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



13
14
15
16
17
18
19
# File 'lib/lutaml/model/type/hex_binary.rb', line 13

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 hex to binary data

Parameters:

  • encoded (String)

    hex encoded string

Returns:

  • (String)

    decoded binary data



48
49
50
51
52
# File 'lib/lutaml/model/type/hex_binary.rb', line 48

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

  [encoded].pack("H*")
end

.default_xsd_typeString

XSD type for HexBinary

Returns:



30
31
32
# File 'lib/lutaml/model/type/hex_binary.rb', line 30

def self.default_xsd_type
  "xs:hexBinary"
end

.encode(data) ⇒ String

Encode binary data to hex

Parameters:

  • data (String)

    binary data to encode

Returns:

  • (String)

    hex encoded string



38
39
40
41
42
# File 'lib/lutaml/model/type/hex_binary.rb', line 38

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

  data.unpack1("H*")
end

.serialize(value) ⇒ Object



21
22
23
24
25
# File 'lib/lutaml/model/type/hex_binary.rb', line 21

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

  value.to_s
end