Module: UnicodeTools::StringExtension::Squish
- Included in:
- String
- Defined in:
- lib/unicode-tools/string_extension/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\u2003\u2004\u2005\u2006
\u2007\u2008\u2009\u200a\u2028\u2029
\u2028\u2029\u202f\u205f\u3000 World! "
string.squish => “Hello World!”
16 17 18 |
# File 'lib/unicode-tools/string_extension/squish.rb', line 16 def squish dup.squish! end |
#squish! ⇒ Object
20 21 22 23 24 25 |
# File 'lib/unicode-tools/string_extension/squish.rb', line 20 def squish! return self if empty? gsub!(SURROUNDING_WHITESPACE_REGEXP, '') gsub!(WHITESPACE_REGEXP, ' ') self end |