Extract query construction

This commit is contained in:
Jack Nagel 2013-06-12 14:48:16 -05:00
parent 90768d03d2
commit 1d1c292bcb

View File

@ -13,13 +13,7 @@ module Homebrew extend self
exec_browser "http://packages.debian.org/search?keywords=#{ARGV.next}&searchon=names&suite=all&section=all" exec_browser "http://packages.debian.org/search?keywords=#{ARGV.next}&searchon=names&suite=all&section=all"
else else
query = ARGV.first query = ARGV.first
rx = case query rx = query_regexp(query)
when nil then ""
when %r{^/(.*)/$} then Regexp.new($1)
else
/.*#{Regexp.escape query}.*/i
end
search_results = search_brews rx search_results = search_brews rx
puts_columns search_results puts_columns search_results
@ -61,6 +55,14 @@ module Homebrew extend self
end end
end end
def query_regexp(query)
case query
when nil then ""
when %r{^/(.*)/$} then Regexp.new($1)
else /.*#{Regexp.escape(query)}.*/i
end
end
def search_tap user, repo, rx def search_tap user, repo, rx
return [] if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}-#{repo.downcase}").directory? return [] if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}-#{repo.downcase}").directory?