Class: Ro::Slug
- Inherits:
-
String
- Object
- String
- Ro::Slug
- Defined in:
- lib/ro/slug.rb
Constant Summary collapse
- Join =
'-'
Class Method Summary collapse
Class Method Details
.for(*args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ro/slug.rb', line 5 def Slug.for(*args) = args.last.is_a?(Hash) ? args.pop : {} join = ([:join]||['join']||Join).to_s string = args.flatten.compact.join(join) string = unidecode(string) words = string.to_s.scan(%r|[/\w]+|) words.map!{|word| word.gsub %r|[_-]|, join} words.map!{|word| word.gsub %r|[^/0-9a-zA-Z_-]|, ''} words.delete_if{|word| word.nil? or word.strip.empty?} new(words.join(join).downcase.gsub('/', (join * 2))) end |
.unidecode(string) ⇒ Object
18 19 20 |
# File 'lib/ro/slug.rb', line 18 def Slug.unidecode(string) string end |