Sha256: 286ffb3a724789f6ebc1728179ae3c21dc3561cda79c8733bc058a60ce10e94a

Contents?: true

Size: 870 Bytes

Versions: 1

Compression:

Stored size: 870 Bytes

Contents

require 'patchmaster/list'
require 'patchmaster/list_container'

module PM

# A SongList is a list of Songs with a cursor.
class SongList

  attr_accessor :name, :songs

  include ListContainer

  def initialize(name)
    @name = name
    @songs = List.new
  end

  def <<(song)
    @songs << song
  end

  # Returns the first Song that matches +name+. +name+ may be either a
  # Regexp or a String. The match will be made case-insensitive. Does not
  # move or set the cursor.
  def find(name_regex)
    name_regex = Regexp.new(name_regex.to_s, true) # make case-insensitive
    @songs.detect { |s| s.name =~ name_regex }
  end

  %w(first prev curr next last).each do |dir|
    instance_eval("def #{dir}_patch; @songs.curr.#{dir}_patch; end")
  end

  # Called when moving out of this song list to another
  def stop_current_song
    @songs.stop_current
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
patchmaster-0.0.0 lib/patchmaster/song_list.rb