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



165
166
167
168
169
170
171
# File 'lib/xoptparse.rb', line 165

def initialize(*)
  super
  @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.



163
164
165
# File 'lib/xoptparse.rb', line 163

def arg_parameters
  @arg_parameters
end

Instance Method Details

#match_nonswitch?Boolean



186
187
188
# File 'lib/xoptparse.rb', line 186

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

#summarizeObject



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

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



190
191
192
# File 'lib/xoptparse.rb', line 190

def switch_name
  arg_parameters.first.first
end