module ARMerge::ClassMethods

Public Instance Methods

merge_duplicates!(records,options) click to toggle source
# 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