Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/usaidwat/ext/string.rb

Instance Method Summary collapse

Instance Method Details

#highlight(pattern) ⇒ Object



16
17
18
# File 'lib/usaidwat/ext/string.rb', line 16

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

#pluralize(n, suffix = 's', singular_suffix = '') ⇒ Object



8
9
10
11
12
13
14
# File 'lib/usaidwat/ext/string.rb', line 8

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

#truncate(width) ⇒ Object



4
5
6
# File 'lib/usaidwat/ext/string.rb', line 4

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

#unescape_htmlObject



20
21
22
# File 'lib/usaidwat/ext/string.rb', line 20

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