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