View Source Tablex.CodeGenerate (tablex v0.1.1-alpha.3)

This module is responsible for generating Elixir code from a table.

Link to this section Summary

Functions

Transform a table into Elixir code.

Link to this section Functions

@spec generate(String.t() | Tablex.Table.t()) :: String.t()

Transform a table into Elixir code.

examples

Examples

iex> table = """
...> F CreditScore EmploymentStatus Debt-to-Income-Ratio || Action
...> 1 700         employed         <0.43                || Approved
...> 2 700         unemployed       -                    || "Further Review"
...> 3 <=700       -                -                    || Denied
...> """
...>
...> code = generate(table)
...> is_binary(code)
true

The code generated in the above example is:

case {credit_score, employment_status, debt_to_income_ratio} do
  {700, "employed", debt_to_income_ratio}
  when is_number(debt_to_income_ratio) and debt_to_income_ratio < 0.43 ->
    %{action: "Approved"}

  {700, "unemployed", _} ->
    %{action: "Further Review"}

  {credit_score, _, _} when is_number(credit_score) and credit_score <= 700 ->
    %{action: "Denied"}
end