Created
September 26, 2011 19:54
-
-
Save tsycho/1243226 to your computer and use it in GitHub Desktop.
Read ABX/Primex RCD files and extract factors
This file contains hidden or 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 "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