11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/tempest/repl/dispatcher.rb', line 11
def dispatch(input)
return Command.new(name: :quit, args: []) if input.nil?
stripped = input.strip
return Command.new(name: :noop, args: []) if stripped.empty?
if stripped.start_with?(":")
name, *rest = stripped[1..].split(/\s+/)
symbol = name.to_sym
if KNOWN_COMMANDS.include?(symbol)
Command.new(name: symbol, args: rest)
else
Command.new(name: :unknown, args: [name])
end
else
head, tail = stripped.split(/\s+/, 2)
if DOLLAR_ID.match?(head)
Command.new(name: :reply, args: [head, tail.to_s])
else
Command.new(name: :post, args: [stripped])
end
end
end
|