Class: Pantograph::CommandParser
- Inherits:
-
Object
- Object
- Pantograph::CommandParser
- Defined in:
- pantograph/lib/pantograph/server/command_parser.rb
Class Method Summary collapse
- .handle_new_style_commands(command_json: nil) ⇒ Object
- .handle_old_style_action_command(command_json: nil) ⇒ Object
- .intercept_old_done_command ⇒ Object
- .parse(json: nil) ⇒ Object
Class Method Details
.handle_new_style_commands(command_json: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'pantograph/lib/pantograph/server/command_parser.rb', line 16 def self.handle_new_style_commands(command_json: nil) command_type = command_json['commandType'].to_sym command = command_json['command'] case command_type when :action return ActionCommand.new(json: command) when :control return ControlCommand.new(json: command) end end |
.handle_old_style_action_command(command_json: nil) ⇒ Object
28 29 30 |
# File 'pantograph/lib/pantograph/server/command_parser.rb', line 28 def self.handle_old_style_action_command(command_json: nil) return ActionCommand.new(json: command_json) end |
.intercept_old_done_command ⇒ Object
32 33 34 |
# File 'pantograph/lib/pantograph/server/command_parser.rb', line 32 def self.intercept_old_done_command return ControlCommand.new(json: '{"command":"done"}') end |
.parse(json: nil) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'pantograph/lib/pantograph/server/command_parser.rb', line 7 def self.parse(json: nil) if json.strip == "done" return intercept_old_done_command end command_json = JSON.parse(json) return handle_new_style_commands(command_json: command_json) end |