Module: OptParse2::Positional

Defined in:
lib/optparse2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



184
185
186
# File 'lib/optparse2.rb', line 184

def name
  @name
end

Instance Method Details

#summarize(sdone = {}, ldone = {}, width = 1, max = width - 1, indent = "") ⇒ Object

Essentially directly copied from ‘OptParse::Switch`.summarize, except with custom `left`



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/optparse2.rb', line 187

def summarize(sdone = {}, ldone = {}, width = 1, max = width - 1, indent = "")
  left = ["#{name}"]
  sdone[name] = true
  ldone[name] = true
  right = desc.dup

  mlen = left.collect {|ss| ss.length}.max.to_i
  while mlen > width and l = left.shift
    mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen
    if l.length < width and (r = right[0]) and !r.empty?
      l = l.to_s.ljust(width) + ' ' + r
      right.shift
    end
    yield(indent + l)
  end

  while begin l = left.shift; r = right.shift; l or r end
    l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
    yield(indent + l)
  end

  self
end