Class: XOptionParser::Switch::SummarizeArgument

Inherits:
XOptionParser::Switch show all
Defined in:
lib/xoptparse.rb

Direct Known Subclasses

SimpleArgument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSummarizeArgument



177
178
179
180
181
182
183
184
# File 'lib/xoptparse.rb', line 177

def initialize(*)
  super
  @ranges = []
  @arg_parameters = arg.scan(/\[\s*(.*?)\s*\]|(\S+)/).map do |opt, req|
    name = opt || req
    [name.sub(/\s*\.\.\.$/, ''), opt ? :opt : :req, name.end_with?('...') ? :rest : nil]
  end
end

Instance Attribute Details

#arg_parametersObject (readonly)

Returns the value of attribute arg_parameters.



175
176
177
# File 'lib/xoptparse.rb', line 175

def arg_parameters
  @arg_parameters
end

#rangesObject (readonly)

Returns the value of attribute ranges.



174
175
176
# File 'lib/xoptparse.rb', line 174

def ranges
  @ranges
end

Instance Method Details

#match_nonswitch?Boolean



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

def match_nonswitch?(*)
  super if @pattern.is_a?(Regexp)
end

#parse(_arg, _argv) ⇒ Object

Raises:

  • (XOptionParser::InvalidOption)


207
208
209
# File 'lib/xoptparse.rb', line 207

def parse(_arg, _argv)
  raise XOptionParser::InvalidOption
end

#summarizeObject



186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/xoptparse.rb', line 186

def summarize(*)
  original_arg = arg
  @short = arg_parameters.map do |name, type, rest|
    var = "#{name}#{rest ? '...' : ''}"
    type == :req ? var : "[#{var}]"
  end
  @arg = nil
  res = super
  @arg = original_arg
  @short = nil
  res
end

#switch_nameObject



203
204
205
# File 'lib/xoptparse.rb', line 203

def switch_name
  arg_parameters.first.first
end