Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/usaidwat/ext/string.rb
Instance Method Summary collapse
- #highlight(pattern) ⇒ Object
- #pluralize(n, suffix = 's', singular_suffix = '') ⇒ Object
- #prefix_subreddit ⇒ Object
- #unescape_html ⇒ Object
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_subreddit ⇒ Object
20 21 22 23 |
# File 'lib/usaidwat/ext/string.rb', line 20 def prefix_subreddit return self if length == 0 '/r/' + self end |
#unescape_html ⇒ Object
16 17 18 |
# File 'lib/usaidwat/ext/string.rb', line 16 def unescape_html gsub(/>/, '>').gsub(/</, '<').gsub(/&/, '&') end |