2021-12-19 07:51:04 -08:00
|
|
|
class Profile < ApplicationRecord
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
attr_readonly :user_id
|
|
|
|
|
2021-12-19 14:51:06 -08:00
|
|
|
validates :display_name, length: { maximum: 50 }
|
2021-12-19 07:51:04 -08:00
|
|
|
validates :location, length: { maximum: 72 }
|
2021-12-19 14:51:06 -08:00
|
|
|
validates :description, length: { maximum: 200 }
|
2021-12-19 07:51:04 -08:00
|
|
|
|
|
|
|
before_save do
|
|
|
|
unless website.blank?
|
|
|
|
self.website = if website.match %r{\Ahttps?://}
|
|
|
|
website
|
|
|
|
else
|
|
|
|
"http://#{website}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_website
|
|
|
|
website.match(/https?:\/\/([A-Za-z.\-0-9]+)\/?(?:.*)/i)[1]
|
|
|
|
rescue NoMethodError
|
|
|
|
website
|
|
|
|
end
|
|
|
|
|
|
|
|
def safe_name
|
2021-12-19 14:51:06 -08:00
|
|
|
display_name.presence || user.screen_name
|
2021-12-19 07:51:04 -08:00
|
|
|
end
|
|
|
|
end
|