Class: Shellissimo::InputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/shellissimo/input_parser.rb

Constant Summary collapse

COMMAND_PATTERN =
/(\w+)(?:\s*(.*))/

Instance Method Summary collapse

Constructor Details

#initialize(commands) ⇒ InputParser

Returns a new instance of InputParser.

Parameters:



11
12
13
# File 'lib/shellissimo/input_parser.rb', line 11

def initialize(commands)
  @commands = commands
end

Instance Method Details

#parse_command(line) ⇒ Command

Returns a command with pre-populated params.

Parameters:

  • line (String)

    a line of input from shell

Returns:

  • (Command)

    a command with pre-populated params



19
20
21
22
23
# File 'lib/shellissimo/input_parser.rb', line 19

def parse_command(line)
  command_name, command_params = line.match(COMMAND_PATTERN)[1..2]
  command = @commands[command_name]
  command.prepend_params(parse_params(command_params))
end