Module: Raptcha::Encoder

Extended by:
Encoder
Included in:
Encoder
Defined in:
lib/raptcha.rb

Instance Method Summary collapse

Instance Method Details

#decode(string) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/raptcha.rb', line 132

def decode(string)
  return nil if string.nil?
  case string.length.modulo(4)
  when 2
    string += '=='
  when 3
    string += '='
  end
  Base64.decode64(string.gsub("-", "+").gsub("_", "/"))
end

#encode(string) ⇒ Object



127
128
129
130
# File 'lib/raptcha.rb', line 127

def encode(string)
  return nil if string.nil?
  Base64.encode64(string.to_s).gsub(/[\s=]+/, "").gsub("+", "-").gsub("/", "_")
end