Class: DumpCleaner::Cleanup::CleaningSteps::RandomizeEmail

Inherits:
Base
  • Object
show all
Defined in:
lib/dump_cleaner/cleanup/cleaning_steps/randomize_email.rb

Instance Attribute Summary

Attributes inherited from Base

#step_context

Instance Method Summary collapse

Methods inherited from Base

#crc32, #initialize, #raise_params_error

Constructor Details

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

Instance Method Details

#run(domains_to_keep_data_key: "domains_to_keep", words_data_key: "words") ⇒ Object



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

def run(domains_to_keep_data_key: "domains_to_keep", words_data_key: "words")
  validate_params(domains_to_keep_data_key:, words_data_key:)

  mailbox, domain = current_value.split("@", 2)

  if !mailbox || !domain || mailbox.empty? || domain.empty? || !domain.include?(".")
    Log.warn { "Invalid email: type=#{type}, id=#{record['id']}, value=#{current_value}" } if repetition.zero?
    step_context.current_value = nil
    return step_context
  end

  new_mailbox = new_mailbox(mailbox, words: cleanup_data[words_data_key])
  new_domain = new_domain(domain, domains: cleanup_data[domains_to_keep_data_key],
                                  words: cleanup_data[words_data_key])

  step_context.current_value = "#{new_mailbox}@#{new_domain}"
  step_context
end