Class: CommandParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ CommandParser

Returns a new instance of CommandParser.



3
4
5
6
7
8
# File 'lib/command_parser.rb', line 3

def initialize(line)
  @line = line
  @command = nil
  @params = nil
  parse
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



10
11
12
# File 'lib/command_parser.rb', line 10

def command
  @command
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/command_parser.rb', line 10

def params
  @params
end

Instance Method Details

#is_command?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/command_parser.rb', line 12

def is_command?
  !@command.nil?
end

#parseObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/command_parser.rb', line 16

def parse
  m = @line.match /^\s*\.(\w+) *(.*)$/
  return if m.nil?
  @command = m[1].to_sym
  @params = m[2].split(' ').compact.map{|p| p.split(".")}.flatten
  case @command
    when "find"
    when "explain"
    when "use"
  end
end