class TuringMachine::CommandLineParser

Public Class Methods

new(args) click to toggle source
# 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

Public Instance Methods

help() click to toggle source
# File lib/turing_machine/command_line_parser.rb, line 37
def help
  @opt_parser.help
end
parse() click to toggle source
# File lib/turing_machine/command_line_parser.rb, line 32
def parse
  @opt_parser.parse!(@args)
  @options
end