Module: ARMerge::ClassMethods

Defined in:
lib/ar_merge.rb

Instance Method Summary collapse

Instance Method Details

#merge_duplicates!(records, options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ar_merge.rb', line 34

def merge_duplicates!(records,options)
  records.each do |record|
    next if record.nil?
    records.each do |other|
      next if other.nil?
      next if other == record
      is_comparable = other.send(options[:compare]) == record.send(options[:compare])
      next unless is_comparable

      #merge and remove the other
      records[records.index(other)]=nil
      record.merge!(other)
    end
  end.compact
end