Module: Lazier::String

Extended by:
ActiveSupport::Concern
Defined in:
lib/lazier/string.rb

Overview

Extensions for the String class.

Instance Method Summary (collapse)

Instance Method Details

- (Object) remove_accents

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

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

Returns:

  • The string with all accents removed.



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 &.

Returns:

  • (String)

    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"

Returns:

  • (String)

    The untitleized version of the string.



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.

Returns:

  • (String)

    The string itself.



50
51
52
# File 'lib/lazier/string.rb', line 50

def value
  self
end