Class: Top100::Artist
- Inherits:
-
Object
- Object
- Top100::Artist
- Defined in:
- lib/top_100/artist.rb
Constant Summary collapse
- CURRENT_HITS =
Top100::BillboardScraper.new.scrape_from_chart_page
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
Instance Method Summary collapse
- #add_current_hits ⇒ Object
- #display_details ⇒ Object
-
#initialize(artist_hash) ⇒ Artist
constructor
A new instance of Artist.
Constructor Details
#initialize(artist_hash) ⇒ Artist
Returns a new instance of Artist.
5 6 7 8 9 |
# File 'lib/top_100/artist.rb', line 5 def initialize(artist_hash) artist_hash.each {|key, value| self.send("#{key}=", value)} @songs = [] self.add_current_hits 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
.create_artist(rank) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/top_100/artist.rb', line 23 def self.create_artist(rank) info_hash = CURRENT_HITS.find { |hit| hit[:current_rank] == rank } unless info_hash == nil artist_hash = Top100::BillboardScraper.new.scrape_from_artist_bio_page(info_hash[:artist_bio_link]) artist = self.new(artist_hash) artist end end |
Instance Method Details
#add_current_hits ⇒ Object
11 12 13 |
# File 'lib/top_100/artist.rb', line 11 def add_current_hits CURRENT_HITS.each { |hit| self.songs << hit[:song_name] if hit[:song_artist].include?(self.name) } end |
#display_details ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/top_100/artist.rb', line 15 def display_details puts "Name: #{self.name}" puts "From: #{self.location}" puts "Formed: #{self.date} " puts "Currently Trending Songs: #{self.songs.join(", ")}" puts "Bio: #{self.bio}" end |