Initial commit
This commit is contained in:
20
lib/helpers/csv.ex
Normal file
20
lib/helpers/csv.ex
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
Reference in New Issue
Block a user