module Awestruct module Extensions module Obfuscate def mail_to(email, options={}) index = email.index('@') or raise "email needs to contain @" index += 3 parts = [ email[0...index], email[index..-1] ] "#{hex(parts[0])}#{hex(parts[1])}" end private def hex(s) result = '' s.each_codepoint do |cp| result << "&#x%x;" % [cp] end result end def percent(s) result = '' s.each_codepoint do |cp| result << "%%%x" % [cp] end result end end end end