Module: FFaker::Internet

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

Constant Summary collapse

BYTE =
[*'0'..'255']
HOSTS =
%w(gmail.com yahoo.com hotmail.com)
DISPOSABLE_HOSTS =
%w(mailinator.com suremail.info spamherelots.com binkmail.com safetymail.info)
DOMAIN_SUFFIXES =
%w(co.uk com us ca biz info name)
SAFE_DOMAIN_SUFFIXES =
%w(org com net)
SLUG_DELIMITERS =
%w(- _ .)

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#disposable_email(name = nil) ⇒ Object

returns an email address of an online disposable email service (like tempinbox.com). you can really send an email to these addresses an access it by going to the service web pages.



21
22
23
# File 'lib/ffaker/internet.rb', line 21

def disposable_email(name = nil)
  [user_name(name), DISPOSABLE_HOSTS.sample].join('@')
end

#domain_nameObject



49
50
51
# File 'lib/ffaker/internet.rb', line 49

def domain_name
  "#{domain_word}.#{domain_suffix}"
end

#domain_suffixObject



60
61
62
# File 'lib/ffaker/internet.rb', line 60

def domain_suffix
  DOMAIN_SUFFIXES.sample
end

#domain_wordObject



53
54
55
56
57
58
# File 'lib/ffaker/internet.rb', line 53

def domain_word
  dw = Company.name.split(' ').first
  dw.gsub!(/\W/, '')
  dw.downcase!
  dw
end

#email(name = nil) ⇒ Object



15
16
17
# File 'lib/ffaker/internet.rb', line 15

def email(name = nil)
  [user_name(name), domain_name].join('@')
end

#free_email(name = nil) ⇒ Object



25
26
27
# File 'lib/ffaker/internet.rb', line 25

def free_email(name = nil)
  "#{user_name(name)}@#{HOSTS.sample}"
end

#http_urlObject



68
69
70
# File 'lib/ffaker/internet.rb', line 68

def http_url
  uri('http')
end

#ip_v4_addressObject



72
73
74
# File 'lib/ffaker/internet.rb', line 72

def ip_v4_address
  (1..4).map { BYTE.sample }.join('.')
end

#password(min_length = 8, max_length = 16) ⇒ Object



82
83
84
85
86
# File 'lib/ffaker/internet.rb', line 82

def password(min_length = 8, max_length = 16)
  length =
    min_length > max_length ? min_length : [*min_length..max_length].sample
  String.from_regexp(/[a-z]{#{length}}/)
end

#safe_email(name = nil) ⇒ Object



29
30
31
# File 'lib/ffaker/internet.rb', line 29

def safe_email(name = nil)
  "#{user_name(name)}@example.#{SAFE_DOMAIN_SUFFIXES.sample}"
end

#slug(words = nil, glue = nil) ⇒ Object



76
77
78
79
80
# File 'lib/ffaker/internet.rb', line 76

def slug(words = nil, glue = nil)
  words ||= Lorem.words(2).join(' ')
  glue ||= SLUG_DELIMITERS.sample
  words.downcase.gsub(/[^a-z0-9]+/, glue)
end

#uri(protocol) ⇒ Object



64
65
66
# File 'lib/ffaker/internet.rb', line 64

def uri(protocol)
  "#{protocol}://#{domain_name}"
end

#user_name(name = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ffaker/internet.rb', line 33

def user_name(name = nil)
  if name
    parts = name.scan(/\w+/).shuffle.join(%w(. _).sample)
    parts.downcase
  else
    case rand(2)
    when 0
      sanitize(Name.first_name)
    when 1
      [Name.first_name, Name.last_name]
        .map { |n| sanitize(n) }
        .join(%w(. _).sample)
    end
  end
end