class RDF::Literal::HexBinary
hexBinary represents arbitrary hex-encoded binary data. The value space of hexBinary is the set of finite-length sequences of binary octets.
Constants
- DATATYPE
- GRAMMAR
Public Class Methods
new(value, datatype: nil, lexical: nil, **options)
click to toggle source
@param [String] value The encoded form of the literal @option options [String] :object (nil) decoded value
Calls superclass method
# 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
Public Instance Methods
canonicalize!()
click to toggle source
Converts this literal into its canonical lexical representation.
@return [RDF::Literal] ‘self`
# File lib/rdf/xsd/binary.rb, line 32 def canonicalize! @string = bin_to_hex(@object) self end
to_s()
click to toggle source
Returns the encoded value as a string.
@return [String]
# File lib/rdf/xsd/binary.rb, line 41 def to_s @string.to_s end
Private Instance Methods
bin_to_hex(value)
click to toggle source
# File lib/rdf/xsd/binary.rb, line 46 def bin_to_hex(value) value.unpack('H*').first.upcase end
hex_to_bin(value)
click to toggle source
# File lib/rdf/xsd/binary.rb, line 50 def hex_to_bin(value) value.scan(/../).map { |x| x.hex }.pack('c*').force_encoding("BINARY") end