Module: Ruport::Data::Table::Pivot::Operations

Extended by:
Operations
Included in:
Operations
Defined in:
lib/ruport/data/table.rb

Instance Method Summary collapse

Instance Method Details

#count(rows, _summary_column) ⇒ Object



135
136
137
# File 'lib/ruport/data/table.rb', line 135

def count(rows, _summary_column)
  rows && rows.length
end

#first(rows, summary_column) ⇒ Object



127
128
129
# File 'lib/ruport/data/table.rb', line 127

def first(rows, summary_column)
  rows.first && rows.first[summary_column]
end

#max(rows, summary_column) ⇒ Object



149
150
151
# File 'lib/ruport/data/table.rb', line 149

def max(rows, summary_column)
  rows && (rows.collect { |r| r[summary_column] }).max
end

#mean(rows, summary_column) ⇒ Object



139
140
141
142
143
# File 'lib/ruport/data/table.rb', line 139

def mean(rows, summary_column)
  return if rows.length == 0
  sum = rows && rows.inject(0) { |sum,row| sum+row[summary_column] }
  sum / rows.length
end

#min(rows, summary_column) ⇒ Object



145
146
147
# File 'lib/ruport/data/table.rb', line 145

def min(rows, summary_column)
  rows && (rows.collect { |r| r[summary_column] }).min
end

#sum(rows, summary_column) ⇒ Object



131
132
133
# File 'lib/ruport/data/table.rb', line 131

def sum(rows, summary_column)
  rows && rows.inject(0) { |sum,row| sum+row[summary_column] }
end