Sha256: 2a667fdcc67bbeb657dc1205b679a6ea18ae945f6da0a88a26bc3675d479ef45

Contents?: true

Size: 538 Bytes

Versions: 1

Compression:

Stored size: 538 Bytes

Contents

class String
  def noescape
    gsub(%r{\e[^m]*m}, '')
  end

  def ljust_noescape(width, delim=" ")
    self + delim*(width - noescape.length)
  end

  def rjust_noescape(width, delim=" ")
    delim*(width - noescape.length) + self
  end

  def format_substring(substring, formatter, downcase: false)
    index = downcase ? self.downcase.index(substring.downcase) : index(substring)

    if index.nil?
      self
    else
      substring = self[index, substring.length]
      gsub(substring, formatter.call(substring))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doublespeak-0.1.0 lib/doublespeak/string.rb