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
|