Find file
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (25 sloc) 682 Bytes
$stdout.sync = $stderr.sync = true
@delimiter = ';;;'
# expose methods:
def parse(str)
Chronic.parse(str)
end
# input loop
$stdin.each_line do |line|
@buffer ||= ""
@buffer << line
begin
req = JSON.parse(@buffer)
@buffer = ""
res = {}
params = req['params'] || []
res['result'] = self.send(req['method'].to_sym, *params)
res['error'] = "Could not parse date: #{params.to_s}" if res['result'].nil?
# expecting an answer?
res['id'] = req['id'] if req['id'].is_a?(Integer)
$stdout.write(res.to_json+@delimiter) && $stdout.flush
rescue
res = {:error=>'FUUUUCK'}
$stderr.write(res.to_json+@delimiter) && $stderr.flush
end
end