Module: UriSigner::Helpers::String

Defined in:
lib/uri_signer/helpers/string.rb

Instance Method Summary collapse

Instance Method Details

#base64_encodedString

This returns the string Base64 encoded with the newlines removed

Returns:



14
15
16
# File 'lib/uri_signer/helpers/string.rb', line 14

def base64_encoded
  Base64.encode64(self).chomp
end

#escapedString

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

Returns:



21
22
23
24
25
# 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) ⇒ String

Digitally sign a string with a secret and get the digest

Returns:



37
38
39
40
41
# File 'lib/uri_signer/helpers/string.rb', line 37

def hmac_signed_with(secret)
  hmac = HMAC::SHA256.new(secret)
  hmac << self
  hmac.digest
end

#nl2brString

Returns the string with newlines replaced with

Returns:



7
8
9
# File 'lib/uri_signer/helpers/string.rb', line 7

def nl2br
  self.gsub(/\n/, '<br>')
end

#to_parsed_uriAddressable

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

Returns:

  • (Addressable)


46
47
48
# File 'lib/uri_signer/helpers/string.rb', line 46

def to_parsed_uri
  Addressable::URI.parse(CGI.unescapeHTML(self))
end

#unescapedString

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

Returns:



30
31
32
# File 'lib/uri_signer/helpers/string.rb', line 30

def unescaped
  Rack::Utils.unescape(self)
end