defp init_parser(opts) do
state = if Keyword.get(opts, :skip_headers, true), do: :header, else: :line
separator = :binary.compile_pattern(Keyword.get(opts, :separator, @separator))
{state, separator, :binary.compile_pattern(@escape)}
end
That way the user is allowed to override the parser separator (and maybe also escape).
I understand that this contradicts with the idea that each Parser has a specified functionality,
but when you have to deal with different kind of separated files (commas, semicolons, tabs, spaces, pipes, etc),
it would really help to avoid creating multiple modules for just in case or having to rewrite-recompile-redeploy
if/when a new format arrives.
It unfortunately won’t work. The whole deal about NimbleCSV is to generate parsers at compile time for performance, so we can’t guarantee you can override options at runtime.
Hello, and apologies if this already discussed.
We could update the
init_parser/1
like this:That way the user is allowed to override the parser separator (and maybe also escape).
I understand that this contradicts with the idea that each Parser has a specified functionality, but when you have to deal with different kind of separated files (commas, semicolons, tabs, spaces, pipes, etc), it would really help to avoid creating multiple modules for just in case or having to rewrite-recompile-redeploy if/when a new format arrives.