Skip to content

Instantly share code, notes, and snippets.

@tsycho
Created September 26, 2011 19:54
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 tsycho/1243226 to your computer and use it in GitHub Desktop.
Save tsycho/1243226 to your computer and use it in GitHub Desktop.
Read ABX/Primex RCD files and extract factors
require "crack"
require "json"
files = File.read("files.txt").split("\n")
files.each { |filename|
filename = filename.strip
next if filename.empty?
myXML = Crack::XML.parse( File.read(filename) )
json = JSON.parse(myXML.to_json)
data = json["data"]["abcds"] # Array of <abcds/> nodes
data.map { |index|
name = index['indexname']
cur = index['currentsettlement']
nxt = index['nextsettlement']
starting_factor = cur['factor']
new_factor = nxt['factor']
isf = cur['interestshortfallpmtamt']
isfr = cur['interestshortfallreimbursementpmtamt']
psf = cur['principalshortfallamt']
psfr = cur['principalshortfallreimbursementamt']
wd = cur['writedownamt']
wdr = cur['writedownreimbursementamt']
iwd = cur['impliedwritedownamt']
iwdr = cur['impliedwritedownreimbursementamt']
#[name, starting_factor, new_factor, isf, isfr, psf, psfr, wd, wdr, iwd, iwdr].join(", ")
[filename[-12...-4], name, new_factor].join("\t")
}.each { |row| puts row }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment