Module: LucaSalary::Accumulator::ClassMethods

Defined in:
lib/luca_salary/accumulator.rb

Instance Method Summary collapse

Instance Method Details

#accumulate(records) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/luca_salary/accumulator.rb', line 10

def accumulate(records)
  count = 0
  result = records.each_with_object({}) do |record, result|
    count += 1
    record
      .select { |k, _v| /^[1-4][0-9A-Fa-f]{,3}$/.match(k) }
      .each do |k, v|
      next if v.nil?

      result[k] = result[k] ? result[k] + v : v
    end
  end
  [result, count]
end