Sha256: 660c916cbc7d952c81f9856dc8871f39d2fe134f772fb1cb4230a2b440b87f26

Contents?: true

Size: 663 Bytes

Versions: 8

Compression:

Stored size: 663 Bytes

Contents

module PM

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

  attr_accessor :name, :songs

  def initialize(name)
    @name = name
    @songs = []
  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
end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
patchmaster-1.1.2 lib/patchmaster/song_list.rb
patchmaster-1.0.0 lib/patchmaster/song_list.rb
patchmaster-0.0.6 lib/patchmaster/song_list.rb
patchmaster-0.0.5 lib/patchmaster/song_list.rb
patchmaster-0.0.4 lib/patchmaster/song_list.rb
patchmaster-0.0.3 lib/patchmaster/song_list.rb
patchmaster-0.0.2 lib/patchmaster/song_list.rb
patchmaster-0.0.1 lib/patchmaster/song_list.rb