Module: CleanThisDirtyString

Defined in:
lib/clean_this_dirty_string.rb

Class Method Summary collapse

Class Method Details

.clean!(string) ⇒ Object



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

.diff(string) ⇒ Object



35
36
37
# File 'lib/clean_this_dirty_string.rb', line 35

def diff(string)
  string.split('') - clean!(string).split('')
end