Skip to content

Instantly share code, notes, and snippets.

@zarkzork
Created August 5, 2012 09:20
Show Gist options
  • Save zarkzork/3263264 to your computer and use it in GitHub Desktop.
Save zarkzork/3263264 to your computer and use it in GitHub Desktop.
class Server
def parse_command
line = $stdin.readline.chomp
command, arguments = line.split(' ', 2)
if commands.include?(command)
self.send(command, arguments)
else
puts "ERROR: no such command: #{command}"
end
end
private
def commands; %w[init search]; end
def init(arguments)
path, *extensions_part = arguments.split(' ')
@engine = Engine.new('data', ['.rb'])
puts 'ok'
end
def search(arguments)
if @engine
results = @engine.search(arguments)
puts results.map{ |file, line, string| "#{file}:#{line} #{string}"}
puts "ok"
else
puts "ERROR: you need to issue init first."
end
end
end
@server = Server.new
@server.parse_command while true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment