Class: KDL::Types::Base64

Inherits:
Value
  • Object
show all
Defined in:
lib/kdl/types/base64.rb

Constant Summary collapse

RGX =
/^[A-Za-z0-9+\/=]+$/.freeze

Constants inherited from Value

Value::Null

Instance Attribute Summary

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Methods inherited from Value

#as_type, from, #initialize, #stringify_value, #to_s

Constructor Details

This class inherits a constructor from KDL::Value

Class Method Details

.call(value, type = 'base64') ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/kdl/types/base64.rb', line 8

def self.call(value, type = 'base64')
  return nil unless value.is_a? ::KDL::Value::String

  unless RGX.match?(value.value)
      raise ArgumentError, "invalid base64: #{value.value}"
  end

  data = ::Base64.decode64(value.value)
  new(data, type: type)
end