Files
confient/lib/helpers/csv.ex
2020-12-12 18:38:31 +01:00

21 lines
546 B
Elixir

defmodule CSV do
@moduledoc """
Helper to interact with CSV
"""
def parse(path) do
content = File.read!(path)
[_ | parts] = String.replace(content, "\r", "") |> String.split("\n") |> Enum.filter(fn v -> v != "" end)
names = Enum.map(parts, fn v ->
[name | _ ] = String.split(v, ";")
String.trim(name, "\"")
end)
students = Enum.map(names, fn v ->
IO.inspect(v)
[_, lastname, firstname] = Regex.run(~r/(^[A-Z -]{2,}) (.+)/, v)
{lastname, firstname}
end)
{:ok, students}
end
end