Class: BillboardHot100Songs::Song
- Inherits:
-
Object
- Object
- BillboardHot100Songs::Song
- Defined in:
- lib/billboard_hot_100_songs/song.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#delta ⇒ Object
Returns the value of attribute delta.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#name ⇒ Object
Returns the value of attribute name.
-
#peak_rank ⇒ Object
Returns the value of attribute peak_rank.
-
#rank_last_week ⇒ Object
Returns the value of attribute rank_last_week.
-
#rank_this_week ⇒ Object
Returns the value of attribute rank_this_week.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_array(song_array) ⇒ Object
-
.find_by_rank_this_week(rank_this_week) ⇒ Object
UNUSED METHODS - MAY BE USEFUL FOR FUTURE PROGRAMS.
-
.select_new_songs ⇒ Object
SONGS BY DURATION.
-
.select_no_1_peak_songs ⇒ Object
SONGS BY PEAK RANK.
- .select_top_10_by_duration ⇒ Object
-
.sort_by_duration ⇒ Object
By descending order.
- .sort_by_peak_rank ⇒ Object
-
.sort_by_rank_this_week ⇒ Object
SONGS BY RANK.
Instance Method Summary collapse
-
#initialize(song_hash) ⇒ Song
constructor
A new instance of Song.
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
#artist ⇒ Object
Returns the value of attribute artist.
3 4 5 |
# File 'lib/billboard_hot_100_songs/song.rb', line 3 def artist @artist end |
#delta ⇒ Object
Returns the value of attribute delta.
3 4 5 |
# File 'lib/billboard_hot_100_songs/song.rb', line 3 def delta @delta end |
#duration ⇒ Object
Returns the value of attribute duration.
3 4 5 |
# File 'lib/billboard_hot_100_songs/song.rb', line 3 def duration @duration end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/billboard_hot_100_songs/song.rb', line 3 def name @name end |
#peak_rank ⇒ Object
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_week ⇒ Object
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_week ⇒ Object
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
.all ⇒ Object
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_songs ⇒ Object
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_songs ⇒ Object
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_duration ⇒ Object
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_duration ⇒ Object
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_rank ⇒ Object
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_week ⇒ Object
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 |