Class: Muzak::Playlist
- Inherits:
-
Object
- Object
- Muzak::Playlist
- Defined in:
- lib/muzak/playlist.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#songs ⇒ Object
Returns the value of attribute songs.
Class Method Summary collapse
Instance Method Summary collapse
- #add(song) ⇒ Object
- #delete(song) ⇒ Object
-
#initialize(name, songs) ⇒ Playlist
constructor
A new instance of Playlist.
- #shuffle! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, songs) ⇒ Playlist
Returns a new instance of Playlist.
23 24 25 26 |
# File 'lib/muzak/playlist.rb', line 23 def initialize(name, songs) @name = name @songs = songs end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/muzak/playlist.rb', line 3 def name @name end |
#songs ⇒ Object
Returns the value of attribute songs.
3 4 5 |
# File 'lib/muzak/playlist.rb', line 3 def songs @songs end |
Class Method Details
.load_playlist(path) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/muzak/playlist.rb', line 13 def self.load_playlist(path) instance = allocate playlist_hash = YAML.load_file(path) instance.name = File.basename(path, File.extname(path)) instance.songs = playlist_hash["songs"] instance end |
.playlist_names ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/muzak/playlist.rb', line 5 def self.playlist_names Dir.entries(PLAYLIST_DIR).reject do |ent| ent.start_with?(".") end.map do |ent| File.basename(ent, File.extname(ent)) end end |
Instance Method Details
#add(song) ⇒ Object
28 29 30 31 |
# File 'lib/muzak/playlist.rb', line 28 def add(song) return if @songs.include?(song) @songs << song end |
#delete(song) ⇒ Object
33 34 35 |
# File 'lib/muzak/playlist.rb', line 33 def delete(song) @songs.delete(song) end |
#shuffle! ⇒ Object
37 38 39 |
# File 'lib/muzak/playlist.rb', line 37 def shuffle! @songs.shuffle! end |
#to_hash ⇒ Object
41 42 43 |
# File 'lib/muzak/playlist.rb', line 41 def to_hash { "songs" => songs } end |