Method: String#fix_separators!

Defined in:
lib/name_tamer/string.rb

#fix_separators!(separator) ⇒ Object

Make sure separators are not where they shouldn’t be



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/name_tamer/string.rb', line 53

def fix_separators!(separator)
  return self if separator.nil? || separator.empty?

  r = Regexp.escape(separator)

  # No more than one of the separator in a row.
  substitute!(/#{r}{2,}/, separator)

  # Remove leading/trailing separator.
  substitute!(/^#{r}|#{r}$/i, '')
end