Class: HammerCLI::CompleterWord

Inherits:
String
  • Object
show all
Defined in:
lib/hammer_cli/completer.rb

Overview

Single “word” on a command line to complete. It contains trailing spaces to recognize whether the word is complete or not. –param[ ]* or -flag[ ]* or [‘“]?word?[ ]*

Instance Method Summary collapse

Methods inherited from String

#camelize, #constantize, #format, #indent_with, #underscore, #wrap

Constructor Details

#initialize(str) ⇒ CompleterWord

Returns a new instance of CompleterWord.



11
12
13
14
15
16
17
18
19
# File 'lib/hammer_cli/completer.rb', line 11

def initialize(str)
  @original = str
  if quoted?
    str = str.gsub(/^['"]/, '').gsub(/['"]\s*$/, '')
  else
    str = str.strip
  end
  super(str)
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/hammer_cli/completer.rb', line 29

def complete?
  if quoted?
    @original.strip.gsub(/^['"].*['"][\s]*$/, '') == ""
  else
    @original[-1,1] == " "
  end
end

#quoteObject



25
26
27
# File 'lib/hammer_cli/completer.rb', line 25

def quote
  @original.gsub(/^(['"]?)(.*)$/, '\1')
end

#quoted?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/hammer_cli/completer.rb', line 21

def quoted?
  quote != ""
end