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



25
26
27
# File 'lib/top_100/artist.rb', line 25

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.



30
31
32
33
# File 'lib/top_100/artist.rb', line 30

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

Instance Method Details

#display_detailsObject



16
17
18
19
20
21
22
23
# File 'lib/top_100/artist.rb', line 16

def display_details
  puts "Name: #{self.name}"
  puts "From: #{self.location}"
  puts "Formed: #{self.date} "
  song_names = self.songs.map {|song| song.name}
  puts "Currently Trending Songs: #{song_names.join(", ")}"
  puts "Bio: #{self.bio}"
end