# `ContactsPerDomainCap`
[🔗](https://github.com/jaizendra-netizen/contacts_per_domain_cap/blob/main/lib/contacts_per_domain_cap.ex#L1)

Mark the contacts that go over a per-domain cap in a CSV you supply.

Input columns: `contact_id` and `email`. The domain is the text after the last `@`,
trimmed and lower-cased. In input order the first `cap` contacts of each domain are
`keep`, later ones are `over cap`. Extra columns are ignored.

Every domain is counted the same, including a domain that belongs to a mailbox provider
rather than a company: you decide what to do with those. The library reads no outside data.

# `row`

```elixir
@type row() :: %{
  row: pos_integer(),
  id: String.t(),
  email: String.t(),
  domain: String.t()
}
```

# `analyze`

```elixir
@spec analyze([row()], pos_integer()) :: map()
```

Apply the cap. Returns a map with `:cap`, `:contacts`, `:domains`, `:rows` (each row plus
`:decision`, `"keep"` or `"over cap"`, in input order), `:over_domains` (list of
`{domain, ids}`, count desc then domain) and `:over_contacts`.

# `default_cap`

The default cap (3). It is only a default: set it with `--cap`.

# `parse`

```elixir
@spec parse(String.t()) :: {:ok, [row()]} | {:error, String.t()}
```

Parse CSV text into rows. Errors name the row (data rows are counted from 1, header excluded).

# `pct`

```elixir
@spec pct(non_neg_integer(), non_neg_integer()) :: String.t()
```

Percentage with one decimal, rounded half up, as text such as `30.8%`.

# `render`

```elixir
@spec render(map()) :: String.t()
```

Render the analysis as text.

# `to_csv`

```elixir
@spec to_csv(map()) :: String.t()
```

The decisions as CSV text (`contact_id,email,domain,decision`), in input order.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
