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

Instance Method Details

#remove_accentsObject

Removes accents from the string, normalizing to the normal letter.

"èòàù".remove_accents
# => "eoau"

Returns:

  • The string with all accents removed.



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_ampersandsString

Returns the string with all & replaced with &.

Returns:

  • (String)

    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

#untitleizeString

Returns the tagged version of a string.

The string is downcased and spaces are substituted with -.

"ABC cde".untitleize
# => "abc-cde"

Returns:

  • (String)

    The untitleized version of the string.



37
38
39
# File 'lib/cowtech-extensions/string.rb', line 37

def untitleize
	self.downcase.gsub(" ", "-")
end

#valueString

Returns the string itself for use in form helpers.

Returns:

  • (String)

    The string itself.



51
52
53
# File 'lib/cowtech-extensions/string.rb', line 51

def value
	self
end