Sha256: 8629b742dc072a2dbe02a1ce3491ee5ec114aa2aa22532d592be64ad8941811a

Contents?: true

Size: 390 Bytes

Versions: 4

Compression:

Stored size: 390 Bytes

Contents

require 'rainbow'

class String
  def truncate(width)
    self[0, width]
  end

  def pluralize(n, suffix = 's', singular_suffix = '')
    if n == 1
      self + singular_suffix
    else
      self + suffix
    end
  end

  def highlight(pattern)
    gsub(/#{pattern}/i) { |m| Rainbow(m).red }
  end

  def unescape_html
    gsub(/&gt;/, '>').gsub(/&lt;/, '<').gsub(/&amp;/, '&')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
usaidwat-1.5.0 lib/usaidwat/ext/string.rb
usaidwat-1.4.5 lib/usaidwat/ext/string.rb
usaidwat-1.4.4 lib/usaidwat/ext/string.rb
usaidwat-1.4.3 lib/usaidwat/ext/string.rb