Transform Map v1.0.3 TransformMap View Source

Documentation for TransformMap.

Link to this section Summary

Link to this section Functions

Link to this function multiple_expand(map, delimiter \\ ".", parallel \\ true) View Source

Convert flat map to deep nested map.

Examples

iex> shrink_map = [%{“id” => 4179, “inserted_at” => “2018-04-25 14:13:33.469994”, “key” => “cGhpc2h4fDI5fD”, “message.schedule_id” => “127”, “message.target.target_domain” => “mydomain.com”, “type” => “email”}] …> iex> expand_map = TransformMap.multiple_expand(shrink_map, “.”, true) [

%{
  "id" => 4179,
  "inserted_at" => "2018-04-25 14:13:33.469994",
  "key" => "cGhpc2h4fDI5fD",
  "message" => %{
    "schedule_id" => "127",
    "target" => %{"target_domain" => "mydomain.com"}
  },
  "type" => "email"
}

] iex> expand_map |> List.first() |> get_in([“message”, “target”, “target_domain”]) “mydomain.com”

Link to this function multiple_keys(map, parallel) View Source

Get All Unique Keys from several maps.

Examples

iex> map = [%{“id” => 4179, “inserted_at” => “2018-04-25 14:13:33.469994”, “key” => “cGhpc2h4fDI5fD”, “message” => %{“schedule_id” => “127”, “target” => %{“target_domain” => “mydomain.com”} }, “type” => “email”}, %{“action” => “open”, “data” => %{“accept_language” => “pt”, “action_group” => “open”, “host” => “host.mydomain.com”, “ip” => “127.0.0.1”, “method” => “GET”, “params” => %{“id” => “cGhpc2h4fDF8MXwx”}}, “referer” => nil, “user_agent” => “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36”, “id” => 7, “updated_at” => “2018-04-01 13:52:48.648710”, “key” => “cGhpc2h4fDF8MXwxfHJlZ3VsYXJ8MXwx”}] …> iex> shrink_map = TransformMap.multiple_shrink(map, “.”, true, true) …> iex> _all_keys = TransformMap.multiple_keys(shrink_map, true) [“action”, “data.accept_language”, “data.action_group”, “data.host”, “data.ip”, “data.method”, “data.params.id”, “id”, “inserted_at”, “key”, “message.schedule_id”, “message.target.target_domain”, “referer”, “type”, “updated_at”, “user_agent”]

Link to this function multiple_shrink(map, delimiter \\ ".", convert_nil \\ true, parallel \\ true) View Source

Convert deep nested map to flat map.

Examples

iex> map = [%{“id” => 4179, “inserted_at” => “2018-04-25 14:13:33.469994”, “key” => “cGhpc2h4fDI5fD”, “message” => %{“schedule_id” => “127”, “target” => %{“target_domain” => “mydomain.com”} }, “type” => “email”}] …> iex> shrink_map = TransformMap.multiple_shrink(map, “.”, true, true) [

%{
  "id" => 4179,
  "inserted_at" => "2018-04-25 14:13:33.469994",
  "key" => "cGhpc2h4fDI5fD",
  "message.schedule_id" => "127",
  "message.target.target_domain" => "mydomain.com",
  "type" => "email"
}

] iex> shrink_map |> List.first() |> Map.get(“message.target.target_domain”) “mydomain.com”

Link to this function multiple_to_array(map, delimiter \\ ".", convert_nil \\ true, parallel \\ true) View Source

Convert map to 2 dimensional array.

Examples

iex> map = [%{“id” => 4179, “inserted_at” => “2018-04-25 14:13:33.469994”, “key” => “cGhpc2h4fDI5fD”, “message” => %{“schedule_id” => “127”, “target” => %{“target_domain” => “mydomain.com”} }, “type” => “email”}] …> iex> _array = TransformMap.multiple_to_array(map, “.”, true, true) [

["id", "inserted_at", "key", "message.schedule_id",
"message.target.target_domain", "type"],
[4179, "2018-04-25 14:13:33.469994", "cGhpc2h4fDI5fD", "127", "mydomain.com",
"email"]

]

Link to this function type_keys(map, item, value, delimiter) View Source