Class: AccentBuster::Buster
- Inherits:
-
Object
- Object
- AccentBuster::Buster
- 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
-
#bust ⇒ Object
Convert diacritics chars to their non-diacritic equivalents.
-
#down ⇒ Object
Downcase the string, correctly converting diacritcs.
-
#initialize(a_string) ⇒ Buster
constructor
Wrap an object to add accent wise (diacritic wise) methods.
-
#up ⇒ Object
Upcase the string, correctly converting diacritcs.
Constructor Details
#initialize(a_string) ⇒ Buster
Wrap an object to add accent wise (diacritic wise) methods.
It works for latin languages only.
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
#bust ⇒ Object
Convert diacritics chars to their non-diacritic equivalents.
“áéíóú âêîôû äëïöü ãõ ñç” => “aeiou aeiou aeiou ao nc”
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 |
#down ⇒ Object
Downcase the string, correctly converting diacritcs.
Example: “ÓTIMO” => “ótimo”
40 41 42 |
# File 'lib/accent-buster/buster.rb', line 40 def down @a_string.tr(ACCENT_UPCASE, ACCENT_DOWNCASE).downcase end |
#up ⇒ Object
Upcase the string, correctly converting diacritcs.
Example: “ótimo” => “ÓTIMO”
31 32 33 |
# File 'lib/accent-buster/buster.rb', line 31 def up @a_string.tr(ACCENT_DOWNCASE, ACCENT_UPCASE).upcase end |