Module: Songbirdsh::Queue

Included in:
Player
Defined in:
lib/songbirdsh/queue.rb

Instance Method Summary collapse

Instance Method Details

#dequeueObject



17
18
19
20
21
22
23
24
# File 'lib/songbirdsh/queue.rb', line 17

def dequeue
  file = Dir.glob('*.song').sort.first
  return nil unless file
  hash = YAML.load(File.read(file))
  id = hash[:id] if hash
  FileUtils.rm file
  id
end

#eachObject



11
12
13
14
15
# File 'lib/songbirdsh/queue.rb', line 11

def each
  Dir.glob('*.song').sort.each do |file|
    yield YAML.load File.read(file)
  end
end

#enqueue(id) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/songbirdsh/queue.rb', line 3

def enqueue id
  @sequence ||= 0
  @library.with_track id do |track|
    File.open("#{Time.now.to_i}-#{@sequence.to_s.rjust(8,'0')}.song", 'w') {|f| f.print track.to_yaml }
    @sequence += 1
  end
end