Class: DumpCleaner::Cleanup::DataSourceSteps::RemoveAccents

Inherits:
Base
  • Object
show all
Defined in:
lib/dump_cleaner/cleanup/data_source_steps/remove_accents.rb

Instance Attribute Summary

Attributes inherited from Base

#step_context

Instance Method Summary collapse

Methods inherited from Base

#initialize, #raise_params_error

Constructor Details

This class inherits a constructor from DumpCleaner::Cleanup::DataSourceSteps::Base

Instance Method Details

#run(under_keys: []) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dump_cleaner/cleanup/data_source_steps/remove_accents.rb', line 7

def run(under_keys: [])
  block = lambda do |word|
    word.match?(/^\p{ASCII}+$/) ? word : word.unicode_normalize(:nfd).gsub(/\p{M}/, "")
  end

  step_context.cleanup_data = begin
    if under_keys.any?
      new_data = cleanup_data.dup
      under_keys.each do |key|
        new_data[key] = new_data[key].map(&block)
      end
      new_data
    else
      cleanup_data.map(&block)
    end
  end

  step_context
end