Sha256: 1060d644146257f3a45d3cae48c10d2d69b939e249d34e9b630c03a2cd30c20a

Contents?: true

Size: 754 Bytes

Versions: 1

Compression:

Stored size: 754 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 ()
			if @track.empty? 
				RSpotify::Album.search @query
			else
				RSpotify::Track.search @query
			end		 
		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.1 lib/spotify_osx_controller/search.rb