Class: SpotTracks::Track
- Inherits:
-
Object
- Object
- SpotTracks::Track
- Defined in:
- lib/spot_tracks/track.rb
Instance Attribute Summary collapse
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Track
constructor
A new instance of Track.
- #title ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Track
Returns a new instance of Track.
5 6 7 8 9 10 |
# File 'lib/spot_tracks/track.rb', line 5 def initialize(params = {}) @name = params[:name] @artist = params[:artist] @image = params[:image] @uri = params[:uri] end |
Instance Attribute Details
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
3 4 5 |
# File 'lib/spot_tracks/track.rb', line 3 def artist @artist end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
3 4 5 |
# File 'lib/spot_tracks/track.rb', line 3 def image @image end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/spot_tracks/track.rb', line 3 def name @name end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/spot_tracks/track.rb', line 3 def uri @uri end |
Class Method Details
.parse(data = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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'].first new({ name: item['name'], artist: artist['name'], image: image['url'], uri: item['uri'] }) end |
.search(title) ⇒ Object
12 13 14 |
# File 'lib/spot_tracks/track.rb', line 12 def self.search(title) SpotTracks::Player.new.search(title) end |
Instance Method Details
#title ⇒ Object
33 34 35 |
# File 'lib/spot_tracks/track.rb', line 33 def title "#{artist} - #{name}" end |
#to_h ⇒ Object
37 38 39 40 41 42 |
# File 'lib/spot_tracks/track.rb', line 37 def to_h { title: title, name: name, artist: artist, urls: { image: image, uri: uri } } end |