Skip to content

Instantly share code, notes, and snippets.

@straightjacket
Created October 1, 2013 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save straightjacket/6786935 to your computer and use it in GitHub Desktop.
Save straightjacket/6786935 to your computer and use it in GitHub Desktop.
A quick script to crunch bank numbers.
require 'pp'
require 'yaml'
require 'date'
require 'rspec'
PRINT_ALL = true
class Financials
@@financials = YAML.load_file('funds.yml')
def show
@@financials
end
def accounts
@@financials.each { |b| b['Accounts'] }
end
end
def add_up(bank)
printf "\t%s\n", bank
sum = 0;
bank.each { |k,v|
#pp k;
v.each { |i,j|
sum += j;
}
}
sum
end
f = Financials.new
financials = f.show
financials.each do |entry|
tot = 0
entry['Accounts'].each do |a|
stot = add_up a;
tot += stot;
if PRINT_ALL then printf "\tSubtotal: %.2f\n", stot end
end
printf "%s - Total: %.2f\n", DateTime.parse(entry['Date'].to_s).strftime("%D"), tot
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment