Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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