Class: RTunnel::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/cmds.rb,
lib/cmds.rb

Constant Summary collapse

CODES_TO_CLASSES =
{
  "C" => CreateConnectionCommand,
  "X" => CloseConnectionCommand,
  "D" => SendDataCommand,
  "P" => PingCommand,
  "L" => RemoteListenCommand,
}
CLASSES_TO_CODES =
CODES_TO_CLASSES.invert

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match(data) ⇒ Object



20
21
22
23
24
# File 'lib/cmds.rb', line 20

def match(data)
  return false  if ! (klass = class_from_code(data[0..0]))

  klass.match(data[1..-1])
end

.parse(data) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/cmds.rb', line 9

def parse(data)
  klass = class_from_code(data[0..0])

  new_data = data[1..-1]
  cmd = klass.parse(new_data)

  data.replace(new_data)

  cmd
end

Instance Method Details

#to_sObject



4
5
6
# File 'lib/cmds.rb', line 4

def to_s
  CLASSES_TO_CODES[self.class].dup
end