Packages

Elixir SDK to encrypt / decrypt Realex HPP requests and responses.

Current section

Files

Jump to
rxp_hpp lib utils struct_key_mapper.ex
Raw

lib/utils/struct_key_mapper.ex

defmodule RxpHpp.StructKeyMapper do
alias RxpHpp.StructKeyMapper.Helper
@moduledoc """
Convert structs upcasing / downcasing the keys
"""
@doc """
Map a struct `origin` to another `base` applying `func` to each key
"""
def map_struct_with_keys(origin, type, func) do
struct type, map_keys(origin, func)
end
def map_keys(origin, func) do
origin
|> Helper.keys
|> Enum.reduce(
%{},
fn (field, result) ->
Map.put result, func.(field), Map.get(origin, field)
end
)
end
end