Class: Cartos::Spreadsheet::Month

Inherits:
Object
  • Object
show all
Defined in:
lib/cartos/spreadsheet/sheets/month.rb

Constant Summary collapse

DATE =
"A"
AMOUNT =
"B"
DESCRIPTION =
"C"
CATEGORY =
"D"
CATEGORIES =
"F"
EXPENDINGS_BY_CATEGORY =
"G"
EARNINGS_TOTAL =
"F"
EXPENDINGS_TOTAL =
"G"

Instance Method Summary collapse

Constructor Details

#initialize(sheet) ⇒ Month

Returns a new instance of Month.



15
16
17
# File 'lib/cartos/spreadsheet/sheets/month.rb', line 15

def initialize(sheet)
  @sheet = sheet
end

Instance Method Details

#push_category(category) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/cartos/spreadsheet/sheets/month.rb', line 26

def push_category(category)
  push_row CATEGORIES, category
  formula        = Cartos::Google::Sheet::Formulas.new
  entry_range    = @sheet.row_range(AMOUNT, 1, @sheet.last_row(AMOUNT))
  category_range = @sheet.row_range(CATEGORY, 1, @sheet.last_row(CATEGORY))
  push_row EXPENDINGS_BY_CATEGORY, formula.sum.filter(entry_range, "#{category_range} = \"#{category}\"")
end

#push_entry(date, amount, description, category) ⇒ Object



19
20
21
22
23
24
# File 'lib/cartos/spreadsheet/sheets/month.rb', line 19

def push_entry(date, amount, description, category)
  push_row DATE, date
  push_row AMOUNT, amount
  push_row DESCRIPTION, description
  push_row CATEGORY, category
end

#push_row(column, value) ⇒ Object



41
42
43
# File 'lib/cartos/spreadsheet/sheets/month.rb', line 41

def push_row(column, value)
  @sheet.push_row column, value
end

#push_summary(expendings_total, earnings_total) ⇒ Object



34
35
36
37
38
39
# File 'lib/cartos/spreadsheet/sheets/month.rb', line 34

def push_summary(expendings_total, earnings_total)
  push_row EARNINGS_TOTAL, "Earnings"
  push_row EARNINGS_TOTAL, earnings_total
  push_row EXPENDINGS_TOTAL, "Expendings"
  push_row EXPENDINGS_TOTAL, expendings_total
end

#saveObject



45
46
47
# File 'lib/cartos/spreadsheet/sheets/month.rb', line 45

def save
  @sheet.save
end