Module: UnicodeTools::StringExt::Squish
- Included in:
- String
- Defined in:
- lib/unicode-tools/string_ext/squish.rb
Instance Method Summary collapse
-
#squish ⇒ Object
Removes leading, trailing whitespace and collapses remaining whitespace into one group each.
- #squish! ⇒ Object
Instance Method Details
#squish ⇒ Object
Removes leading, trailing whitespace and collapses remaining whitespace into one group each.
string = “ Hellofnrtvu00A0u1680u180eu2000
\u2001\u2002
string.squish => “Hello World!”
16 17 18 |
# File 'lib/unicode-tools/string_ext/squish.rb', line 16 def squish dup.squish! end |
#squish! ⇒ Object
20 21 22 23 24 |
# File 'lib/unicode-tools/string_ext/squish.rb', line 20 def squish! gsub!(SURROUNDING_WHITESPACE_REGEX, '') gsub!(WHITESPACE_REGEX, ' ') self end |