Class: String

Inherits:
Object show all
Defined in:
lib/ext/ext.rb

Instance Method Summary collapse

Instance Method Details

#humanizeObject



25
26
27
# File 'lib/ext/ext.rb', line 25

def humanize
  self.capitalize.gsub(/[-_]+/, ' ')
end

#slugize(slug = '-') ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/ext/ext.rb', line 12

def slugize(slug = '-')
  slugged = Iconv.iconv('ascii//TRANSLIT//IGNORE', 'utf-8', self).to_s
  slugged.gsub!(/&/, 'and')
  slugged.gsub!(/[^\w_\-#{Regexp.escape(slug)}]+/i, slug)
  slugged.gsub!(/#{slug}{2,}/i, slug)
  slugged.gsub!(/^#{slug}|#{slug}$/i, '')
  url_encode(slugged.downcase)
end

#url_encode(word) ⇒ Object



21
22
23
# File 'lib/ext/ext.rb', line 21

def url_encode(word)
  URI.escape(word, /[^\w_+-]/i)
end