Module: Unaccent
- Defined in:
- lib/unaccent.rb,
lib/unaccent/string.rb,
lib/unaccent/version.rb
Defined Under Namespace
Modules: String
Constant Summary collapse
- VERSION =
'0.2.0'.freeze
Class Method Summary collapse
-
.unaccent(str) ⇒ String
Replace a string’s accented characters with unaccented characters.
-
.via_each_char(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#each_char` to iterate on characters.
-
.via_gsub(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#gsub` to replace non-ascii characters.
-
.via_scan(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#scan` to iterate on characters.
-
.via_split_map(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#split` and `#map` to iterate on characters.
Class Method Details
.unaccent(str) ⇒ String
Replace a string’s accented characters with unaccented characters.
14 15 16 |
# File 'lib/unaccent.rb', line 14 def unaccent(str) via_gsub(str) end |
.via_each_char(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#each_char` to iterate on characters.
57 58 59 60 61 |
# File 'lib/unaccent.rb', line 57 def via_each_char(str) return str if str.ascii_only? res = ''; str.each_char { |c| res << ACCENTMAP.fetch(c, c) }; res end |
.via_gsub(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#gsub` to replace non-ascii characters.
27 28 29 30 31 |
# File 'lib/unaccent.rb', line 27 def via_gsub(str) return str if str.ascii_only? str.gsub(/[^[:ascii:]]/) { |c| ACCENTMAP.fetch(c, c) } end |
.via_scan(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#scan` to iterate on characters.
42 43 44 45 46 |
# File 'lib/unaccent.rb', line 42 def via_scan(str) return str if str.ascii_only? res = ''; str.scan(/./) { |c| res << ACCENTMAP.fetch(c, c) }; res end |
.via_split_map(str) ⇒ String
Replace a string’s accented characters with unaccented characters, by using string ‘#split` and `#map` to iterate on characters.
72 73 74 75 76 |
# File 'lib/unaccent.rb', line 72 def via_split_map(str) return str if str.ascii_only? str.split(//u).map { |c| ACCENTMAP.fetch(c, c) }.join end |