Class: Shellissimo::InputParser
- Inherits:
-
Object
- Object
- Shellissimo::InputParser
- Defined in:
- lib/shellissimo/input_parser.rb
Constant Summary collapse
- COMMAND_PATTERN =
/(\w+)(?:\s*(.*))/
Instance Method Summary collapse
-
#initialize(commands) ⇒ InputParser
constructor
A new instance of InputParser.
-
#parse_command(line) ⇒ Command
A command with pre-populated params.
Constructor Details
#initialize(commands) ⇒ InputParser
Returns a new instance of InputParser.
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.
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 |