Class: Options

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, options = {}) ⇒ Options

Returns a new instance of Options.



22
23
24
25
# File 'lib/freshmind.rb', line 22

def initialize( argv, options={})
  @argv = argv
  @options = options
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



21
22
23
# File 'lib/freshmind.rb', line 21

def argv
  @argv
end

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/freshmind.rb', line 21

def options
  @options
end

Instance Method Details

#argsObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/freshmind.rb', line 27

def args
  res = {}
  options.each do |opt_key, opt_value| 
    opt_value[:variants].each do |variant|
      arg_index = argv.index(variant.to_s)
      res[opt_key] = arg_index.nil? ? opt_value[:default] : argv[arg_index].to_sym
    end
  end
  res
end