Class: Fingerprint::Command::Duplicates
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Fingerprint::Command::Duplicates
- Defined in:
- lib/fingerprint/command/duplicates.rb
Instance Attribute Summary collapse
-
#duplicates_recordset ⇒ Object
readonly
Returns the value of attribute duplicates_recordset.
Instance Method Summary collapse
Instance Attribute Details
#duplicates_recordset ⇒ Object (readonly)
Returns the value of attribute duplicates_recordset.
42 43 44 |
# File 'lib/fingerprint/command/duplicates.rb', line 42 def duplicates_recordset @duplicates_recordset end |
Instance Method Details
#call ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fingerprint/command/duplicates.rb', line 44 def call @options[:output] = @parent.output @duplicates_recordset = RecordSet.new results = RecordSetPrinter.new(duplicates_recordset, @options[:output]) master_file_path = @master File.open(master_file_path) do |master_file| master_recordset = RecordSet.new master_recordset.parse(master_file) ignore_similar = false copy_file_paths = @copies || [] if copy_file_paths.size == 0 copy_file_paths = [master_file_path] ignore_similar = true end copy_file_paths.each do |copy_file_path| File.open(copy_file_path) do |copy_file| copy_recordset = RecordSet.new copy_recordset.parse(copy_file) copy_recordset.records.each do |record| record.['fingerprint'] = copy_file_path # We need to see if the record exists in the master if @options[:verbose] $stderr.puts "Checking #{record.inspect}" end main_record = master_recordset.find_by_key(record) # If we are scanning the same index, don't print out every file, just those that are duplicates within the single file. if ignore_similar && main_record && (main_record.path == record.path) main_record = nil end if main_record record.['original.path'] = main_record.path record.['original.fingerprint'] = master_file_path results << record if !@options[:inverse] else results << record if @options[:inverse] end end end end end end |