Refactor `User#suggest_name`.
* Rename `email` to `string` as variable can be an email, username or any valid string.
This commit is contained in:
parent
441a52ad17
commit
117763493b
|
@ -286,15 +286,11 @@ class User < ActiveRecord::Base
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.suggest_name(email)
|
def self.suggest_name(string)
|
||||||
return "" if email.blank?
|
return "" if string.blank?
|
||||||
if email[/\A[^@]+/].present?
|
local_part = string[/\A[^@]+/]
|
||||||
# email provided
|
suggestion = local_part.present? ? local_part : string[/[^@]+\z/]
|
||||||
email[/\A[^@]+/].tr(".", " ").titleize
|
suggestion.tr(".", " ").titleize
|
||||||
else
|
|
||||||
# username/name provided
|
|
||||||
email[/[^@]+\z/].tr(".", " ").titleize
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_by_username_or_email(username_or_email)
|
def self.find_by_username_or_email(username_or_email)
|
||||||
|
|
Loading…
Reference in New Issue