module UriSigner::Helpers::String

Public Instance Methods

base64_encoded() click to toggle source

This returns the string Base64 encoded with the newlines removed

@return [String] encoded

# File lib/uri_signer/helpers/string.rb, line 14
def base64_encoded
  Base64.encode64(self).chomp
end
escaped() click to toggle source

This delegates the call to Rack::Utils to escape a string

@return [String] escaped

# File lib/uri_signer/helpers/string.rb, line 21
def escaped
  return '' if self.nil?
  unescaped = URI.unescape(self) # This will fix the percent encoding issue
  Rack::Utils.escape(unescaped)
end
hmac_signed_with(secret) click to toggle source

Digitally sign a string with a secret and get the digest

@return [String]

# File lib/uri_signer/helpers/string.rb, line 37
def hmac_signed_with(secret)
  hmac = HMAC::SHA256.new(secret)
  hmac << self
  hmac.digest
end
nl2br() click to toggle source

Returns the string with newlines replaced with

@return [String] HTML version

# File lib/uri_signer/helpers/string.rb, line 7
def nl2br
  self.gsub(/\n/, '<br>')
end
to_parsed_uri() click to toggle source

Take a URL string and convert it to a URI Parsed object

@return [Addressable]

# File lib/uri_signer/helpers/string.rb, line 46
def to_parsed_uri
  Addressable::URI.parse(CGI.unescapeHTML(self))
end
unescaped() click to toggle source

This delegates the call to Rack::Utils to unescape a string

@return [String] unescaped

# File lib/uri_signer/helpers/string.rb, line 30
def unescaped
  Rack::Utils.unescape(self)
end