Class: CommandParser
- Inherits:
-
Object
- Object
- CommandParser
- Defined in:
- lib/command_parser.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(line) ⇒ CommandParser
constructor
A new instance of CommandParser.
- #is_command? ⇒ Boolean
- #parse ⇒ Object
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
10 11 12 |
# File 'lib/command_parser.rb', line 10 def command @command end |
#params ⇒ Object (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
12 13 14 |
# File 'lib/command_parser.rb', line 12 def is_command? !@command.nil? end |
#parse ⇒ Object
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 |