Permalink
Browse files

De-duplicate transactions and apply updated values

  • Loading branch information...
1 parent fb27bdf commit d9a029ded3c8a83ff7e9e295138c9b3c2b01a7e7 @aredridel aredridel committed Nov 28, 2010
Showing with 58 additions and 5 deletions.
  1. +10 −2 bin/dump-paypal-csv
  2. +48 −3 lib/paypal/csv.rb
View
@@ -2,5 +2,13 @@
require 'paypal/csv'
-f = Paypal::CSV.new(ARGV[0])
-p f
+Paypal::CSV.new(ARGV[0]).each do |r|
+ p r
+end
+
+def transaction_for(row)
+
+end
+
+def print_transaction(t)
+end
View
@@ -5,11 +5,56 @@
require 'csv'
end
+require 'enumerator'
+
module Paypal
- class CSV
+end
+
+class Paypal::CSV
+
+ include Enumerable
+
+ def initialize(filename)
+ rows = {}
+ data = ::CSV.read(filename, {:headers => true})
+ (data.length - 1).downto(0) do |n|
+ row = data[n]
+ next if row[" Status"] != "Completed" and row[" Status"] != "Reversed"
+ p row
+ case row[" Type"]
+ when /Update to (.*)/
+ puts "Updating Txn " << row[" Reference Txn ID"]
+ old = rows[row[" Reference Txn ID"]]
+ if !old
+ puts "Unknown row to update"
+ end
+ row.each do |k, v|
+ if k != " Type" and k != " Name"
+ old[k] = row[k]
+ end
+ end
+ when "Cash Back Bonus"
+ rows[row[" Transaction ID"]] = row
+ when "Debit Card Purchase"
+ rows[row[" Transaction ID"]] = row
+ when "Payment Received"
+ rows[row[" Transaction ID"]] = row
+ else
+ rows[row[" Transaction ID"]] = row
+ puts "Unknown type: " << row[" Type"]
+ end
+ end
+
+ @data = rows
+ end
+
+ attr_reader :data
- def initialize(filename)
- @data = ::CSV.read(filename, {:headers => true})
+ def each
+ if block_given?
+ @data.each do |e| yield e end
+ else
+ return Enumerable::Enumerator.new(self, :each)
end
end
end

0 comments on commit d9a029d

Please sign in to comment.