Sha256: 5e2590f56b0d9d1aef08449e7c10d7856d650274052148866d24362c21f5d362

Contents?: true

Size: 750 Bytes

Versions: 4

Compression:

Stored size: 750 Bytes

Contents

require_relative '../wrap'
require_relative 'layer'

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

      private_attr_reader :wrap

      private

      def quote
        starts = wrap.lines.map { |line| line[self.class::QUOTES] }.uniq
        starts.size == 1 ? starts.first || '' : ''
      end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lovely_rufus-1.0.0 lib/lovely_rufus/layers/quote_stripper.rb
lovely_rufus-0.3.2 lib/lovely_rufus/layers/quote_stripper.rb
lovely_rufus-0.3.1 lib/lovely_rufus/layers/quote_stripper.rb
lovely_rufus-0.3.0 lib/lovely_rufus/layers/quote_stripper.rb