Class: Artist

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

Constant Summary collapse

@@artists =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(artist_name) ⇒ Artist

Songs already initialized, search for matching songs using name.



6
7
8
9
10
11
12
13
14
# File 'lib/top_100/artist.rb', line 6

def initialize(artist_name)
  @songs = Song.all.select {|song| song.artist_name == artist_name}
  if @songs.empty?
    self.name = nil
  else
    BillboardScraper.scrape_from_artist_bio_page(@songs[0].artist_url).each {|key, value| self.send("#{key}=", value)}
    @@artists << self
  end
end

Instance Attribute Details

#bioObject

Returns the value of attribute bio.



2
3
4
# File 'lib/top_100/artist.rb', line 2

def bio
  @bio
end

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/top_100/artist.rb', line 2

def date
  @date
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/top_100/artist.rb', line 2

def location
  @location
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/top_100/artist.rb', line 2

def name
  @name
end

#songsObject

Returns the value of attribute songs.



2
3
4
# File 'lib/top_100/artist.rb', line 2

def songs
  @songs
end

Class Method Details

.allObject



16
17
18
# File 'lib/top_100/artist.rb', line 16

def self.all
  @@artists
end

.find_or_create(artist_name) ⇒ Object

Artists have unique names, search for a match using the name or create a new Artist object. ISSUE: song.artist_name and Artist.name will not match if the song has collaborators, meaning that a new artist object will be created each time.



22
23
24
25
# File 'lib/top_100/artist.rb', line 22

def self.find_or_create(artist_name)
  Artist.all.each {|artist| return artist if artist.name == artist_name}
  Artist.new(artist_name)
end