Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/googletastic.rb

Instance Method Summary collapse

Instance Method Details

#parameterize(sep = '-') ⇒ Object

active_support isn’t letting me do this!



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/googletastic.rb', line 43

def parameterize(sep = '-')
  # replace accented chars with ther ascii equivalents
  # parameterized_string = transliterate(string)
  parameterized_string = self.dup
  # Turn unwanted chars into the seperator
  parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
  unless sep.blank?
    re_sep = Regexp.escape(sep)
    # No more than one of the separator in a row.
    parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
    # Remove leading/trailing separator.
    parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
  end
  parameterized_string.downcase
end