Skip to content

Instantly share code, notes, and snippets.

@tzvetkoff
Created July 26, 2012 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzvetkoff/3182946 to your computer and use it in GitHub Desktop.
Save tzvetkoff/3182946 to your computer and use it in GitHub Desktop.
foobarbazbaz.rb
def collection_from_string(songs_as_string, artist_tags)
songs_as_string.strip.split("\n").map do |line|
name, artist, genre, tags = line.split('.').map(&:strip)
genre, subgenre = genre.split(',').map(&:strip)
tags = tags.to_s.split(',').push(genre).push(subgenre).concat(Array(artist_tags[artist])).reject(&:nil?).map(&:strip).map(&:downcase)
{:name => name, :artist => artist, :genre => genre, :subgenre => subgenre, :tags => tags}
end
end
def find_in_collection(collection, criteria)
collection.select do |song|
criteria.all? do |k, v|
if k == :filter
v.call(song)
else
Array(v).all? do |t|
(k == :tags && t.end_with?('!')) ^ song[k].include?(k == :tags && t.chomp('!') || t)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment