Module: Dry::CLI::WordWrap

Included in:
Banner, Usage
Defined in:
lib/dry/cli/banner.rb

Overview

Utility module for wrapping text to a given width

Instance Method Summary collapse

Instance Method Details

#wrap_description(text, width: 55, prefix: " ") ⇒ Object Also known as: wrap



10
11
12
13
14
# File 'lib/dry/cli/banner.rb', line 10

def wrap_description(text, width: 55, prefix: "  ")
  text.split("\n", -1).map { |para|
    para.scan(/\S.{0,#{width - 1}}(?=\s|\z)|\S{#{width},}/).join("\n#{prefix}")
  }.join("\n")
end