class Song

Attributes

artists[RW]
chart_status[RW]
title[RW]

Public Class Methods

all() click to toggle source
# File lib/Hot_100_CLI/song.rb, line 21
def self.all
  @@all
end
create(song_hash) click to toggle source
# File lib/Hot_100_CLI/song.rb, line 13
def self.create(song_hash)
  song = Song.new(song_hash[:title])
  song.spotify_link = song_hash[:spotify_link]
  song.vevo_link = song_hash[:vevo_link]
  song.save
  song
end
find_by_rank(int) click to toggle source
# File lib/Hot_100_CLI/song.rb, line 33
def self.find_by_rank(int)
  Song.all.detect { |song| song.rank == int.to_i }
end
find_by_title(title) click to toggle source
# File lib/Hot_100_CLI/song.rb, line 29
def self.find_by_title(title)
  Song.all.detect { |song| song.title.downcase == title.downcase }
end
new(title) click to toggle source
# File lib/Hot_100_CLI/song.rb, line 8
def initialize(title)
  @title = title
  @artists = []
end

Public Instance Methods

artist_listing() click to toggle source
# File lib/Hot_100_CLI/song.rb, line 57
def artist_listing
  if artists.length < 3
    artists.map { |artist| artist.name }.join(" Featuring ")
  else
    listing = artists[0].name + " Featuring " + artists[1].name
    artists.each_with_index do |artist, i|
      listing += " & " + artist.name if i > 1
    end
    listing
  end
end
peak_position() click to toggle source
# File lib/Hot_100_CLI/song.rb, line 49
def peak_position
  chart_status.peak_position
end
previous_week() click to toggle source
# File lib/Hot_100_CLI/song.rb, line 53
def previous_week
  chart_status.previous_week
end
rank() click to toggle source

association methods

# File lib/Hot_100_CLI/song.rb, line 41
def rank
  chart_status.rank
end
save() click to toggle source
# File lib/Hot_100_CLI/song.rb, line 25
def save
  @@all << self
end
weeks_charted() click to toggle source
# File lib/Hot_100_CLI/song.rb, line 45
def weeks_charted
  chart_status.weeks_charted
end