Sha256: 2e6464330b3df76a477bad8f699b49379026d7eb4808c81eadb2604df99e94ab

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

require "rspotify"

module SpotifyOsxController

	class Search

		def initialize (parameters = {})
			@track = parse parameters[:track]
			@artist = parse parameters[:artist]
			@album = parse parameters[:album]
			@query = construct_query
			@results = run_query
		end

		def any?
			@results.any?
		end

		def first
			@results.first
		end

		private 

		def run_query () 
			RSpotify::Track.search @query 
		end

		def parse (array)
			array.join('+') if array
		end

		def construct_query
			query = ""
			query += "artist:#{@artist} " if !@artist.empty? 
			query += "track:#{@track} " if !@track.empty?
			query += "album:#{@album}" if !@album.empty?
			query
		end
	end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spotify_osx_controller-2.0.0 lib/spotify_osx_controller/search.rb