Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/transit/support/string.rb

Overview

Extends string to create url friendly formatted values. Original implemention by Ludo van den Boom

Direct Known Subclasses

HtmlContent

Instance Method Summary collapse

Instance Method Details

#to_slugObject

Removes all non url-friendly characters and replaces spaces and underscores with hyphens.



12
13
14
15
16
17
18
19
20
# File 'lib/transit/support/string.rb', line 12

def to_slug
  value = self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, '').to_s
  value.gsub!(/[']+/, '')
  value.gsub!(/\W+/, ' ')
  value.strip!
  value.downcase!
  value.gsub!(' ', '-')
  value
end