Class: RDF::Literal::HexBinary

Inherits:
RDF::Literal show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-e532a0ab7189/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

Methods inherited from RDF::Literal

#inspect, #valid_extended?

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 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-e532a0ab7189/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 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-e532a0ab7189/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:



41
42
43
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-e532a0ab7189/lib/rdf/xsd/binary.rb', line 41

def to_s
  @string.to_s
end