Class: CommandLine::OptionData

Inherits:
Object
  • Object
show all
Defined in:
lib/commandline/optionparser/optiondata.rb

Overview

Data resulting from parsing a command line (Array) using a particular OptionParser object

Defined Under Namespace

Classes: OptionDataError, UnknownOptionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, opts, unknown_options, args, not_parsed, cmd) ⇒ OptionData

Returns a new instance of OptionData.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/commandline/optionparser/optiondata.rb', line 27

def initialize(argv, opts, unknown_options, args, not_parsed, cmd)
  @opts = {}
  opts.each { |k,v| 
    @opts[k] = 
      begin
        Marshal.load(Marshal.dump(v))
      rescue
        v
      end
  }
  @unknown_options = Marshal.load(Marshal.dump(unknown_options))
  @not_parsed = Marshal.load(Marshal.dump(not_parsed))
  @argv = Marshal.load(Marshal.dump(argv))
  @args = Marshal.load(Marshal.dump(args))
  @cmd  = Marshal.load(Marshal.dump(cmd))
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



22
23
24
# File 'lib/commandline/optionparser/optiondata.rb', line 22

def args
  @args
end

#argvObject (readonly)

Returns the value of attribute argv.



22
23
24
# File 'lib/commandline/optionparser/optiondata.rb', line 22

def argv
  @argv
end

#cmdObject (readonly)

Returns the value of attribute cmd.



22
23
24
# File 'lib/commandline/optionparser/optiondata.rb', line 22

def cmd
  @cmd
end

#not_parsedObject (readonly)

Returns the value of attribute not_parsed.



22
23
24
# File 'lib/commandline/optionparser/optiondata.rb', line 22

def not_parsed
  @not_parsed
end

#unknown_optionsObject (readonly)

Returns the value of attribute unknown_options.



22
23
24
# File 'lib/commandline/optionparser/optiondata.rb', line 22

def unknown_options
  @unknown_options
end

Instance Method Details

#[](key) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/commandline/optionparser/optiondata.rb', line 44

def [](key)
  if @opts.has_key?(key)
    @opts[key]
  else
    raise(UnknownOptionError, "Unknown option '#{key}'.")
  end
end