Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string-utils.rb

Overview

Silvio Relli’s string_utils gem - released under the MIT License

Instance Method Summary collapse

Instance Method Details

#hsObject

Just a shortcut to force a string to be html safe. Use with caution.



19
20
21
# File 'lib/string-utils.rb', line 19

def hs
  self.html_safe
end

#sanObject

Ensures the string is sanitized and html safe, so it won’t be escaped by xss protection and erubis in rails >=2.3.6 and >=3.0.



13
14
15
# File 'lib/string-utils.rb', line 13

def san
  self.sanitize
end

#sanitizeObject

Workaround for sanitize method not availabe in controllers, models and libs. Now you can call “mystryng”.sanitize everywere.



7
8
9
# File 'lib/string-utils.rb', line 7

def sanitize
  ActionController::Base.helpers.sanitize(self)
end

#urlifyObject

Makes strings be url-friendly



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/string-utils.rb', line 24

def urlify
  str = self.downcase.gsub(/ /,'-')
  str.gsub!(/À|à|á|Â|â|Ã|ã|Ä|ä/i,'a') 
  str.gsub!(/È|è|É|é|Ê|ê|Ë|ë|&/i,'e')
  str.gsub!(/Ì|ì|í|Î|î/i,'i')
  str.gsub!(/Ò|ò|ó|Ô|ô|Õ|õ|Ö|ö/i,'o')
  str.gsub!(/Ù|ù|ú|Û|û|Ü|ü/i,'u')
  str.gsub!(/ç/i,'c')
  str.gsub!(/œ/i,'oe')
  str.gsub!(/ß/i,'ss')
  str.gsub!(/[^a-z0-9\-]+/i, '')
  str
end