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

Split a keyword list into head, body and long-tail bands by word count.

Input is a CSV with a `keyword` column and an optional `volume` column (a non-negative
whole number). Words are the whitespace-separated tokens of the trimmed keyword.

  * head: fewer than `body_from` words (default: 1 word)
  * body: `body_from` or more words but fewer than `long_from` (default: 2 to 3 words)
  * long tail: `long_from` or more words (default: 4 or more)

`body_from` and `long_from` are parameters set by you, not rules. They must satisfy
`2 <= body_from < long_from`.

Keywords that repeat (ignoring case and extra spaces) are counted once; the first row
wins, including its volume. Shares and averages are rounded half up to one decimal.

# `keyword_row`

```elixir
@type keyword_row() :: %{
  keyword: String.t(),
  words: pos_integer(),
  volume: non_neg_integer() | nil
}
```

# `parsed`

```elixir
@type parsed() :: %{
  keywords: [keyword_row()],
  duplicates: [String.t()],
  has_volume: boolean()
}
```

# `band`

```elixir
@spec band(pos_integer(), pos_integer(), pos_integer()) :: :head | :body | :long_tail
```

Band name for a word count.

# `check_limits`

```elixir
@spec check_limits(integer(), integer()) :: :ok | {:error, String.t()}
```

Check the band limits: `2 <= body_from < long_from`.

# `parse`

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

Parse the CSV text. Duplicate keywords are dropped (first row kept) and listed.

# `ratio`

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

Divide `num / den * mult` exactly (integers only) and format with `decimals` places,
rounding half up. Returns `"n/a"` when `den` is zero.

# `render`

```elixir
@spec render(parsed(), pos_integer(), pos_integer()) :: String.t()
```

Printable report: totals, duplicates, band table and top keywords.

# `summarize`

```elixir
@spec summarize(parsed(), pos_integer(), pos_integer()) :: [map()]
```

Per-band summary for parsed keywords. Returns a list of three maps (head, body, long tail)
with the keys `band`, `keywords`, `words_total`, `volume` and `top` (up to 3 keywords by
volume, ties by keyword).

---

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