Sha256: aa4ecc41de7a636e2559159a719c1a3e00186e3771114ed998cbc3caaefd0c0a

Contents?: true

Size: 651 Bytes

Versions: 1

Compression:

Stored size: 651 Bytes

Contents

module AirPlayer
  class Playlist < Array
    def initialize(options = {})
      @shuffle = options['shuffle'] || false
      @repeat  = options['repeat']  || false
    end

    def add(item)
      path = File.expand_path(item)
      Dir.exists?(path) ? concat(media_in(path)) : push(Media.new(item))
      self
    end

    def entries(&blk)
      loop do
        shuffle! if @shuffle
        send(:each, &blk)
        break unless @repeat
      end
    end

    private
      def media_in(path)
        Dir.entries(path).map do |node|
          Media.new(File.expand_path(node, path)) if Media.playable? node
        end.compact
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
airplayer-0.0.5 lib/airplayer/playlist.rb