Class: TuringMachine::CommandLineParser

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CommandLineParser

Returns a new instance of CommandLineParser.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/turing_machine/command_line_parser.rb', line 8

def initialize(args)
  @args = args
  @options = OpenStruct.new
  @options.tape = '0'

  @opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: turing_machine instruction_set [options]"

    opts.on("-t", "--tape DATA", "Initialize the tape with DATA") do |data|
      @options.tape = data
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("--version", "Show version") do
      puts VERSION
      exit
    end
  end
end

Instance Method Details

#helpObject



37
38
39
# File 'lib/turing_machine/command_line_parser.rb', line 37

def help
  @opt_parser.help
end

#parseObject



32
33
34
35
# File 'lib/turing_machine/command_line_parser.rb', line 32

def parse
  @opt_parser.parse!(@args)
  @options
end