Skip to content

Commit

Permalink
fixes city of phoenix water firstname, lastname & bill_date
Browse files Browse the repository at this point in the history
  • Loading branch information
andobolocco committed Jun 26, 2020
1 parent 80a0c22 commit f84d862
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/documentTypes/cityOfPhoenixWaterBill.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ module.exports = {

extractor: (keyValues, rawText) => {
const keys = Object.keys(keyValues);
const [, fullNameLine] = rawText;
const first5Lines = rawText.slice(0, 5);
let fullName;
let first_name;
let last_name;
if (fullNameLine) {

fullName = first5Lines.find((line) => (
!line.match(/City of Phoenix/gi)
&& !line.match(/City Services Bill?/gi)
&& !line.match(/\d+/g)
&& line.toUpperCase() === line
));

if (fullName) {
// first name & last name (dropping anything between first and last words)
first_name = fullNameLine.split(' ').slice(0, 1).join(' ');
last_name = fullNameLine.split(' ').slice(-1).join(' ');
first_name = fullName.split(' ').slice(0, 1).join(' ');
last_name = fullName.split(' ').slice(-1).join(' ');
}

// street address line 1 & 2
Expand Down Expand Up @@ -75,11 +84,16 @@ module.exports = {
}

// bill date
let bill_date = keyValues[keys[stringSimilarity.findBestMatch(
const billDateIndex = stringSimilarity.findBestMatch(
'Due Date',
keys,
).bestMatchIndex]];
if (!bill_date || !bill_date.length || !bill_date.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/g)) {
).bestMatchIndex;
let bill_date = keyValues[keys[billDateIndex]];

if (!bill_date
|| !bill_date.length
|| keys[billDateIndex].match(/Bill Date/gi)
|| !bill_date.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/g)) {
const lineWithDueDate = rawText.findIndex((line) => line.match(/^Due Date$/g));
bill_date = rawText.slice(lineWithDueDate - 5, lineWithDueDate + 5).filter((line) => (
line.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/g)
Expand Down

0 comments on commit f84d862

Please sign in to comment.