Class: DumpCleaner::Cleanup::CleaningSteps::TakeSample

Inherits:
Base
  • Object
show all
Defined in:
lib/dump_cleaner/cleanup/cleaning_steps/take_sample.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(uniqueness_strategy: :resample) ⇒ 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/take_sample.rb', line 7

def run(uniqueness_strategy: :resample)
  if !cleanup_data || cleanup_data.empty?
    step_context.current_value = nil
    return step_context
  end

  uniqueness_strategy = uniqueness_strategy.to_sym
  step_context.current_value =
    if uniqueness_strategy == :resample
      cleanup_data[crc32 % cleanup_data.size]
    elsif uniqueness_strategy == :suffix
      sample = cleanup_data[crc32(use_repetition: false) % cleanup_data.size]
      AddRepetitionSuffix.new(StepContext.new_from(step_context, current_value: sample)).run.current_value
    else
      raise_params_error("Unknown uniqueness strategy: #{uniqueness_strategy}")
    end
  step_context
end