テキスト ファイルをスキャンして CSV ファイルに変換するスクリプトがあります。情報debtor
を取得し、その後にcreditor
情報を配置します。
問題は、それぞれを取得しますdebtor
が、同じcreditor
情報をそれぞれdebtor
に配置し、以下の新しい情報を取得していないことdebtor
です:
FasterCSV.open('data.csv', 'a') do |csv|
debtor_info = results.scan(/^(\d{2}\-\d{5})(\s+)(.*)(\s+)(Total:)(\s+)(\$(\d+\,? \.?)+)/)
debtor_info.each do |line|
case_number = line.at(0)
debtor = line.at(2).strip
total_amount = line.at(6)
csv << [case_number, debtor, total_amount]
creditor_info = results.scan(/((\d{1,2})\/(\d{1,2})\/(\d{1,4}))\s+(\$(\d+\,?\.?)+)\s+(\d{1,5}BK)\s+(.*)/)
creditor_info.each do |info|
date = info.at(0)
amount = info.at(4)
fund_number = info.at(6)
creditor = info.at(7)
empty = " "
csv << [empty, date, amount, fund_number, creditor]
end
end
end
これはいくつかのサンプル入力です:
00-000## Company Inc Total: $3,134.55
2/25/2003 $416.02 0000BK A Comp Inc
2/25/2003 $105.60 0000BK California Imprinted Apparel
2/25/2003 $58.41 0000BK John Doe
2/25/2003 $33.41 0000BK E Doe & Assoc
2/25/2003 $78.28 0000BK Candle Candles
2/25/2003 $44.74 0000BK Personnel Svcs
2/25/2003 $28.34 0000BK Jane Doe
2/25/2003 $32.77 0000BK Water Co
2/25/2003 $141.21 0000BK XYX
2/25/2003 $250.96 0000BK PDQ INC
2/25/2003 $146.17 0000BK RS FM
2/25/2003 $722.91 0000BK A Corp
2/25/2003 $841.14 0000BK BAC Corp
2/25/2003 $202.57 0000BK ABC Communications
2/25/2003 $32.02 0000BK YXY SA Corp
00-00128 May June Total: $29.60
6/26/2002 $29.60 0000BK May June
00-00653 Joe Doey Total: $347.10
7/10/2002 $59.62 0000BK Financial Corp
7/10/2002 $287.48 0000BK ABC Corp
00-00657 Thomas P Public Total: $1,096.75
7/2/2003 $1,096.75 0000BK Contract Svc
00-00735 Jean Jane Total: $29.89
6/18/2003 $29.89 0000BK Jean Jane