Class: XOptionParser::Switch::SimpleArgument

Inherits:
SummarizeArgument show all
Defined in:
lib/xoptparse.rb

Instance Attribute Summary collapse

Attributes inherited from SummarizeArgument

#arg_parameters

Instance Method Summary collapse

Methods inherited from SummarizeArgument

#match_nonswitch?, #summarize, #switch_name

Constructor Details

#initializeSimpleArgument



198
199
200
201
202
203
# File 'lib/xoptparse.rb', line 198

def initialize(*)
  super
  @ranges = arg_parameters.map do |_name, type, rest|
    (type == :req ? 1 : 0)..(rest == :rest ? nil : 1)
  end
end

Instance Attribute Details

#rangesObject (readonly)

Returns the value of attribute ranges.



196
197
198
# File 'lib/xoptparse.rb', line 196

def ranges
  @ranges
end

Instance Method Details

#add_banner(to) ⇒ Object



205
206
207
# File 'lib/xoptparse.rb', line 205

def add_banner(to)
  to << " #{arg}"
end

#parse(arg, argv) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/xoptparse.rb', line 209

def parse(arg, argv)
  case ranges.size
  when 0
    super(arg, argv)
  when 1
    unless arg
      raise XOptionParser::MissingArgument if argv.empty?

      arg = argv.shift
    end
    arg = [arg] if ranges.first.end.nil?
    conv_arg(*parse_arg(arg, &method(:raise)))
  else
    raise XOptionParser::InvalidOption
  end
end