Module: ZFaker::Internet

Extended by:
ModuleUtils, Internet
Included in:
Internet
Defined in:
lib/custom/internet.rb

Overview

Internet Module

Instance Method Summary collapse

Instance Method Details

#email(name = nil) ⇒ Object



12
13
14
# File 'lib/custom/internet.rb', line 12

def email(name = nil)
  unique_sample(@emails) { [user_name(name), email_domain].join('@') }
end

#email_domainObject



40
41
42
# File 'lib/custom/internet.rb', line 40

def email_domain
    "#{host}"
end

#hostObject



44
45
46
# File 'lib/custom/internet.rb', line 44

def host
  HOSTS.sample
end

#user_name(name = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/custom/internet.rb', line 16

def user_name(name = nil)
  if name
    input = name.split(' ')
    case rand(18)
    when 0..3   then parts = input.shuffle.join('_')
    when 4..6   then parts = input[0].to_s + input[1].to_s
    when 7..9   then parts = input[0][0].to_s + input[1].to_s
    when 10..12 then parts = input[0].to_s + input[1][0].to_s
    when 13..15 then parts = input[1].to_s
    else             parts = input[0].to_s
    end
    parts.to_s.downcase
  else
    case rand(2)
    when 0
      Name.first_name.gsub(/\W/, '').downcase
    when 1
      parts = [Name.first_name, Name.last_name].map { |n| n.gsub(/\W/, '') }
      parts = parts.join(%w(. _).sample)
      parts.downcase
    end
  end
end