defmodule Braintree.Record do @moduledoc """ A record contains details for a transaction in a summary. """ @type t :: %__MODULE__{ card_type: String.t, count: String.t, merchant_account_id: String.t, kind: String.t, amount_settled: String.t } defstruct card_type: nil, count: "0", merchant_account_id: nil, kind: nil, amount_settled: nil import Braintree.Util, only: [atomize: 1] @doc """ Convert a list of records into structs, including any custom fields that were used as the grouping value. """ @spec new(Map.t) :: t def new(params) when is_map(params) do atomized = atomize(params) summary = struct(__MODULE__, atomized) case Map.keys(atomized) -- Map.keys(summary) do [custom_key] -> Map.put(summary, custom_key, atomized[custom_key]) _ -> summary end end end