Class: Kerplutz::Flag

Inherits:
Option
  • Object
show all
Defined in:
lib/kerplutz/options.rb

Instance Attribute Summary collapse

Attributes inherited from Option

#abbrev, #desc, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Option

#abbrev_sig, #display_name, #parser_args

Constructor Details

#initialize(name, desc, arg_name = nil) ⇒ Flag

Returns a new instance of Flag.



48
49
50
51
# File 'lib/kerplutz/options.rb', line 48

def initialize(name, desc, arg_name=nil)
  super(name, desc)
  @arg_name = arg_name
end

Instance Attribute Details

#arg_nameObject

Returns the value of attribute arg_name.



39
40
41
# File 'lib/kerplutz/options.rb', line 39

def arg_name
  @arg_name
end

#arg_requiredObject

Returns the value of attribute arg_required.



39
40
41
# File 'lib/kerplutz/options.rb', line 39

def arg_required
  @arg_required
end

Class Method Details

.build(name, desc, opts) ⇒ Object



41
42
43
44
45
46
# File 'lib/kerplutz/options.rb', line 41

def self.build(name, desc, opts)
  flag = super(name, desc, opts)
  flag.arg_name = opts[:required] || opts[:optional]
  flag.arg_required = opts.has_key?(:required)
  flag
end

Instance Method Details

#configure(parser, &blk) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/kerplutz/options.rb', line 53

def configure(parser, &blk)
  parser.on(*parser_args) do |arg|
    if NilClass === arg
      blk.call(true)
    else
      blk.call(arg)
    end
  end
end

#option_sigObject



63
64
65
# File 'lib/kerplutz/options.rb', line 63

def option_sig
  "#{super}#{formatted_arg_name}"
end