Class: CoderDecorator::Coders::Base64

Inherits:
Coder
  • Object
show all
Defined in:
lib/coder_decorator/coders/base64.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Coder

#coder

Instance Method Summary collapse

Constructor Details

#initialize(coder = nil, strict: true) ⇒ Base64

Returns a new instance of Base64.



7
8
9
10
# File 'lib/coder_decorator/coders/base64.rb', line 7

def initialize(coder = nil, strict: true)
  super(coder)
  @template_str = strict ? 'm0' : 'm'
end

Instance Method Details

#decode(str) ⇒ Object



16
17
18
# File 'lib/coder_decorator/coders/base64.rb', line 16

def decode(str)
  coder.decode(str.unpack(@template_str).first)
end

#encode(obj) ⇒ Object



12
13
14
# File 'lib/coder_decorator/coders/base64.rb', line 12

def encode(obj)
  [coder.encode(obj)].pack(@template_str)
end