Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Last active December 16, 2015 22:39
Show Gist options
  • Save jbrechtel/5508848 to your computer and use it in GitHub Desktop.
Save jbrechtel/5508848 to your computer and use it in GitHub Desktop.
T&E
require 'rubygems'
require 'csv'
require 'json'
require 'pp'
data = CSV.parse(File.read(ARGV[0]))
cols = data.shift
hashes = data.map { |v| cols.zip(v) }.map { |a| Hash[*a.flatten] }
puts 'var e = '+hashes.to_json
e.each(function(item, index) {
var amountInput = $$('#activities_0_items_'+index+'_amount')[0];
var dateInput = $$('#activities_0_items_'+index+'_item_date_string')[0];
var descInput = $$('#activities_0_items_'+index+'_description')[0];
var vendorInput = $$('#activities_0_items_'+index+'_vendor')[0];
var categoryInput = $$('#activities_0_items_'+index+'_category')[0];
var paymentInput = $$('#activities_0_items_'+index+'_payment')[0];
var attendeeInput = $$('#activities_0_items_'+index+'_attendees')[0];
dateInput.value = item['Timestamp'];
amountInput.value = item['Amount'];
descInput.value = item['Comment'];
vendorInput.value = item['Merchant'];
categoryInput.value = 'EXPBMEAL';
paymentInput.value = 'PMTPERS';
attendeeInput.value = 'me';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment