class Rubypivot::PivotRow
Attributes
title[R]
Public Class Methods
new(title, data_type = nil)
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 35 def initialize(title, data_type = nil) @title = title # Title of the row : String @data_type = data_type @data = {} end
Public Instance Methods
add(column_title, value)
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 41 def add(column_title, value) return unless value case @data_type when :integer @data[column_title] = 0 unless @data[column_title] @data[column_title] += value.to_i when :float @data[column_title] = 0.0 unless @data[column_title] @data[column_title] += value.to_f when :string @data[column_title] = value.to_s else # raw data @data[column_title] = value end end
get(column_title)
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 57 def get(column_title) return nil if column_title.nil? @data[column_title] end
to_a(column_titles)
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 62 def to_a(column_titles) column_titles.map{|column_title| @data[column_title] } end
total(column_titles)
click to toggle source
# File lib/rubypivot/pivot_row.rb, line 66 def total(column_titles) return unless [:integer, :float].include?(@data_type) total = @data_type == :float ? 0.0 : 0 column_titles.each do |column_title| total += @data[column_title] if @data[column_title] end total end