Sha256: 00ff7c5e9d28a9d8ed9fcdb3efae45004080be9ca0abd3fb1376fb9f8638fbd7

Contents?: true

Size: 615 Bytes

Versions: 2

Compression:

Stored size: 615 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

2 entries across 2 versions & 1 rubygems

Version Path
lovely_rufus-0.1.1 lib/lovely_rufus/text_wrapper.rb
lovely_rufus-0.1.0 lib/lovely_rufus/text_wrapper.rb