Module: FFaker::Internet
Constant Summary
collapse
- BYTE =
Array('0'..'255').freeze
- HOSTS =
%w[gmail.com yahoo.com hotmail.com].freeze
- DISPOSABLE_HOSTS =
%w[
mailinator.com suremail.info spamherelots.com binkmail.com safetymail.info
].freeze
- DOMAIN_SUFFIXES =
%w[co.uk com us ca biz info name].freeze
- SAFE_DOMAIN_SUFFIXES =
%w[org com net].freeze
- SLUG_DELIMITERS =
%w[- _ .].freeze
- MAC_LIMIT =
281_474_976_710_655
Instance Method Summary
collapse
const_missing, k, luhn_check, underscore, unique
#fetch_sample, #rand, #shuffle
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.
25
26
27
|
# File 'lib/ffaker/internet.rb', line 25
def disposable_email(name = nil)
[user_name(name), fetch_sample(DISPOSABLE_HOSTS)].join('@')
end
|
#domain_name ⇒ Object
45
46
47
|
# File 'lib/ffaker/internet.rb', line 45
def domain_name
[domain_word, domain_suffix].join('.')
end
|
#domain_suffix ⇒ Object
53
54
55
|
# File 'lib/ffaker/internet.rb', line 53
def domain_suffix
fetch_sample(DOMAIN_SUFFIXES)
end
|
#domain_word ⇒ Object
49
50
51
|
# File 'lib/ffaker/internet.rb', line 49
def domain_word
sanitize(Company.name.split(' ').first)
end
|
#email(name = nil) ⇒ Object
18
19
20
|
# File 'lib/ffaker/internet.rb', line 18
def email(name = nil)
[user_name(name), domain_name].join('@')
end
|
#free_email(name = nil) ⇒ Object
29
30
31
|
# File 'lib/ffaker/internet.rb', line 29
def free_email(name = nil)
[user_name(name), fetch_sample(HOSTS)].join('@')
end
|
#http_url ⇒ Object
61
62
63
|
# File 'lib/ffaker/internet.rb', line 61
def http_url
uri('http')
end
|
#ip_v4_address ⇒ Object
65
66
67
|
# File 'lib/ffaker/internet.rb', line 65
def ip_v4_address
(1..4).map { fetch_sample(BYTE) }.join('.')
end
|
#mac(delimiter = ':') ⇒ Object
80
81
82
|
# File 'lib/ffaker/internet.rb', line 80
def mac(delimiter = ':')
rand(0...MAC_LIMIT).to_s(16).rjust(12, '0').scan(/.{2}/).join(delimiter)
end
|
#password(min_length = 8, max_length = 16) ⇒ Object
75
76
77
78
|
# File 'lib/ffaker/internet.rb', line 75
def password(min_length = 8, max_length = 16)
length = min_length > max_length ? min_length : fetch_sample(min_length..max_length)
String.from_regexp(/\w{#{length}}/)
end
|
#safe_email(name = nil) ⇒ Object
33
34
35
|
# File 'lib/ffaker/internet.rb', line 33
def safe_email(name = nil)
[user_name(name), fetch_sample(SAFE_DOMAIN_SUFFIXES)].join('@example.')
end
|
#slug(words = nil, glue = nil) ⇒ Object
69
70
71
72
73
|
# File 'lib/ffaker/internet.rb', line 69
def slug(words = nil, glue = nil)
words ||= Lorem.words(2).join(' ')
glue ||= fetch_sample(SLUG_DELIMITERS)
words.downcase.gsub(/[^a-z0-9]+/, glue)
end
|
#uri(protocol) ⇒ Object
57
58
59
|
# File 'lib/ffaker/internet.rb', line 57
def uri(protocol)
[protocol, domain_name].join('://')
end
|
#user_name(name = nil) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/ffaker/internet.rb', line 37
def user_name(name = nil)
return shuffle(name.split(' ')).join(fetch_sample(%w[. _])).downcase if name
return sanitize(Name.first_name) if rand(0..1).zero?
[sanitize(Name.first_name), sanitize(Name.last_name)].join(fetch_sample(%w[. _]))
end
|