csv_parser v0.0.4 CsvParser
Link to this section Summary
Functions
Creates a new object to be passed into reduce!/3. new and reduce exist separately so that errors in your files can be handled explicitly.
Raises if path represents an invalid file
Reads the file returning a list of list. See new/2 for valid opts
Reads the file returning a list of list or raises on error
Reduces over the parsed file, calling fun/2 for each row.
Like calling new!/2 then reduce!/3
Link to this section Functions
new(path, opts \\ [])
Creates a new object to be passed into reduce!/3. new and reduce exist separately so that errors in your files can be handled explicitly.
opts:
type: :csv | :xlsx
Defaults to nil, which will auto-detect
map: true | false | :lower | :upper | fun/1
Whether you want rows as a list or map. Defaults to false, which keeps rows
as lists. When :lower, keys will be lowercased. When :upper, keys will be
uppercased. When true, keys will be kept as-is. When fun/1 is passed, the
row, as a list, will be given to the function a a list must be returned (the
function maps the input keys to output key).
sheet_index: int
Index of the sheet to parse. Default to 1 (only applicable to xlsx)
new!(path, opts \\ [])
Raises if path represents an invalid file
read(path, opts \\ [])
Reads the file returning a list of list. See new/2 for valid opts
read!(path, opts \\ [])
Reads the file returning a list of list or raises on error
reduce!(csv, acc, fun)
Reduces over the parsed file, calling fun/2 for each row.
Example: csv = CsvParser.new!("sample.xlsx") rows = Enum.reduce(csv, [], fn {row, rows} -> [row | rows] end)
reduce!(file, acc, fun, opts \\ [])
Like calling new!/2 then reduce!/3