Add migrations, helpers, dev config, models

This commit is contained in:
Ryan Pandya
2022-10-21 13:01:58 -07:00
parent c22df96bd2
commit 7b2a5f2baa
20 changed files with 578 additions and 5 deletions
+34
View File
@@ -0,0 +1,34 @@
defmodule Helpers.Names do
def full_name(friend) do
friend.name
|> String.reverse()
|> String.split(" ", parts: 2)
|> Enum.map(&String.reverse/1)
|> Enum.reverse()
# This is all so that "First Middle Last" becomes ["First Middle", "Last"]
# Is there a more elegant solution? DEFINITELY.
end
def first_name(friend) do
friend
|> first_and_middle_name()
|> String.split()
|> List.first()
end
def first_and_middle_name(friend) do
friend
|> full_name
|> List.first()
end
def middle_name(friend) do
[first | middles] = friend |> first_and_middle_name() |> String.split()
middles |> Enum.join(" ")
end
def last_name(friend) do
friend |> full_name |> List.last()
end
end