Class: Spotify::Music::Importer::SpotifyMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/spotify/music/importer/spotify_match.rb

Instance Method Summary collapse

Constructor Details

#initialize(results, options = {}) ⇒ SpotifyMatch

Returns a new instance of SpotifyMatch.



5
6
7
8
9
# File 'lib/spotify/music/importer/spotify_match.rb', line 5

def initialize(results, options = {})
  @results = results
  @clean_album = options.delete(:clean_album) { false }
  @clean_track = options.delete(:clean_track) { false }
end

Instance Method Details

#albumObject



27
28
29
30
31
32
33
# File 'lib/spotify/music/importer/spotify_match.rb', line 27

def album
  if @clean_album
    AlbumNameCleaner.new(@results["tracks"]['items'].first['album']['name']).clean
  else
    @results["tracks"]['items'].first['album']['name']
  end
end

#artistObject



23
24
25
# File 'lib/spotify/music/importer/spotify_match.rb', line 23

def artist
  @results["tracks"]['items'].first['artists'].first['name']
end

#found_match?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/spotify/music/importer/spotify_match.rb', line 11

def found_match?
  @results['tracks']['items'].count > 0
end

#idObject



35
36
37
# File 'lib/spotify/music/importer/spotify_match.rb', line 35

def id
  @results ["tracks"]["items"].first["id"]
end

#nameObject



15
16
17
18
19
20
21
# File 'lib/spotify/music/importer/spotify_match.rb', line 15

def name
  if @clean_track
    TrackNameCleaner.new(@results["tracks"]["items"].first["name"]).clean
  else
    @results["tracks"]["items"].first["name"]
  end
end

#to_sObject



39
40
41
# File 'lib/spotify/music/importer/spotify_match.rb', line 39

def to_s
  "Name: #{name} Album: #{album} Artist: #{artist} id: #{id}"
end