Class: OptConfig::Option

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

Overview

オプション定義

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Option

初期化

args

オプション名(String) のリスト、オプションの属性(Hash)



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/optconfig.rb', line 483

def initialize(*args)
  name = args.dup
  if name.last.is_a? Hash
    attr = name.pop
  else
    attr = {}
  end
  raise "no option name: #{args.inspect}" if name.empty?
  argument = nil
  @usage_name = name
  @name = name.to_a.map do |n|
    unless n =~ /\A([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9_-]+)(\[?=.*)?\z/
      raise "invalid option name: #{n.inspect}"
    end
    n = $1
    argument = $2.nil? ? nil : $2 =~ /\A\[/ ? :optional : true
    n
  end
  @argument = attr.key?(:argument) ? attr[:argument] : argument
  @format = attr.key?(:format) ? attr[:format] : @argument ? true : nil
  @default = attr[:default]
  @description = attr[:description]
  @multiple = attr.key?(:multiple) ? attr[:multiple] : :last
  @completion = attr.key?(:completion) ? attr[:completion] : true
  @underscore_is_hyphen = attr[:underscore_is_hyphen]
  @in_config = attr.key?(:in_config) ? attr[:in_config] : true
  @proc = attr[:proc]
  @pre_proc = attr[:pre_proc]
  @value = @default
  @ovalue = @default
end

Instance Attribute Details

#argumentObject (readonly)

Returns the value of attribute argument.



514
515
516
# File 'lib/optconfig.rb', line 514

def argument
  @argument
end

#completionObject (readonly)

Returns the value of attribute completion.



515
516
517
# File 'lib/optconfig.rb', line 515

def completion
  @completion
end

#defaultObject (readonly)

Returns the value of attribute default.



514
515
516
# File 'lib/optconfig.rb', line 514

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



514
515
516
# File 'lib/optconfig.rb', line 514

def description
  @description
end

#formatObject (readonly)

Returns the value of attribute format.



514
515
516
# File 'lib/optconfig.rb', line 514

def format
  @format
end

#in_configObject (readonly)

Returns the value of attribute in_config.



515
516
517
# File 'lib/optconfig.rb', line 515

def in_config
  @in_config
end

#multipleObject (readonly)

Returns the value of attribute multiple.



514
515
516
# File 'lib/optconfig.rb', line 514

def multiple
  @multiple
end

#nameObject (readonly)

Returns the value of attribute name.



514
515
516
# File 'lib/optconfig.rb', line 514

def name
  @name
end

#ovalueObject

Returns the value of attribute ovalue.



517
518
519
# File 'lib/optconfig.rb', line 517

def ovalue
  @ovalue
end

#pre_procObject (readonly)

Returns the value of attribute pre_proc.



515
516
517
# File 'lib/optconfig.rb', line 515

def pre_proc
  @pre_proc
end

#procObject (readonly)

Returns the value of attribute proc.



515
516
517
# File 'lib/optconfig.rb', line 515

def proc
  @proc
end

#underscore_is_hyphenObject (readonly)

Returns the value of attribute underscore_is_hyphen.



515
516
517
# File 'lib/optconfig.rb', line 515

def underscore_is_hyphen
  @underscore_is_hyphen
end

#usage_nameObject (readonly)

Returns the value of attribute usage_name.



516
517
518
# File 'lib/optconfig.rb', line 516

def usage_name
  @usage_name
end

#valueObject

Returns the value of attribute value.



517
518
519
# File 'lib/optconfig.rb', line 517

def value
  @value
end

Instance Method Details

#may_not_take_argument?Boolean

Returns:

  • (Boolean)


519
520
521
# File 'lib/optconfig.rb', line 519

def may_not_take_argument?
  argument == false or argument == :optional or (argument.nil? and !format)
end