Class: Mongoid::Report::Merger

Inherits:
Struct
  • Object
show all
Defined in:
lib/mongoid/report/merger.rb

Overview

We are using this class to combine results by group by fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#groupsObject

Returns the value of attribute groups

Returns:

  • (Object)

    the current value of groups



5
6
7
# File 'lib/mongoid/report/merger.rb', line 5

def groups
  @groups
end

Instance Method Details

#do(rows) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/mongoid/report/merger.rb', line 6

def do(rows)
  # Merge by groups.
  rows
    .group_by { |row| groups.map { |group| row[group] }.join('-') }
    .values
    .map { |array_row| combine(array_row) }
end