Sha256: befd77458dd90c0f977ff5dbb3ca7052bff4bb3e691b710d095343a649bdcc2d

Contents?: true

Size: 618 Bytes

Versions: 1

Compression:

Stored size: 618 Bytes

Contents

module LovelyRufus class TextWrapper
  def self.wrap text, width: 72
    new(Wrap[text, width: width]).call
  end

  def initialize wrap
    @wrap = wrap
  end

  def call
    paras.map do |para|
      chain.call(Wrap[para, width: wrap.width]).text.tr NBSP, ' '
    end.join "\n"
  end

  attr_reader :wrap
  private     :wrap

  private

  def chain
    layers = [QuoteStripper, OneLetterGluer, BasicWrapper, HangoutWrapper]
    layers.reverse.reduce(-> wrap { wrap }) { |inner, outer| outer.new inner }
  end

  def paras
    wrap.text.split(/\n#{QUOTES}?\n/).reject { |para| para[/^(#{QUOTES}| )$/] }
  end
end end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lovely_rufus-0.1.2 lib/lovely_rufus/text_wrapper.rb