4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/clean_this_dirty_string.rb', line 4
def clean!(string)
chars = string.split('')
result =
chars.map do |char|
case char
when /[\t\n\r]/ then ' '
when /[а-ё\d\w\s\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\; \< \= \> \? \@\[\\\]\^\_\`\{\|\}]/i then char
when /[\«\»\˝\“\”\„\《\》]/ then '"'
when /[\\–\—\-]/ then '-'
when /[\´]/ then '`'
when /[\‘\’]/ then "'"
when /[\℅]/ then '%'
when /[\№]/ then '№'
when /[\!]/ then '!'
when /[\#]/ then '#'
when /[\(]/ then '('
when /[\)]/ then ')'
when /[\,]/ then ','
when /[\;]/ then ';'
when /[\<]/ then '<'
when /[\>]/ then '>'
when /[\ ]/ then ' '
when /[\₽]/ then 'Р'
else ''
end
end
result.join('')
end
|