new ColumnTool(opts)
Methods for sniffing column positions and for accessing column content by column nickname, while recognizing columns in arbitrary sequence within the spreadsheet.
Parameters:
Name | Type | Description |
---|---|---|
opts |
Object | command-line options set by the |
Members
colMapHints
A mapping of column nicknames to strings likely to be found in the header of each.
Methods
checkColMap()
Check that all expected columns are present in the spreadsheet, and throw an error if they are not.
Throws:
a helpful error on the first column identified as missing
checkCsvFilenameSanity()
Check that there is one and only one CSV file in the current directory with the form "data-<country name>.csv".
- If more than one such file exists, throw an appropriate error
- If no such file exists, throw a different appropriate error
getSpreadsheetArrays(csvFilePath)
Read the spreadsheet file, normalize its line endings, and parse the content to an array of arrays. Analyze the first line to match columns to nicknames, and discard the headline.
Parameters:
Name | Type | Description |
---|---|---|
csvFilePath |
str | path to CSV file to use as input |
- Source:
- See:
loadLine(record) → {Object}
Copy each labeled cell of a spreadsheet line to an object with the column nickname as its key, and return the object.
Parameters:
Name | Type | Description |
---|---|---|
record |
Array.<Object> | an array representing one spreadsheet line |
Returns:
- Type
- Object
setColMap(headline)
For each column label in the spreadsheet headline, check for its match string among those corresponding to column nicknames. If found, add its nickname to an array of column nicknames. Otherwise add null to the array to flag it as irrelevant.
Parameters:
Name | Type | Description |
---|---|---|
headline |
Array.<Object> | an array representing one spreadsheet line |
Properties:
Name | Type | Description |
---|---|---|
colMap |
Array.<Object> | an array of column nicknames, in the order of the corresponding columns in the spreadsheet |
headline |
Array.<Object> | the original headline values in array format, for use in dumping normalized content as CSV |