class Rubypivot::PivotRows
Attributes
data_type[R]
rows[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 4 def initialize(options = {}) @options = options @data_type = options[:data_type] @rows = {} end
Public Instance Methods
get_row(row_title)
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 10 def get_row(row_title) @rows[row_title] ||= PivotRow.new(row_title, @data_type) end
Also aliased as: add_row
total(column_titles = [], show_grand_total = false)
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 15 def total(column_titles = [], show_grand_total = false) return ['Total', 'row', 'can', 'not', 'create', "type :#{@data_type}"] unless [:integer, :float].include?(@data_type) grand_total = @data_type == :float ? 0.0 : 0 data_array = [] column_titles.each do |column_title| total = @data_type == :float ? 0.0 : 0 @rows.each do |row_title, row| v = row.get(column_title) total += v if v end grand_total += total if show_grand_total data_array << total end data_array << grand_total if show_grand_total data_array end