Module: UriSigner::Helpers::String
- Defined in:
- lib/uri_signer/helpers/string.rb
Instance Method Summary collapse
-
#base64_encoded ⇒ String
This returns the string Base64 encoded with the newlines removed.
-
#escaped ⇒ String
This delegates the call to Rack::Utils to escape a string.
-
#hmac_signed_with(secret) ⇒ String
Digitally sign a string with a secret and get the digest.
-
#nl2br ⇒ String
Returns the string with newlines replaced with
. -
#to_parsed_uri ⇒ Addressable
Take a URL string and convert it to a URI Parsed object.
-
#unescaped ⇒ String
This delegates the call to Rack::Utils to unescape a string.
Instance Method Details
#base64_encoded ⇒ String
This returns the string Base64 encoded with the newlines removed
14 15 16 |
# File 'lib/uri_signer/helpers/string.rb', line 14 def base64_encoded Base64.encode64(self).chomp end |
#escaped ⇒ String
This delegates the call to Rack::Utils to escape a string
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
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 |
#nl2br ⇒ String
Returns the string with newlines replaced with
7 8 9 |
# File 'lib/uri_signer/helpers/string.rb', line 7 def nl2br self.gsub(/\n/, '<br>') end |
#to_parsed_uri ⇒ Addressable
Take a URL string and convert it to a URI Parsed object
46 47 48 |
# File 'lib/uri_signer/helpers/string.rb', line 46 def to_parsed_uri Addressable::URI.parse(CGI.unescapeHTML(self)) end |