class SpotTracks::Track
Attributes
artist[R]
image[R]
name[R]
uri[R]
Public Class Methods
new(params = {})
click to toggle source
# File lib/spot_tracks/track.rb, line 5 def initialize(params = {}) @name = params[:name] @artist = params[:artist] @image = params[:image] @uri = params[:uri] end
parse(data = {})
click to toggle source
# File lib/spot_tracks/track.rb, line 16 def self.parse(data = {}) tracks = data.fetch('tracks', {}) item = tracks.fetch('items', []).first return if item.nil? album = item['album'] artist = item['artists'].first image = album['images'].detect{|i| i['height'] == 300 } new({ name: item['name'], artist: artist['name'], image: image['url'], uri: item['uri'] }) end
search(title)
click to toggle source
# File lib/spot_tracks/track.rb, line 12 def self.search(title) SpotTracks::Player.new.search(title) end
Public Instance Methods
title()
click to toggle source
# File lib/spot_tracks/track.rb, line 33 def title "#{artist} - #{name}" end
to_h()
click to toggle source
# File lib/spot_tracks/track.rb, line 37 def to_h { title: title, name: name, artist: artist, urls: { image: image, uri: uri } } end