Class: Bosh::Cli::LineWrap

Inherits:
Object show all
Defined in:
lib/cli/line_wrap.rb

Instance Method Summary collapse

Constructor Details

#initialize(width, left_margin = 0) ⇒ LineWrap

Returns a new instance of LineWrap.



3
4
5
6
# File 'lib/cli/line_wrap.rb', line 3

def initialize(width, left_margin = 0)
  @width = width
  @left_margin = left_margin
end

Instance Method Details

#wrap(string) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cli/line_wrap.rb', line 8

def wrap(string)
  paragraphs = string.split("\n")

  wrapped_paragraphs = paragraphs.map do |paragraph|
    lines = wrapped_lines(paragraph)
    lines = indent_lines(lines)

    paragraph_indentation(paragraph) + lines.join("\n")
  end

  wrapped_paragraphs.join("\n")
end