Class: WIP::Runner::Parser::OptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/wip/runner/parser/option_parser.rb

Instance Method Summary collapse

Instance Method Details

#list(items, mode = :rows, option = nil, pad = true) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/wip/runner/parser/option_parser.rb', line 7

def list(items, mode = :rows, option = nil, pad = true)
  if (mode == :rows)
    items   = items.map { |item| "#{option} #{item}" } if option
    items.join("\n#{pad ? padding : nil}")
  else
    HighLine.new.list(items, mode, option)
  end
end

#wrap(text, mode = :description, line_width = 80) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wip/runner/parser/option_parser.rb', line 16

def wrap(text, mode = :description, line_width = 80)
  indented = false

  if mode == :description
    line_width -= indentation
    indented = true
  end

  wrapped = text.split("\n").collect! do |line|
    line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
  end * "\n"

  indented ? wrapped.split("\n").join("\n#{padding}") : wrapped
end