Sha256: 40da380e14ca103c4928a3114ddd20222dd109e33f776997003aab8d1be0ba96

Contents?: true

Size: 803 Bytes

Versions: 3

Compression:

Stored size: 803 Bytes

Contents

module LovelyRufus class HangoutWrapper < Layer
  def call wrap
    @wrap  = wrap
    final  = hangout_line ? rewrapped : wrap.text
    next_layer.call Wrap[final, width: wrap.width]
  end

  attr_reader :wrap
  private     :wrap

  private

  def hangout_line
    lines.each_cons 2 do |a, b|
      return a if a[/\p{space}/] and a.rindex(/\p{space}/) >= b.size
      unless b == lines.last
        return b if b[/\p{space}/] and b.rindex(/\p{space}/) >= a.size
      end
    end
  end

  def lines
    @lines ||= wrap.text.lines.map(&:chomp)
  end

  def rewrapped
    hangout_line << NBSP
    unfolded = lines.join(' ').gsub("#{NBSP} ", NBSP)
    wrapped  = BasicWrapper.new.call(Wrap[unfolded, width: wrap.width]).text
    HangoutWrapper.new.call(Wrap[wrapped, width: wrap.width]).text
  end
end end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lovely_rufus-0.1.2 lib/lovely_rufus/hangout_wrapper.rb
lovely_rufus-0.1.1 lib/lovely_rufus/hangout_wrapper.rb
lovely_rufus-0.1.0 lib/lovely_rufus/hangout_wrapper.rb