-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathchartOneSix.js
More file actions
55 lines (47 loc) · 2.26 KB
/
Copy pathchartOneSix.js
File metadata and controls
55 lines (47 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { chartToArrayBuilder } = require('./chartToArrayBuilder');
const { getFromArr } = require('./parsersUtils');
const log = require('../../../log');
// this function look for the correct columns for the given headers, and returns a factory embedded with these findings
const rowAbstractFactoryChart1_6 = (firstPageOfTable, headersStartIndex) => {
// clean the headers
firstPageOfTable = firstPageOfTable.map(row => row.map(cell => cell.replace(/\n/g, ' ')
.replace(/ {2}/g, ' ')
.trim()));
if (headersStartIndex === -1) {
// it's an error
log.error('didn\'t find headers for some char 1.6');
return () => {};
}
const header = firstPageOfTable[headersStartIndex];
const planNumberIdx = header.findIndex(title => title.includes('מספר תכנית מאושרת'));
const kindIdx = header.findIndex(title => title.includes('סוג יחס'));
const commentIdx = header.findIndex(title => title.includes('הערה ליחס'));
const yalkootNumberIdx = header.findIndex(title => title.includes('מספר ילקוט פרסומים'));
const yalkootPageNumberIdx = header.findIndex(title => title.includes('עמוד בילקוט פרסומים'));
const dateIdx = header.findIndex(title => title.includes('תאריך'));
return (row) => {
return {
prev_plan_number: getFromArr(row, planNumberIdx),
kind: getFromArr(row, kindIdx),
comment: getFromArr(row, commentIdx),
yalkoot_number: getFromArr(row, yalkootNumberIdx),
yalkoot_page_number: getFromArr(row, yalkootPageNumberIdx),
date: getFromArr(row, dateIdx),
};
};
};
const extractChartOneSix = (pageTables) => {
return chartToArrayBuilder({
pageTables,
rowAbstractFactory: rowAbstractFactoryChart1_6,
startOfChartPred: (cell) => cell.includes('יחס בין התכנית לבין תכניות מאושרות קודמות') && cell.includes('1.6'),
offsetOfRowWithDataInChart: 1,
chartDonePredicate: (row) => row.some(cell => cell.includes('מסמכי התכנית') && cell.includes('1.7')),
getHeaderRowIndex: (page, searchFrom) => page.slice(searchFrom).findIndex(row => row.some(cell => cell.includes('סוג יחס'))) + searchFrom,
rowTrimmer: (row) => row.map((cell) => cell.replace(/\n/g, ' ').replace(/ {2}/g, ' ').trim()),
identifier: '1.6'
});
};
module.exports = {
extractChartOneSix
};