Class: Organo::StringUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/organo/tools/string_utils.rb

Class Method Summary collapse

Class Method Details

.create_slug(title) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/organo/tools/string_utils.rb', line 5

def self.create_slug(title)
  # strip the string
  ret = title.strip

  # blow away apostrophes
  ret.gsub!(/['`]/, '')

  # @ --> at, and & --> and
  ret.gsub!(/\s*@\s*/, ' at ')
  ret.gsub!(/\s*&\s*/, ' and ')

  # replace all non alphanumeric with dash
  ret.gsub!(/\s*[^A-Za-z0-9]\s*/, '-')

  # convert double underscores to single
  ret.gsub!(/-+/, '-')

  # strip off leading/trailing dash
  ret.gsub!(/\A-+|-+\z/, '')

  ret.downcase
end