Sha256: 8a7a1378060c3d8cf484f2fd2c5a86b1b8d0cfe34744bf203489cb29c4fce5e3

Contents?: true

Size: 697 Bytes

Versions: 2

Compression:

Stored size: 697 Bytes

Contents

module LovelyRufus class QuoteStripper < Layer
  def call wrap
    @wrap   = wrap
    wrapped = next_layer.call stripped_wrap
    quoted  = wrapped.text.lines.map { |line| fixed_quote + line }.join
    Wrap[quoted, width: wrapped.width + fixed_quote.size]
  end

  attr_reader :wrap
  private     :wrap

  private

  def fixed_quote
    quote.size > 0 ? quote.delete(' ') + ' ' : ''
  end

  def quote
    starts = wrap.text.lines.map { |line| line[/^#{QUOTES}/] }.uniq
    starts.size == 1 ? starts.first || '' : ''
  end

  def stripped_wrap
    stripped_text = wrap.text.lines.map { |line| line[quote.size..-1] }.join
    Wrap[stripped_text, width: wrap.width - fixed_quote.size]
  end
end end

Version data entries

2 entries across 2 versions & 1 rubygems

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