A quick script to crunch bank numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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