Module: UnicodeAlphanumeric

Defined in:
lib/unicode_alphanumeric.rb

Class Method Summary collapse

Class Method Details

.filter(str, options = {}) ⇒ Object



4
5
6
# File 'lib/unicode_alphanumeric.rb', line 4

def self.filter(str, options = {})
  replace(str, '', options)
end

.map(str, options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/unicode_alphanumeric.rb', line 22

def self.map(str, options = {})
  str.gsub(ascii_regex(options)) do |char|
    alphanumeric?(char, options) ? char : yield(char)
  end
end

.replace(str, replacement, options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/unicode_alphanumeric.rb', line 8

def self.replace(str, replacement, options = {})
  str.gsub(ascii_regex(options)) do |char|
    alphanumeric?(char, options) ? char : replacement
  end
end

.scan(str, options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/unicode_alphanumeric.rb', line 14

def self.scan(str, options = {})
  non_alphanumeric = []
  str.scan(ascii_regex(options)) do |char|
    non_alphanumeric << char if !alphanumeric?(char, options)
  end
  non_alphanumeric
end