Class: Dictation::Commander

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

Class Method Summary collapse

Class Method Details

.order(args) ⇒ Object



6
7
8
9
10
11
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/dictation/commander.rb', line 6

def order(args)
  options = {}
  commands = {
      'new' => OptionParser.new do |opts|
        opts.banner = set_banner('new')

        opts.on('-d', '--dictate TTS', 'Specify two-letters language code for dictation') do |tts|
          options[:dictate] = tts.downcase
        end

        opts.on('-v', '--verify TTS', 'Specify two-letters language code for verification') do |tts|
          options[:verify] = tts.downcase
        end
      end,

      'add' => OptionParser.new do |opts|
        opts.banner = set_banner('add')

        opts.on('-l', '--language LANGUAGE', 'Specify the target language file for adding more words') do |language|
          options[:language] = language
        end
      end,

      'dictate' => OptionParser.new do |opts|
        opts.banner = set_banner('dictate')

        opts.on('-l', '--language LANGUAGE', 'Specify the language for dictation') do |language|
          options[:language] = language
        end

        opts.on('-b', '--begin WORD', 'Begin with given word') do |word|
          options[:word_begin] = word
        end

        opts.on('-e', '--end WORD', 'End with given word') do |word|
          options[:word_end] = word
        end

        opts.on('-s', '--start LINE', Integer, 'Start with given line') do |line|
          options[:line_start] = line
        end

        opts.on('-f', '--finish LINE', Integer, 'Finish with given line') do |line|
          options[:line_finish] = line
        end
      end,

      'verify' => OptionParser.new do |opts|
        opts.banner = set_banner('verify')

        opts.on('-l', '--language LANGUAGE', 'Specify the language for dictation') do |language|
          options[:language] = language
        end

        opts.on('-b', '--begin WORD', 'Begin with given word') do |word|
          options[:word_begin] = word
        end

        opts.on('-e', '--end WORD', 'End with given word') do |word|
          options[:word_end] = word
        end

        opts.on('-s', '--start LINE', Integer, 'Start with given line') do |line|
          options[:line_start] = line
        end

        opts.on('-f', '--finish LINE', Integer, 'Finish with given line') do |line|
          options[:line_finish] = line
        end
      end
  }
  valid_cmds = ['new', 'add', 'dictate', 'verify']
  if valid_cmds.include?(args[0])
    commands[args.shift].order!
    options
  else
    puts "Unknown commands [#{args[0]}], only support #{valid_cmds.inspect}."
  end
end