Class: RichUrls::Parsers::EmbedParser::Spotify

Inherits:
Base
  • Object
show all
Defined in:
lib/parsers/embed_parsers/spotify.rb

Constant Summary collapse

IFRAME =
'<iframe src="https://open.spotify.com/embed/%s/%s" '\
'width="300" height="380" frameborder="0" '\
'allowtransparency="true" allow="encrypted-media">'\
'</iframe>'.freeze
SCOPES =
%w[
  album
  track
  playlist
].freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from RichUrls::Parsers::EmbedParser::Base

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/parsers/embed_parsers/spotify.rb', line 16

def match?
  valid_path = SCOPES.any? do |path|
    @uri.path.start_with?("/#{path}")
  end

  @uri.host == 'open.spotify.com' && valid_path
end

#parseObject



24
25
26
27
28
29
# File 'lib/parsers/embed_parsers/spotify.rb', line 24

def parse
  path = @uri.path
  path[0] = ''

  IFRAME % path.split('/')
end