From 3f5f3b937fa58a9a86cac713ac6e4f2b93606e95 Mon Sep 17 00:00:00 2001 From: Andres Bolocco Date: Fri, 19 Jun 2020 17:17:10 -0300 Subject: [PATCH] fix aps street address --- lib/documentTypes/apsBill.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/documentTypes/apsBill.js b/lib/documentTypes/apsBill.js index dfb8aa3..9abe7a8 100644 --- a/lib/documentTypes/apsBill.js +++ b/lib/documentTypes/apsBill.js @@ -29,6 +29,7 @@ module.exports = { extractor: (keyValues, rawText) => { const keys = Object.keys(keyValues); + const lineWithCityStateZipCodeIndex = rawText.findIndex((line) => line.match(/^[A-Z\s]+ [A-Z]{2} \d+-\d+$/g)); let fullName; // first name & last name (WARNING splitting full name by space potential inconsistency) @@ -48,8 +49,7 @@ module.exports = { )); } if (!fullName) { - const index = rawText.findIndex((line) => line.match(/^[A-Z\s]+ [A-Z]{2} \d+-\d+$/g)) - 2; - fullName = rawText[index]; + fullName = rawText[lineWithCityStateZipCodeIndex - 2]; } let first_name; @@ -69,16 +69,18 @@ module.exports = { if (indexOfFullNameInCapsLine >= 0) { street_address_line_1 = rawText[indexOfFullNameInCapsLine + 1]; street_address_line_2 = rawText[indexOfFullNameInCapsLine + 2]; + } else { + street_address_line_1 = rawText[lineWithCityStateZipCodeIndex - 1]; + } - if (street_address_line_2.match(/Visit aps.com/g)) { - // case of no street_address_line_2 - street_address_line_2 = ''; - } + if (street_address_line_2.match(/Visit aps.com/g)) { + // case of no street_address_line_2 + street_address_line_2 = ''; } } // city, state, zip code - const lineWithCityStateZip = rawText.find((line) => line.match(/^[A-Z\s]+ [A-Z]{2} \d+-\d+$/g)); + const lineWithCityStateZip = rawText[lineWithCityStateZipCodeIndex]; if (lineWithCityStateZip === street_address_line_2) { // case of no street_address_line_2 street_address_line_2 = '';