Class: Archivededup::FilePicker

Inherits:
Object
  • Object
show all
Defined in:
lib/archivededup/filepicker.rb

Overview

From a list of file names, pick the file that provides the most information and so should be kept.

Instance Method Summary collapse

Constructor Details

#initializeFilePicker

Returns a new instance of FilePicker.



63
64
65
66
67
68
69
# File 'lib/archivededup/filepicker.rb', line 63

def initialize()
  # A list of ways to compare file names.
  # These are applied in-order until one returns non-zero.
  @comparators = []
  @comparators << FileNamePickerByDate
  @comparators << proc { |a, b| b.length <=> a.length }
end

Instance Method Details

#pick(filelist) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/archivededup/filepicker.rb', line 71

def pick(filelist)

  filelist.sort do |a,b|

    # Default the sort to be equal, no sort.
    last_compare = 0

    # Run comparators until one selcts a better file name.
    @comparators.find do |c|
      last_compare = c.call(a, b)
      last_compare != 0
    end

    # Return the result of the last comparison.
    last_compare
  end.
  first
end