Skip to content

Commit

Permalink
fixup! Add CloudFlareProtectedEmail class
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Denman committed May 25, 2017
1 parent d6d9c80 commit 81bbedf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/cloudflare_protected_email_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
require 'cgi'

class CloudflareProtectedEmailAddress
def initialize(obfuscated:)
def initialize(obfuscated)
@obfuscated = obfuscated
end

def human_readable
CGI.unescape(unobfuscated)
def unobfuscated
return CGI.unescape(escaped_email_address) if CGI.unescape(escaped_email_address).include?('@')
obfuscated
end

private
Expand All @@ -20,10 +21,10 @@ def obfuscated_characters
end

def key
@key ||= obfuscated[0..1].hex
obfuscated[0..1].hex
end

def unobfuscated
def escaped_email_address
obfuscated_characters.reduce('') do |email, encoded_character|
email + (encoded_character ^ key).to_s(16).prepend('%')
end
Expand Down

0 comments on commit 81bbedf

Please sign in to comment.