Module: Extensions::String

Defined in:
lib/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#linkifyObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/extensions/string.rb', line 2

def linkify
  result = self.downcase
  result.gsub!(/&(\d)+;/, '')  # Ditch Entities
  result.gsub!('&', 'and')     # Replace & with 'and'
  result.gsub!(/['"]/, '')    # replace quotes by nothing
  result.gsub!(/\W/, ' ')     # strip all non word chars
  result.gsub!(/\ +/, '-')    # replace all white space sections with a dash
  result.gsub!(/(-)$/, '')    # trim dashes
  result.gsub!(/^(-)/, '')    # trim dashes
  result.gsub!(/[^a-zA-Z0-9\-]/, '-') # Get rid of anything we don't like
  result
end

#linkify!Object



15
16
17
# File 'lib/extensions/string.rb', line 15

def linkify!
  self.replace(self.linkify)
end