Module: Lazier::String
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/lazier/string.rb
Overview
Extensions for the String class.
Instance Method Summary (collapse)
-
- (Object) remove_accents
Removes accents from the string, normalizing to the normal letter.
-
- (String) replace_ampersands
Returns the string with all
&
replaced with&
. -
- (String) untitleize
Returns the tagged version of a string.
-
- (String) value
Returns the string itself for use in form helpers.
Instance Method Details
- (Object) remove_accents
Removes accents from the string, normalizing to the normal letter.
"èòàù".remove_accents
# => "eoau"
20 21 22 23 24 |
# File 'lib/lazier/string.rb', line 20 def remove_accents silence_warnings { self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, "").to_s } end |
- (String) replace_ampersands
Returns the string with all &
replaced with &
.
43 44 45 |
# File 'lib/lazier/string.rb', line 43 def replace_ampersands self.gsub(/&(\S+);/, "&\\1;") end |
- (String) untitleize
Returns the tagged version of a string.
The string is downcased and spaces are substituted with -
.
"ABC cde".untitleize
# => "abc-cde"
36 37 38 |
# File 'lib/lazier/string.rb', line 36 def untitleize self.downcase.gsub(" ", "-") end |
- (String) value
Returns the string itself for use in form helpers.
50 51 52 |
# File 'lib/lazier/string.rb', line 50 def value self end |