class SocialParser::Provider::Base
Public Class Methods
parse(attrs)
click to toggle source
# File lib/social_parser/provider/base.rb, line 10 def self.parse(attrs) if attrs[:provider] SocialParser::Provider.const_get(attrs[:provider].to_s.capitalize).new(attrs) else providers.map do |provider| SocialParser::Provider.const_get(provider.to_s.capitalize).new(attrs) end.find(&:valid?) or ::SocialParser::Link.new(attrs) end end
Private Class Methods
providers()
click to toggle source
# File lib/social_parser/provider/base.rb, line 61 def self.providers @providers ||= [:facebook, :github, :twitter, :youtube, :instagram, :linkedin, :medium, :qiita, :pinterest, :google, :vimeo] end
Public Instance Methods
domain()
click to toggle source
# File lib/social_parser/provider/base.rb, line 36 def domain 'com' end
embed_url()
click to toggle source
# File lib/social_parser/provider/base.rb, line 40 def embed_url nil end
url()
click to toggle source
# File lib/social_parser/provider/base.rb, line 31 def url return url_from_attributes if url_from_attributes "https://www.#{provider.to_s}.com/#{username}" end
username()
click to toggle source
# File lib/social_parser/provider/base.rb, line 22 def username return @username if @username if @url_or_username and invalid_url_format?(@url_or_username) @url_or_username elsif url_from_attributes parse_from_url end end
Also aliased as: id
valid?()
click to toggle source
# File lib/social_parser/provider/base.rb, line 44 def valid? (@provider and @provider == provider) or (username and URI.parse(url_from_attributes).host.match("#{provider.to_s}.#{domain}")) rescue URI::BadURIError, URI::InvalidURIError false end
Private Instance Methods
parse_from_url()
click to toggle source
# File lib/social_parser/provider/base.rb, line 55 def parse_from_url URI.parse(url_from_attributes).path.split('/')[1] rescue URI::BadURIError, URI::InvalidURIError nil end