diff --git a/lib/cloudflare_protected_email_address.rb b/lib/cloudflare_protected_email_address.rb index 1121e91..78ab441 100644 --- a/lib/cloudflare_protected_email_address.rb +++ b/lib/cloudflare_protected_email_address.rb @@ -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 @@ -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