Sha256: def2929cfeae6ca5aec5c14606e28e5bb7f1e4212a67ccabd52a48cc0bdcd251

Contents?: true

Size: 952 Bytes

Versions: 18

Compression:

Stored size: 952 Bytes

Contents

require 'pantograph/server/action_command.rb'
require 'pantograph/server/control_command.rb'
require 'json'

module Pantograph
  class CommandParser
    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

    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

    def self.handle_old_style_action_command(command_json: nil)
      return ActionCommand.new(json: command_json)
    end

    def self.intercept_old_done_command
      return ControlCommand.new(json: '{"command":"done"}')
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pantograph-0.1.22 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.21 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.20 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.19 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.17 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.16 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.15 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.14 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.13 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.12 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.10 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.8 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.7 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.6 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.4 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.3 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.1 pantograph/lib/pantograph/server/command_parser.rb
pantograph-0.1.0 pantograph/lib/pantograph/server/command_parser.rb