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

Returns a new instance of SummarizeArgument.



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

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.



177
178
179
# File 'lib/xoptparse.rb', line 177

def arg_parameters
  @arg_parameters
end

#rangesObject (readonly)

Returns the value of attribute ranges.



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

def ranges
  @ranges
end

Instance Method Details

#match_nonswitch?Boolean

Returns:

  • (Boolean)


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

def match_nonswitch?(*)
  nil
end

#parse(_arg, _argv) ⇒ Object

Raises:

  • (XOptionParser::InvalidOption)


209
210
211
# File 'lib/xoptparse.rb', line 209

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

#summarizeObject



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

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



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

def switch_name
  arg_parameters.first.first
end