Module: Shhh::App::NLP::Usage

Included in:
Base
Defined in:
lib/shhh/app/nlp/usage.rb

Instance Method Summary collapse

Instance Method Details

#convert_dictionary(left = '', right = '') ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/shhh/app/nlp/usage.rb', line 54

def convert_dictionary(left = '', right = '')
  [
    sprintf('%35.35s', left.gsub(/ /, ' ')).italic.yellow,
    '   ───────➤   '.dark,
    sprintf('--%-20.20s', right).blue,

    "\n"
  ].join
end

#usageObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/shhh/app/nlp/usage.rb', line 12

def usage
  out = ''
  out << %Q`
#{header('Natural Language Processing')}

#{'When '.dark.normal}#{'shhh'.bold.blue} #{'is invoked, and the first argument does not begin with a dash,
then the the NLP (natural language processing) Translator is invoked.
The Translator is based on a very simple algorithm:

 * ignore any of the words tagged STRIPPED. These are the ambiguous words,
   or words with duplicate meaning.

 * map the remaining arguments to regular double-dashed options using the DICTIONARY

 * words that are a direct match for a --option are automatically double-dashed

 * remaining words are left as is (these would be file names, key names, etc).

 * finally, the resulting "new" command line is parsed with regular options.

 * When arguments include "verbose", NLP system will print "before" and "after"
   of the arguments, so that any issues can be debugged and corrected.

'.dark.normal}

#{header('Currently ignored words:')}
    #{Constants::STRIPPED.join(', ').red.italic}

#{header('Regular Word Mapping')}
#{Constants::DICTIONARY.pretty_inspect.split(/\n/).map do |line|
    line.gsub(
      /[\:\}\,\[\]]/, ''
    ).gsub(
      /[ {](\w+)=>([^\n]*)/, '\2|\1'
    )
  end.map { |line| convert_dictionary(*line.split('|')) }.join}

#{header('Examples')}
`
  out
end