Class: RDF::Literal::Base64Binary
- Inherits:
-
RDF::Literal
- Object
- RDF::Literal
- RDF::Literal::Base64Binary
- Defined in:
- 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 =
RDF::XSD.base64Binary
Instance Method Summary collapse
-
#canonicalize! ⇒ RDF::Literal
Converts this literal into its canonical lexical representation.
-
#initialize(value, datatype: nil, lexical: nil, **options) ⇒ Base64Binary
constructor
A new instance of Base64Binary.
-
#to_s ⇒ String
Returns the value as a string.
-
#valid? ⇒ Boolean
Returns
true
if the value adheres to the defined grammar of the datatype.
Constructor Details
#initialize(value, datatype: nil, lexical: nil, **options) ⇒ Base64Binary
Returns a new instance of Base64Binary.
69 70 71 72 73 |
# File 'lib/rdf/xsd/binary.rb', line 69 def initialize(value, datatype: nil, lexical: nil, **) super(value, datatype: datatype, lexical: lexical) @object = value.is_a?(String) ? ::Base64.decode64(value) : value canonicalize! unless value.is_a?(String) end |
Instance Method Details
#canonicalize! ⇒ RDF::Literal
Converts this literal into its canonical lexical representation.
88 89 90 91 |
# File 'lib/rdf/xsd/binary.rb', line 88 def canonicalize! @string = ::Base64.encode64(@object) self end |
#to_s ⇒ String
Returns the value as a string.
79 80 81 |
# File '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.
98 99 100 101 102 |
# File 'lib/rdf/xsd/binary.rb', line 98 def valid? !!Base64.strict_decode64(value.gsub(/\s+/m, '')) rescue ArgumentError false end |