Class: BillboardHot100Songs::Song

Inherits:
Object
  • Object
show all
Defined in:
lib/billboard_hot_100_songs/song.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(song_hash) ⇒ Song

Returns a new instance of Song.



7
8
9
10
# File 'lib/billboard_hot_100_songs/song.rb', line 7

def initialize(song_hash)
    song_hash.each {|key, value| self.send("#{key}=", value)}
    self.class.all << self
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



3
4
5
# File 'lib/billboard_hot_100_songs/song.rb', line 3

def artist
  @artist
end

#deltaObject

Returns the value of attribute delta.



3
4
5
# File 'lib/billboard_hot_100_songs/song.rb', line 3

def delta
  @delta
end

#durationObject

Returns the value of attribute duration.



3
4
5
# File 'lib/billboard_hot_100_songs/song.rb', line 3

def duration
  @duration
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/billboard_hot_100_songs/song.rb', line 3

def name
  @name
end

#peak_rankObject

Returns the value of attribute peak_rank.



3
4
5
# File 'lib/billboard_hot_100_songs/song.rb', line 3

def peak_rank
  @peak_rank
end

#rank_last_weekObject

Returns the value of attribute rank_last_week.



3
4
5
# File 'lib/billboard_hot_100_songs/song.rb', line 3

def rank_last_week
  @rank_last_week
end

#rank_this_weekObject

Returns the value of attribute rank_this_week.



3
4
5
# File 'lib/billboard_hot_100_songs/song.rb', line 3

def rank_this_week
  @rank_this_week
end

Class Method Details

.allObject



16
17
18
# File 'lib/billboard_hot_100_songs/song.rb', line 16

def self.all
    @@all
end

.create_from_array(song_array) ⇒ Object



12
13
14
# File 'lib/billboard_hot_100_songs/song.rb', line 12

def self.create_from_array(song_array)
    song_array.each {|song_hash| self.new(song_hash)}
end

.find_by_rank_this_week(rank_this_week) ⇒ Object

UNUSED METHODS - MAY BE USEFUL FOR FUTURE PROGRAMS



52
53
54
# File 'lib/billboard_hot_100_songs/song.rb', line 52

def self.find_by_rank_this_week(rank_this_week)
    self.all.find{|song| song.rank_this_week == rank_this_week}
end

.select_new_songsObject

SONGS BY DURATION



28
29
30
# File 'lib/billboard_hot_100_songs/song.rb', line 28

def self.select_new_songs
    self.sort_by_rank_this_week.select {|song| song.duration == "1"}
end

.select_no_1_peak_songsObject

SONGS BY PEAK RANK



42
43
44
# File 'lib/billboard_hot_100_songs/song.rb', line 42

def self.select_no_1_peak_songs
    self.sort_by_rank_this_week.select {|song| song.peak_rank == "1"}
end

.select_top_10_by_durationObject



36
37
38
# File 'lib/billboard_hot_100_songs/song.rb', line 36

def self.select_top_10_by_duration
    self.sort_by_duration[0, 10]
end

.sort_by_durationObject

By descending order



32
33
34
# File 'lib/billboard_hot_100_songs/song.rb', line 32

def self.sort_by_duration # By descending order
    self.all.sort_by {|song| song.duration.to_i}.reverse
end

.sort_by_peak_rankObject



46
47
48
# File 'lib/billboard_hot_100_songs/song.rb', line 46

def self.sort_by_peak_rank
    self.all.sort_by {|song| song.peak_rank.to_i}
end

.sort_by_rank_this_weekObject

SONGS BY RANK



22
23
24
# File 'lib/billboard_hot_100_songs/song.rb', line 22

def self.sort_by_rank_this_week
    self.all.sort_by {|song| song.rank_this_week.to_i}
end