Class: AccentBuster::Buster

Inherits:
Object
  • Object
show all
Defined in:
lib/accent-buster/buster.rb

Constant Summary collapse

ACCENT_DOWNCASE =
"áéíóúâêîôûäëïöüãõñç"
NO_ACCENT_DOWNCASE =
"aeiouaeiouaeiouaonc"
ACCENT_UPCASE =
"ÁÉÍÓÚÂÊÎÔÛÄËÏÖÜÃÕÑÇ"
NO_ACCENT_UPCASE =
"AEIOUAEIOUAEIOUAONC"

Instance Method Summary collapse

Constructor Details

#initialize(a_string) ⇒ Buster

Wrap an object to add accent wise (diacritic wise) methods.

It works for latin languages only.

Parameters:

  • a_string (#to_s)


13
14
15
# File 'lib/accent-buster/buster.rb', line 13

def initialize(a_string)
  @a_string = a_string.to_s
end

Instance Method Details

#bustObject

Convert diacritics chars to their non-diacritic equivalents.

“áéíóú âêîôû äëïöü ãõ ñç” => “aeiou aeiou aeiou ao nc”

Returns:

  • the string with diacritics removed.



22
23
24
# File 'lib/accent-buster/buster.rb', line 22

def bust
  @a_string.tr(ACCENT_DOWNCASE + ACCENT_UPCASE, NO_ACCENT_DOWNCASE + NO_ACCENT_UPCASE)
end

#downObject

Downcase the string, correctly converting diacritcs.

Example: “ÓTIMO” => “ótimo”

Returns:

  • the string lower case



40
41
42
# File 'lib/accent-buster/buster.rb', line 40

def down
  @a_string.tr(ACCENT_UPCASE, ACCENT_DOWNCASE).downcase
end

#upObject

Upcase the string, correctly converting diacritcs.

Example: “ótimo” => “ÓTIMO”

Returns:

  • the string upper case



31
32
33
# File 'lib/accent-buster/buster.rb', line 31

def up
  @a_string.tr(ACCENT_DOWNCASE, ACCENT_UPCASE).upcase
end