Module: SecurizeString::Base64Methods::InstanceMethods

Defined in:
lib/securize_string/base64_methods.rb

Overview

Adds instance methods for Base64 support via inclusion of SecurizeString::Base64Methods to a class.

Instance Method Summary collapse

Instance Method Details

#from_base64Object

Decode self as a Base64 data string and return the result.



25
26
27
# File 'lib/securize_string/base64_methods.rb', line 25

def from_base64
  return self.class.new( Base64.decode64(self) )
end

#to_base64(url_safe = true) ⇒ Object

Encodes to Base64. By default, the output is made URL safe, which means all newlines are stripped out. If you want standard formatted Base64 with newlines, then call this method with url_safe as false.



19
20
21
22
# File 'lib/securize_string/base64_methods.rb', line 19

def to_base64(url_safe = true)
  encoded_data = (url_safe ? Base64.urlsafe_encode64(self) : Base64.encode64(self))
  return self.class.new( encoded_data )
end