Class: Fakir::EmailAddress
- Inherits:
-
String
- Object
- String
- Fakir::EmailAddress
- Defined in:
- lib/fakir/email.rb
Overview
Returns an email address based on the given name. By default, uses “example.com” as the domain, to not use actual existing email accounts. Returns “simple” email addresses, i.e., without valid-yet-rare characters, such as “[email protected]”@example.com (per en.wikipedia.org/wiki/Email_address). The email address is downcased and non-word characters are removed. Randomly, a trailing number is added. Thus the formats are:
- john.smith@example.com
- jsmith@example.com
- jsmith24@example.com
- smithj@example.com
- smithj17@example.com
Instance Method Summary collapse
- #clean_word(str) ⇒ Object
-
#initialize(firstname, lastname, domain = "example.com") ⇒ EmailAddress
constructor
A new instance of EmailAddress.
Constructor Details
#initialize(firstname, lastname, domain = "example.com") ⇒ EmailAddress
Returns a new instance of EmailAddress.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fakir/email.rb', line 19 def initialize firstname, lastname, domain = "example.com" formats = Array.new formats << "%s.%s" formats << "%.1s%s" formats << "%2$s%1$.1s" formats << "%.1s%s%d" formats << "%2$s%1$.1s%3$d" formats.collect! { |fmt| fmt + "@" + domain } fname = clean_word firstname lname = clean_word lastname fidx = rand(formats.size) format = formats[fidx] args = [ fname, lname ] if format.count("%") >= 3 args << rand(100) end addr = sprintf format, *args super addr end |
Instance Method Details
#clean_word(str) ⇒ Object
41 42 43 |
# File 'lib/fakir/email.rb', line 41 def clean_word str str.gsub(Regexp.new('[^\w]'), '').downcase end |