Class: MrEko::TimedPlaylist
- Defined in:
- lib/mr_eko/timed_playlist.rb
Constant Summary
Constants inherited from Playlist
Playlist::DEFAULT_OPTIONS, Playlist::FORMATS
Constants included from Presets
Instance Attribute Summary collapse
-
#facet ⇒ Object
The name of the Song attribute to build on (tempo, key, etc.).
-
#final ⇒ Object
The start and end value for the facet.
-
#initial ⇒ Object
The start and end value for the facet.
-
#length ⇒ Object
The number of seconds the playlist should be.
Instance Method Summary collapse
-
#after_save ⇒ Object
Have to add songs after save due to the Playlist needing to have a primary key (generated at time of save).
-
#before_save ⇒ Object
Run these essential steps before saving, so that any fatal exception halt the creation of the playlist.
-
#initialize(opts = {}) ⇒ TimedPlaylist
constructor
A new instance of TimedPlaylist.
Methods inherited from Playlist
create_from_options, #output, prepare_options
Methods included from Presets
Methods included from Core
#before_create, #before_update, included
Constructor Details
#initialize(opts = {}) ⇒ TimedPlaylist
Returns a new instance of TimedPlaylist.
12 13 14 15 16 17 |
# File 'lib/mr_eko/timed_playlist.rb', line 12 def initialize(opts={}) @facet = opts.delete(:facet) @length = opts.delete(:length).to_i super end |
Instance Attribute Details
#facet ⇒ Object
The name of the Song attribute to build on (tempo, key, etc.).
7 8 9 |
# File 'lib/mr_eko/timed_playlist.rb', line 7 def facet @facet end |
#final ⇒ Object
The start and end value for the facet
10 11 12 |
# File 'lib/mr_eko/timed_playlist.rb', line 10 def final @final end |
#initial ⇒ Object
The start and end value for the facet
10 11 12 |
# File 'lib/mr_eko/timed_playlist.rb', line 10 def initial @initial end |
#length ⇒ Object
The number of seconds the playlist should be.
4 5 6 |
# File 'lib/mr_eko/timed_playlist.rb', line 4 def length @length end |
Instance Method Details
#after_save ⇒ Object
Have to add songs after save due to the Playlist needing to have a primary key (generated at time of save). Lame.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mr_eko/timed_playlist.rb', line 28 def after_save songs = @song_groups.sort_by{ |group| cost_of group }.first # Sort em direction = final - initial > 0 ? :asc : :desc songs = songs.sort_by(&facet) songs = songs.reverse if direction == :desc songs.each_with_index do |song, position| MrEko::PlaylistEntry.create(:playlist_id => self.id, :song_id => song.id, :position => position) end end |
#before_save ⇒ Object
Run these essential steps before saving, so that any fatal exception halt the creation of the playlist.
21 22 23 24 |
# File 'lib/mr_eko/timed_playlist.rb', line 21 def before_save prepare_attributes find_song_groups! end |