class Cartos::Spreadsheet::Summary

Constants

CATEGORIES
TOTALS

Public Class Methods

new(sheet) click to toggle source
Calls superclass method Cartos::Spreadsheet::Sheet::new
# File lib/cartos/spreadsheet/sheets/summary.rb, line 7
def initialize(sheet)
  super sheet
  @last_col_used = 1
  @month_cols = {}
  @category_row = {}
end

Public Instance Methods

push_categories(categories) click to toggle source
# File lib/cartos/spreadsheet/sheets/summary.rb, line 18
def push_categories(categories)
  row, _ = push_row CATEGORIES, "Categories"
  push_summnary row, CATEGORIES, categories
end
push_totals(totals) click to toggle source
# File lib/cartos/spreadsheet/sheets/summary.rb, line 14
def push_totals(totals)
  row, _ = push_row TOTALS, "Totals"
  push_summnary row, TOTALS, totals
end

Private Instance Methods

col_for_month(month) click to toggle source
# File lib/cartos/spreadsheet/sheets/summary.rb, line 47
def col_for_month(month)
  if @month_cols[month].nil?
    @month_cols[month] = @last_col_used + 1
    @last_col_used += 1
  end

  @month_cols[month]
end
push_month_amount(month, row, amount) click to toggle source
# File lib/cartos/spreadsheet/sheets/summary.rb, line 37
def push_month_amount(month, row, amount)
  set_row row, col_for_month(month), amount
end
push_months(row,months) click to toggle source
# File lib/cartos/spreadsheet/sheets/summary.rb, line 41
def push_months(row,months)
  months.each do |month|
    set_row row, col_for_month(month), month
  end
end
push_summnary(start_row, type_column, elements) click to toggle source
# File lib/cartos/spreadsheet/sheets/summary.rb, line 27
def push_summnary(start_row, type_column, elements)
  push_months start_row, elements.values.map {|v| v.keys}.flatten.uniq.sort.sort
  elements.each do |element, months|
    row, _ = push_row type_column, element
    months.each do |month, amount|
      push_month_amount  month, row, amount
    end
  end
end