Skip to content

Instantly share code, notes, and snippets.

@madx
Created November 4, 2009 09:40
Show Gist options
  • Save madx/225917 to your computer and use it in GitHub Desktop.
Save madx/225917 to your computer and use it in GitHub Desktop.
Transform a text query to a Sequel filter
def to_filter(query)
query.split(/ +/).map { |chunk|
case chunk
when /^by:(.+)/
{:author => $~[1]}
when /^is:(.+)/
{:status => $~[1]}
else
:title.like("%#{chunk}%")
end
}.inject(:ctime) {|f,e| e & f }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment