Class: Faker::Internet
Class Method Summary collapse
- .domain_name ⇒ Object
- .domain_suffix ⇒ Object
- .domain_word ⇒ Object
- .email(name = nil, name_suffix = "") ⇒ Object
- .free_email(name = nil, name_suffix = "") ⇒ Object
- .ip_v4_address ⇒ Object
- .ip_v6_address ⇒ Object
- .mac_address ⇒ Object
- .user_name(name = nil, name_suffix = "") ⇒ Object
Methods inherited from Base
bothify, fetch, letterify, numerify
Class Method Details
.domain_name ⇒ Object
24 25 26 |
# File 'lib/faker/internet.rb', line 24 def domain_name [ domain_word, domain_suffix ].join('.') end |
.domain_suffix ⇒ Object
32 33 34 |
# File 'lib/faker/internet.rb', line 32 def domain_suffix fetch('internet.domain_suffix') end |
.domain_word ⇒ Object
28 29 30 |
# File 'lib/faker/internet.rb', line 28 def domain_word Company.name.split(' ').first.gsub(/\W/, '').downcase end |
.email(name = nil, name_suffix = "") ⇒ Object
4 5 6 |
# File 'lib/faker/internet.rb', line 4 def email(name = nil, name_suffix = "") [ user_name(name, name_suffix), domain_name ].join('@') end |
.free_email(name = nil, name_suffix = "") ⇒ Object
8 9 10 |
# File 'lib/faker/internet.rb', line 8 def free_email(name = nil, name_suffix = "") [ user_name(name, name_suffix), fetch('internet.free_email') ].join('@') end |
.ip_v4_address ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/faker/internet.rb', line 36 def ip_v4_address ary = (2..255).to_a [ary.rand, ary.rand, ary.rand, ary.rand].join('.') end |
.ip_v6_address ⇒ Object
44 45 46 47 48 |
# File 'lib/faker/internet.rb', line 44 def ip_v6_address @@ip_v6_space ||= (0..65535).to_a container = (1..8).map{ |_| @@ip_v6_space.rand } container.map{ |n| n.to_s(16) }.join(':') end |
.mac_address ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/faker/internet.rb', line 50 def mac_address hex_ary = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E'] [hex_ary.rand + hex_ary.rand, hex_ary.rand + hex_ary.rand, hex_ary.rand + hex_ary.rand, hex_ary.rand + hex_ary.rand, hex_ary.rand + hex_ary.rand, hex_ary.rand + hex_ary.rand].join(':') end |
.user_name(name = nil, name_suffix = "") ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/faker/internet.rb', line 12 def user_name(name = nil, name_suffix = "") return name.scan(/\w+/).shuffle.join(%w(. _).rand).downcase + name_suffix.to_s if name [ Proc.new { Name.first_name.gsub(/\W/, '').downcase + name_suffix.to_s }, Proc.new { [ Name.first_name, Name.last_name ].map {|n| n.gsub(/\W/, '') }.join(%w(. _).rand).downcase + name_suffix.to_s } ].rand.call end |