Module: Ruport::Data::Table::Pivot::Operations
Instance Method Summary collapse
- #count(rows, _summary_column) ⇒ Object
- #first(rows, summary_column) ⇒ Object
- #max(rows, summary_column) ⇒ Object
- #mean(rows, summary_column) ⇒ Object
- #min(rows, summary_column) ⇒ Object
- #sum(rows, summary_column) ⇒ Object
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 |