1
0
mirror of https://github.com/askn/faker.git synced 2023-08-10 21:13:01 +03:00

add separators to Internet.user_name

This commit is contained in:
Aşkın Gedik 2016-01-06 15:57:20 +02:00
parent 099dce6fc3
commit ae08268c78
3 changed files with 5 additions and 3 deletions

View File

@ -62,6 +62,7 @@ Faker::Internet.safe_email
Faker::Internet.safe_email("Nancy")
Faker::Internet.user_name
Faker::Internet.user_name("Nancy")
Faker::Internet.user_name("Nancy Johnson", %w(. _ -))
Faker::Internet.domain_name
Faker::Internet.domain_word

View File

@ -38,6 +38,7 @@ puts Faker::Internet.safe_email("Nancy")
puts Faker::Internet.user_name
puts Faker::Internet.user_name("Nancy")
puts Faker::Internet.user_name("Nancy Johnson", %w(. _ -))
puts Faker::Internet.domain_name
puts Faker::Internet.domain_word

View File

@ -12,14 +12,14 @@ module Faker
[user_name(name), "example." + %w(org com net).shuffle.first].join("@")
end
def self.user_name(name = nil)
return name.scan(/\w+/).shuffle.map(&.[0]).join(%w(. _).sample).downcase if name
def self.user_name(name = nil, separators = %w(. _))
return name.scan(/\w+/).shuffle.map(&.[0]).join(separators.sample).downcase if name
[
->{ Name.first_name.gsub(/\W/, "").downcase },
->{
[Name.first_name, Name.last_name].map { |n|
n.gsub(/\W/, "")
}.join(".").downcase
}.join(separators.sample).downcase
},
].sample.call
end