Class: String

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

Instance Method Summary collapse

Instance Method Details

#highlight(pattern) ⇒ Object



12
13
14
# File 'lib/usaidwat/ext/string.rb', line 12

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

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



4
5
6
7
8
9
10
# File 'lib/usaidwat/ext/string.rb', line 4

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

#prefix_subredditObject



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

def prefix_subreddit
  return self if length == 0
  '/r/' + self
end

#unescape_htmlObject



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

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