From 81bbedfd7f6c44d962110e9bde34a0afca33b7db Mon Sep 17 00:00:00 2001 From: Oliver Denman Date: Thu, 25 May 2017 17:33:40 +0100 Subject: [PATCH] fixup! Add CloudFlareProtectedEmail class --- lib/cloudflare_protected_email_address.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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