Module: Ark::Text

Defined in:
lib/ark/utility.rb

Overview

Methods for manipulating text

Class Method Summary collapse

Class Method Details

.wrap(text, width: 78, indent: 0) ⇒ Object

Wrap a string to a given width, with an optional indent. Indented text will fall within the specified width.

text

The text to be wrapped

width

The number of columns to wrap within

indent

Indent each wrapped line of text by this number of columns



98
99
100
101
102
# File 'lib/ark/utility.rb', line 98

def self.wrap(text, width: 78, indent: 0)
  width -= indent
  text = text.gsub(/\s+/, " ").gsub(/(.{1,#{width}})( |\Z)/, "\\1\n")
  text.gsub(/^/, ' ' * indent)
end