Class: Sh::Playlist
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(song) ⇒ Object
-
#initialize(name) ⇒ Playlist
constructor
A new instance of Playlist.
- #save! ⇒ Object
- #songs ⇒ Object
Constructor Details
#initialize(name) ⇒ Playlist
Returns a new instance of Playlist.
5 6 7 8 |
# File 'lib/sh_playlist.rb', line 5 def initialize name @name = name @songs = [] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/sh_playlist.rb', line 3 def name @name end |
Class Method Details
.parse(path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sh_playlist.rb', line 10 def self.parse(path) list = Playlist.new path.match(/\/([^\/]*)$/).captures.last open(path) do |f| while line = f.gets line.strip! unless line[0] == ?# or line.empty? # TODO: make cross-platform ref = File.(line.gsub('\\', '/'), File.dirname(path)) if File.exists? ref if Sh::Global::SUPPORTED_EXTENSIONS.include? File.extname(ref) list << ($db.songs(:path => ref).first || Sh::Song.new(ref).) end else Sh::Log.info "File at #{ref} not found" end end end end return list end |
Instance Method Details
#<<(song) ⇒ Object
31 32 33 |
# File 'lib/sh_playlist.rb', line 31 def <<(song) @songs << song end |
#save! ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sh_playlist.rb', line 39 def save! path = Sh::Global::PATHS[:playlists_file] playlists = [] if File.exists? path playlists = YAML.load_file path end playlists.reject! {|name, paths| name == @name} song_paths = @songs.map {|song| song.path} playlists << [@name, song_paths] open(path, 'w') {|f| f.puts playlists.to_yaml} end |
#songs ⇒ Object
35 36 37 |
# File 'lib/sh_playlist.rb', line 35 def songs return @songs.dup end |