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
- DATATYPE =
XSD.base64Binary
Instance Method Summary (collapse)
-
- (RDF::Literal) canonicalize!
Converts this literal into its canonical lexical representation.
-
- (Base64Binary) initialize(value, options = {})
constructor
A new instance of Base64Binary.
-
- (Boolean) valid?
Returns
trueif the value adheres to the defined grammar of the datatype.
Constructor Details
- (Base64Binary) initialize(value, options = {})
A new instance of Base64Binary
43 44 45 46 47 |
# File 'lib/rdf/xsd/binary.rb', line 43 def initialize(value, = {}) super @object = value.is_a?(String) ? ::Base64.decode64(value) : value canonicalize! unless value.is_a?(String) end |
Instance Method Details
- (RDF::Literal) canonicalize!
Converts this literal into its canonical lexical representation.
54 55 56 57 |
# File 'lib/rdf/xsd/binary.rb', line 54 def canonicalize! @string = ::Base64.encode64(@object) self end |
- (Boolean) valid?
Returns true if the value adheres to the defined grammar of the
datatype.
Note: depends on implementation of Base64.strict_decode64, which may not be implemented for Ruby 1.8.x.
67 68 69 70 71 72 73 74 75 |
# File 'lib/rdf/xsd/binary.rb', line 67 def valid? Base64.respond_to?(:strict_decode64) ? Base64.strict_decode64(value.gsub(/\s+/m, '')) : Base64.decode64(value.gsub(/\s+/m, '')) true rescue ArgumentError STDERR.puts($!.inspect + ": #{value.inspect}") false end |