lib/mongoid/report/collection.rb in mongoid-report-0.1.9 vs lib/mongoid/report/collection.rb in mongoid-report-0.2.0
- old
+ new
@@ -1,11 +1,11 @@
require 'delegate'
module Mongoid
module Report
- class Collection < SimpleDelegator
+ class Collection
def initialize(context, rows, fields, columns, mapping)
@context = context
@rows = rows
@fields = fields
@columns = columns
@@ -13,11 +13,11 @@
@rows = Rows.new(compile_rows)
end
class Rows < SimpleDelegator ; end
- attr_reader :rows
+ attr_reader :context, :rows
def headers
@fields
end
@@ -27,16 +27,17 @@
@fields.each do |field|
# Don't apply for dynamic calculated columns lets wait until we get
# all summaried mongo columns and then apply dynamic columns
# calculations.
next if @columns.has_key?(field)
+ next unless row[field].is_a?(Fixnum) || row[field].is_a?(Float)
summary[field] += row[field]
end
# Apply dynamic columns for summarized row
@columns.each do |name, function|
next unless @fields.include?(name)
- summary[name] = function.call(@context, row, { mapping: @mapping, summary: true })
+ summary[name] = function.call(@context, summary, { mapping: @mapping, summary: true })
end
summary
end
end