Skip to content

Instantly share code, notes, and snippets.

@gavinheavyside
Created September 25, 2013 17:43
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 gavinheavyside/6703255 to your computer and use it in GitHub Desktop.
Save gavinheavyside/6703255 to your computer and use it in GitHub Desktop.
Reverse signs of transactions in a qif file, and open it (OS X) in the associated program. My bank generates .qif files for my credit card with credit & debit reversed compared with how my finance program wants them.
#!/usr/bin/env ruby
require 'qif'
if ARGV.size != 1
$stderr.puts "usage: fix-credit-card-qif-and-load.rb <CC qif file>"
end
input_filename = ARGV[0]
output_filename = input_filename.sub(/\.qif/, "-fixed.qif")
input = Qif::Reader.new(File.open(input_filename))
Qif::Writer.open(output_filename) do |output|
input.each do |transaction|
transaction.amount = -transaction.amount
output << transaction
end
end
`open #{output_filename}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment