Class: MrEko::Playlist
- Defined in:
- lib/mr_eko/playlist.rb
Direct Known Subclasses
Constant Summary collapse
- FORMATS =
[:pls, :m3u, :text].freeze
- DEFAULT_OPTIONS =
[ {:tempo => 0..500}, {:duration => 10..1200} ].freeze
Constants included from Presets
Class Method Summary collapse
-
.create_from_options(options) ⇒ Object
Creates and returns a new Playlist from the passed
options. -
.prepare_options(options) ⇒ Object
Organize and transform!.
Instance Method Summary collapse
-
#output(format = :pls) ⇒ Object
Return the formatted playlist.
Methods included from Presets
Methods included from Core
#before_create, #before_update, included
Class Method Details
.create_from_options(options) ⇒ Object
Creates and returns a new Playlist from the passed options. options should be finder options you pass to Song plus (optionally) :name.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mr_eko/playlist.rb', line 14 def self.() # TODO: Is a name (or persisting) even necessary? MrEko.connection.transaction do pl = create(:name => .delete(:name) || "Playlist #{rand(10000)}") filter = apply_filters () songs = filter.all if songs.size > 0 songs.each{ |song| pl.add_song(song) } pl.save else raise MrEko::NoSongsError.new("No songs match those criteria!") end end end |
.prepare_options(options) ⇒ Object
Organize and transform!
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mr_eko/playlist.rb', line 32 def self.() if preset = .delete(:preset) = load_preset(preset) else = DEFAULT_OPTIONS.reject{ |d| .keys.include?(d.keys.first) } .each do |key, value| case key when :danceability, :energy << transform(key, value, true) when :mode << transform(key, MrEko.mode_lookup(value)) when :key << transform(key, MrEko.key_lookup(value)) else << transform(key, value) end end end end |
Instance Method Details
#output(format = :pls) ⇒ Object
Return the formatted playlist.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mr_eko/playlist.rb', line 63 def output(format = :pls) format = format.to_sym raise ArgumentError.new("Format must be one of #{FORMATS.join(', ')}") unless FORMATS.include? format case format when :text create_text when :m3u create_m3u else create_pls end end |