Class: RDF::Literal::Base64Binary

Inherits:
RDF::Literal show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/lib/rdf/xsd/binary.rb

Overview

base64Binary represents Base64-encoded arbitrary binary data. The ·value space· of base64Binary is the set of finite-length sequences of binary octets. For base64Binary data the entire binary stream is encoded using the Base64 Alphabet in [RFC 2045].

Constant Summary collapse

DATATYPE =
XSD.base64Binary

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!, #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, #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?, #validate!, #variable?

Constructor Details

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

Returns a new instance of Base64Binary

Parameters:

  • value (String, Object)

    If given a string, it will decode it as an object value. Otherwise, it will take the value as the object and encode to retrieve a value

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :lexical (String) — default: nil


69
70
71
72
73
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/lib/rdf/xsd/binary.rb', line 69

def initialize(value, datatype: nil, lexical: nil, **options)
  super(value, datatype: datatype, lexical: lexical)
  @object = value.is_a?(String) ? ::Base64.decode64(value) : value
  canonicalize! unless value.is_a?(String)
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.



88
89
90
91
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/lib/rdf/xsd/binary.rb', line 88

def canonicalize!
  @string = ::Base64.encode64(@object)
  self
end

#to_sString

Returns the value as a string.

Returns:



79
80
81
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/lib/rdf/xsd/binary.rb', line 79

def to_s
  @string || @object.to_s
end

#valid?Boolean

Returns true if the value adheres to the defined grammar of the datatype.

Returns:



98
99
100
101
102
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-xsd-0489489cebb4/lib/rdf/xsd/binary.rb', line 98

def valid?
  !!Base64.strict_decode64(value.gsub(/\s+/m, ''))
rescue ArgumentError
  false
end