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.



166
167
168
# File 'lib/optparse2.rb', line 166

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



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/optparse2.rb', line 169

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