Class: DataAnon::Strategy::Field::RandomEmail

Inherits:
Object
  • Object
show all
Defined in:
lib/strategy/field/email/random_email.rb

Overview

Generates email randomly using the given HOSTNAME and TLD. By defaults generates hostname randomly along with email id.

anonymize('Email').using FieldStrategy::RandomEmail.new('thoughtworks','com')

Constant Summary collapse

TLDS =
['com','org','net','edu','gov','mil','biz','info']

Instance Method Summary collapse

Constructor Details

#initialize(hostname = nil, tld = nil) ⇒ RandomEmail

Returns a new instance of RandomEmail.


17
18
19
20
# File 'lib/strategy/field/email/random_email.rb', line 17

def initialize hostname = nil, tld = nil
  @hostname = hostname
  @tld = tld
end

Instance Method Details

#anonymize(field) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/strategy/field/email/random_email.rb', line 22

def anonymize field

  username_length = DataAnon::Utils::RandomInt.generate(5,15)
  host_name_length = DataAnon::Utils::RandomInt.generate(2,10)

  username = DataAnon::Utils::RandomString.generate(username_length)
  hostname = @hostname || DataAnon::Utils::RandomString.generate(host_name_length)
  tld = @tld || TLDS[rand(TLDS.length)]

  return username + "@" + hostname + "." + tld

end