Created
August 5, 2012 09:20
-
-
Save zarkzork/3263264 to your computer and use it in GitHub Desktop.
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
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