Class: Top100::Artist

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

Constant Summary collapse

CURRENT_HITS =
Top100::BillboardScraper.new.scrape_from_chart_page

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#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

.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_hitsObject



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_detailsObject



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