Initial commit

This commit is contained in:
2020-06-07 17:00:56 +03:00
commit f3b057a7be
32 changed files with 1096 additions and 0 deletions

18
lib/commons/commons.ex Normal file
View File

@@ -0,0 +1,18 @@
defmodule Localizator.Commons do
def struct_from_map(a_map, as: a_struct) do
# Find the keys within the map
keys =
Map.keys(a_struct)
|> Enum.filter(fn x -> x != :__struct__ end)
# Process map, checking for both string / atom keys
processed_map =
for key <- keys, into: %{} do
value = Map.get(a_map, key) || Map.get(a_map, to_string(key))
{key, value}
end
a_struct = Map.merge(a_struct, processed_map)
a_struct
end
end