Class: Spotify::SongsHash
- Inherits:
-
Object
- Object
- Spotify::SongsHash
- Defined in:
- lib/spotifysearch/api_helper.rb
Overview
Search for a specfic track
Instance Attribute Summary collapse
-
#songs_hash ⇒ Object
Returns the value of attribute songs_hash.
Class Method Summary collapse
-
.create(search_result) ⇒ Object
Decompose the search_result and create a “Song” object for each album.
- .get_album_imgs(images) ⇒ Object
-
.get_artists(artists) ⇒ Object
We don’t flay get_artists and get_album_imgs method cause for future uses.
Instance Attribute Details
#songs_hash ⇒ Object
Returns the value of attribute songs_hash.
8 9 10 |
# File 'lib/spotifysearch/api_helper.rb', line 8 def songs_hash @songs_hash end |
Class Method Details
.create(search_result) ⇒ Object
Decompose the search_result and create a “Song” object for each album
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/spotifysearch/api_helper.rb', line 11 def self.create(search_result) @songs_hash = {} search_result.map do |song| @songs_hash[song['id']] = { id: song['id'], track_name: song['name'], link: song['external_urls']['spotify'], album: song['album']['name'], artist: get_artists(song['artists']), imgs: get_album_imgs(song['album']['images']) } end @songs_hash end |
.get_album_imgs(images) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/spotifysearch/api_helper.rb', line 34 def self.get_album_imgs(images) # Return an array including all url of each size of image # imgs[0]:L, imgs[1]:M, imgs[2]:S imgs = [] images.each { |img| imgs.push(img['url']) } imgs end |
.get_artists(artists) ⇒ Object
We don’t flay get_artists and get_album_imgs method cause for future uses.
25 26 27 28 29 30 31 32 |
# File 'lib/spotifysearch/api_helper.rb', line 25 def self.get_artists(artists) # Return an array including all artists of the song arr = [] artists.each do |artist| arr.push(artist['name']) end arr end |