Class: RDF::Literal::HexBinary

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

Constants inherited from RDF::Literal

FALSE, TRUE, ZERO

Instance Attribute Summary

Attributes inherited from RDF::Literal

#datatype, #language

Instance Method Summary collapse

Methods inherited from RDF::Literal

#==, #compatible?, #comperable_datatype?, #eql?, #escape, #has_datatype?, #has_language?, #hash, #humanize, #inspect, #literal?, #method_missing, #object, #plain?, #respond_to_missing?, #simple?, #squish, #squish!, #valid?, #valid_extended?, #validate!, #value, #value_hash

Methods included from Term

#<=>, #==, #aggregate?, #compatible?, #eql?, #escape, #evaluate, #ndvars, #term?, #to_base, #to_term, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Methods included from Value

#anonymous?, #canonicalize, #constant?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #term?, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #uri?, #valid?, #validate!, #variable?

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-d4b9d6c7dd20/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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Literal

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-d4b9d6c7dd20/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-d4b9d6c7dd20/lib/rdf/xsd/binary.rb', line 41

def to_s
  @string.to_s
end