Class: MusicExplorer::Artist

Inherits:
Object
  • Object
show all
Defined in:
lib/music_explorer/artist.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(artist_data = nil) ⇒ Artist

Returns a new instance of Artist.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/music_explorer/artist.rb', line 23

def initialize(artist_data = nil)
  #creates Artist object from the hash returned from the API
  if artist_data && artist_data.length > 0
    @name = artist_data[:name]
    @genres = artist_data[:genres]
    @top_tracks = artist_data[:top_tracks]
    @albums = artist_data[:albums]
    @related_artists = artist_data[:related_artists]
    @@all << self
  end
end

Instance Attribute Details

#albumsObject

Returns the value of attribute albums.



3
4
5
# File 'lib/music_explorer/artist.rb', line 3

def albums
  @albums
end

#genresObject

Returns the value of attribute genres.



3
4
5
# File 'lib/music_explorer/artist.rb', line 3

def genres
  @genres
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/music_explorer/artist.rb', line 3

def name
  @name
end

Returns the value of attribute related_artists.



3
4
5
# File 'lib/music_explorer/artist.rb', line 3

def related_artists
  @related_artists
end

#top_tracksObject

Returns the value of attribute top_tracks.



3
4
5
# File 'lib/music_explorer/artist.rb', line 3

def top_tracks
  @top_tracks
end

Class Method Details

.allObject



19
20
21
# File 'lib/music_explorer/artist.rb', line 19

def self.all
  @@all
end

.create_artist(artist_query) ⇒ Object



7
8
9
10
# File 'lib/music_explorer/artist.rb', line 7

def self.create_artist(artist_query)
  artist_data = lookup_artist(artist_query)
  self.new(artist_data)
end

.lookup_artist(artist_query) ⇒ Object



12
13
14
15
16
17
# File 'lib/music_explorer/artist.rb', line 12

def self.lookup_artist(artist_query)
  #Calls the API with the user's query, in order to get a hash of artist data
  
  api = MusicExplorer::API.new(artist_query)
  api.retrieve_artist_data
end