Module: AppReport::Decoder

Defined in:
lib/app_report/decoder.rb

Class Method Summary collapse

Class Method Details

.decode(encoded, encoding = 'base64') ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/app_report/decoder.rb', line 20

def self.decode encoded, encoding = 'base64'
  supported = ['base64']

  if encoded.blank?
    raise AppReport::Errors::DecoderError, "Encoded can't be blank"

  elsif encoding.blank?
    raise AppReport::Errors::DecoderError, "Encoding can't be blank!"

  elsif not supported.include? encoding
    raise AppReport::Errors::DecoderError, "Encoding '#{encoding}' not supported, only #{supported}."
  end

  send "decode_#{encoding}", encoded
end

.decode_base64(encoded) ⇒ Object



36
37
38
# File 'lib/app_report/decoder.rb', line 36

def self.decode_base64 encoded
  Base64.decode64 encoded
end