Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/sixarm_ruby_unaccent/string.rb

Overview

String extensions.

Instance Method Summary collapse

Instance Method Details

#unaccentString

Replace a string's accented characters with unaccented characters.

Examples:

s = "Å Ç ß"
s.unaccent = > "AA C ss"

Returns:

  • (String)

    a string that has no accents


16
17
18
# File 'lib/sixarm_ruby_unaccent/string.rb', line 16

def unaccent
  unaccent_via_scan
end

#unaccent_via_each_charString

Replace a string's accented characters with unaccented characters, by using string `#each_char` to iterate on characters.

Examples:

s = "Å Ç ß"
s.unaccent_via_each_char = > "AA C ss"

Returns:

  • (String)

    a string that has no accents


42
43
44
# File 'lib/sixarm_ruby_unaccent/string.rb', line 42

def unaccent_via_each_char
  result=""; each_char{|c| result += (ACCENTMAP[c] || c) }; result
end

#unaccent_via_scanString

Replace a string's accented characters with unaccented characters, by using string `#scan` to iterate on characters.

Examples:

s = "Å Ç ß"
s.unaccent_via_scan = > "AA C ss"

Returns:

  • (String)

    a string that has no accents


29
30
31
# File 'lib/sixarm_ruby_unaccent/string.rb', line 29

def unaccent_via_scan
  result=""; scan(/./){|c| result += (ACCENTMAP[c] || c) }; result
end

#unaccent_via_split_mapString

Replace a string's accented characters with unaccented characters, by using string `#split` and `#map` to iterate on characters.

Examples:

s = "Å Ç ß"
s.unaccent_via_split_map = > "AA C ss"

Returns:

  • (String)

    a string that has no accents


55
56
57
# File 'lib/sixarm_ruby_unaccent/string.rb', line 55

def unaccent_via_split_map
  split(//u).map{|c| ACCENTMAP[c] || c }.join("")
end