Class: Artist
- Inherits:
-
Object
- Object
- Artist
- Defined in:
- lib/top_100/artist.rb
Constant Summary collapse
- @@artists =
[]
Instance Attribute Summary collapse
-
#bio ⇒ Object
Returns the value of attribute bio.
-
#date ⇒ Object
Returns the value of attribute date.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#songs ⇒ Object
Returns the value of attribute songs.
Class Method Summary collapse
- .all ⇒ Object
-
.find_or_create(artist_name) ⇒ Object
Artists have unique names, search for a match using the name or create a new Artist object.
Instance Method Summary collapse
-
#initialize(artist_name) ⇒ Artist
constructor
Songs already initialized, search for matching songs using name.
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
#bio ⇒ Object
Returns the value of attribute bio.
2 3 4 |
# File 'lib/top_100/artist.rb', line 2 def bio @bio end |
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/top_100/artist.rb', line 2 def date @date end |
#location ⇒ Object
Returns the value of attribute location.
2 3 4 |
# File 'lib/top_100/artist.rb', line 2 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/top_100/artist.rb', line 2 def name @name end |
#songs ⇒ Object
Returns the value of attribute songs.
2 3 4 |
# File 'lib/top_100/artist.rb', line 2 def songs @songs end |
Class Method Details
.all ⇒ Object
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 |