Module: Cowtech::Extensions::String
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cowtech-extensions/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"
21 22 23 24 25 |
# File 'lib/cowtech-extensions/string.rb', line 21 def remove_accents silence_warnings { self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, "").to_s } end |
#replace_ampersands ⇒ String
Returns the string with all &
replaced with &
.
44 45 46 |
# File 'lib/cowtech-extensions/string.rb', line 44 def replace_ampersands self.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"
37 38 39 |
# File 'lib/cowtech-extensions/string.rb', line 37 def untitleize self.downcase.gsub(" ", "-") end |
#value ⇒ String
Returns the string itself for use in form helpers.
51 52 53 |
# File 'lib/cowtech-extensions/string.rb', line 51 def value self end |