Sha256: a00d3552238808b326f172a6d8f540c6c1e4c76099b02717805bde3d1edf3376

Contents?: true

Size: 787 Bytes

Versions: 1

Compression:

Stored size: 787 Bytes

Contents

require_relative 'layer'
require_relative 'wrap'

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

1 entries across 1 versions & 1 rubygems

Version Path
lovely_rufus-0.2.0 lib/lovely_rufus/quote_stripper.rb