Class: RDF::Literal::HexBinary

Inherits:
RDF::Literal show all
Defined in:
lib/rdf/xsd/binary.rb

Overview

hexBinary represents arbitrary hex-encoded binary data. The value space of hexBinary is the set of finite-length sequences of binary octets.

Constant Summary collapse

DATATYPE =
RDF::XSD.hexBinary
GRAMMAR =
%r(\A[0-9a-fA-F]+\Z)

Instance Method Summary collapse

Constructor Details

#initialize(value, datatype: nil, lexical: nil, **options) ⇒ HexBinary

Returns a new instance of HexBinary.

Parameters:

  • value (String)

    The encoded form of the literal

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :object (String) — default: nil

    decoded value



22
23
24
25
26
# File 'lib/rdf/xsd/binary.rb', line 22

def initialize(value, datatype: nil, lexical: nil, **options)
  super(value, datatype: datatype, lexical: lexical)
  @object = options.fetch(:object, hex_to_bin(value.to_s))
  @string ||= bin_to_hex(@object)
end

Instance Method Details

#canonicalize!RDF::Literal

Converts this literal into its canonical lexical representation.

Returns:



32
33
34
35
# File 'lib/rdf/xsd/binary.rb', line 32

def canonicalize!
  @string = bin_to_hex(@object)
  self
end

#to_sString

Returns the encoded value as a string.

Returns:

  • (String)


41
42
43
# File 'lib/rdf/xsd/binary.rb', line 41

def to_s
  @string.to_s
end