Detection trought longest string in map values
This commit is contained in:
@@ -5,6 +5,17 @@ defmodule Localizator.Commons do
|
||||
String.match?(string, @html_regex)
|
||||
end
|
||||
|
||||
def first_non_empty_longest_string(map) when is_map(map) do
|
||||
map
|
||||
|> Map.values()
|
||||
|> Enum.reject(&is_nil(&1))
|
||||
|> Enum.filter(&is_binary(&1))
|
||||
|> Enum.map(&String.trim(&1))
|
||||
|> Enum.reject(&(&1 == ""))
|
||||
|> Enum.sort(&(String.length(&1) >= String.length(&2)))
|
||||
|> List.first()
|
||||
end
|
||||
|
||||
def struct_from_map(a_map, as: a_struct) do
|
||||
# Find the keys within the map
|
||||
keys =
|
||||
|
||||
Reference in New Issue
Block a user