Skip to content

Commit d9e65ae

Browse files
committed
fix city of phoenix water bill_date
1 parent 731d097 commit d9e65ae

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/documentTypes/cityOfPhoenixWaterBill.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable camelcase */
22
const moment = require('moment');
3+
const stringSimilarity = require('string-similarity');
34

45
module.exports = {
56

@@ -30,6 +31,7 @@ module.exports = {
3031
},
3132

3233
extractor: (keyValues, rawText) => {
34+
const keys = Object.keys(keyValues);
3335
const [, fullNameLine] = rawText;
3436
let first_name;
3537
let last_name;
@@ -61,10 +63,29 @@ module.exports = {
6163
}
6264

6365
// bill amount
64-
const bill_amount = keyValues['Total Amount Due'];
66+
let bill_amount = keyValues[keys[stringSimilarity.findBestMatch(
67+
'Total Amount Due',
68+
keys,
69+
).bestMatchIndex]];
70+
if (!bill_amount || !bill_amount.length) {
71+
bill_amount = keyValues[keys[stringSimilarity.findBestMatch(
72+
'Total amount due:',
73+
keys,
74+
).bestMatchIndex]];
75+
}
6576

6677
// bill date
67-
const bill_date = keyValues['Bill Date:'];
78+
let bill_date = keyValues[keys[stringSimilarity.findBestMatch(
79+
'Due Date',
80+
keys,
81+
).bestMatchIndex]];
82+
if (!bill_date || !bill_date.length || !bill_date.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/g)) {
83+
const lineWithDueDate = rawText.findIndex((line) => line.match(/^Due Date$/g));
84+
bill_date = rawText.slice(lineWithDueDate - 5, lineWithDueDate + 5).filter((line) => (
85+
line.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/g)
86+
));
87+
bill_date = bill_date.length ? bill_date[0] : '';
88+
}
6889

6990
// account number
7091
const account_number = keyValues['Account Number:'];

0 commit comments

Comments
 (0)