Class: Charming::UI::TextWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/ui/text_wrapper.rb

Overview

TextWrapper greedily word-wraps text blocks to a display width.

Instance Method Summary collapse

Constructor Details

#initialize(width:) ⇒ TextWrapper

Returns a new instance of TextWrapper.



7
8
9
# File 'lib/charming/presentation/ui/text_wrapper.rb', line 7

def initialize(width:)
  @width = width
end

Instance Method Details

#wrap(value) ⇒ Object



11
12
13
14
15
# File 'lib/charming/presentation/ui/text_wrapper.rb', line 11

def wrap(value)
  return value unless width

  value.to_s.lines(chomp: true).map { |line| wrap_line(line) }.join("\n")
end