ruby on rails - Finding an Album's Artist with the Spotify API -
i'm trying use rails gem spotify api find artist(s) of particular album. start retrieving name of album such:
album_results = rspotify::album.search("the eminem show") to find artist of album issued following method variable above:
album_results.artists this returns ton of data don't need. want name of artist. able accomplish partially doing:
album_results.first.artists.first.name => "eminem" what i'd return name of available artists album results. tried using select method once again got data wanted:
album_results.select {|album| album.artists} what best approach accomplish this?
using select here return records artists.
you need use either collect or map
my_artists = album_results.flat_map{ |album| album.artists.collect{|artist| artist.name} } edit
use flat_map returns flattened array default.
more efficient using collect , flatten!
Comments
Post a Comment