Created
May 21, 2010 07:46
-
-
Save kasima/408595 to your computer and use it in GitHub Desktop.
sinatra suggester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
require 'json' | |
input = 'suggestions.txt' | |
suggestions = [] | |
File.open(input, 'r').each { |line| suggestions << line.strip } | |
get '/:q' do | |
matches = suggestions.find_all{ |s| s.match(params[:q]) }[0..9] | |
halt 200, {'Content-Type' => 'text/json'}, matches.to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment