Class: Nav::Slug

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

Constant Summary collapse

Join =
'-'

Class Method Summary collapse

Class Method Details

.for(*args) ⇒ Object



351
352
353
354
355
356
357
358
359
360
# File 'lib/rails_nav.rb', line 351

def Slug.for(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  join = (options[:join]||options['join']||Join).to_s
  string = args.flatten.compact.join(join)
  string = unidecode(string).titleize
  words = string.to_s.scan(%r/\w+/)
  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)
end

.unidecode(string) ⇒ Object



368
369
370
# File 'lib/rails_nav.rb', line 368

def Slug.unidecode(string)
  string
end