Class: NauktisUtils::Duplicate::HandlingStrategy::OriginalFrom

Inherits:
KeepOne show all
Defined in:
lib/nauktis_utils/duplicate.rb

Instance Attribute Summary

Attributes inherited from BaseHandlingStrategy

#deleting_strategy

Instance Method Summary collapse

Constructor Details

#initialize(deleting_strategy, directory) ⇒ OriginalFrom

Returns a new instance of OriginalFrom.



41
42
43
44
# File 'lib/nauktis_utils/duplicate.rb', line 41

def initialize(deleting_strategy, directory)
  super(deleting_strategy)
  @directory = File.expand_path(directory)
end

Instance Method Details

#handle(files) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nauktis_utils/duplicate.rb', line 46

def handle(files)
  files = files.sort
  i = files.find_index do |f|
    f.start_with?(@directory)
  end
  unless i.nil?
    file_kept = files.delete_at(i)
    files.each do |duplicate|
      @deleting_strategy.delete_duplicate(duplicate, file_kept)
    end
  end
end