thirteen-tien-len/app/models/social_link.rb

22 lines
615 B
Ruby

class SocialLink < ActiveRecord::Base
belongs_to :profile
has_one :user, through: :profile
def to_icon
case self.url
when /twitter\.com/, /x\.com/
social_icon = "<svg class='x-logo' viewBox='0 0 24 24' aria-hidden='true'><g><path d='M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z'></path></g></svg>"
else
social_icon = "🌐"
end
end
def to_url
if self.url.scan(/https?:\/\//).empty?
"https://#{self.url}"
else
self.url
end
end
end