# `GanttEx.Resource`
[🔗](https://github.com/rocket4ce/gantt_ex/blob/v0.1.0/lib/gantt_ex/resource.ex#L1)

A resource (a person, a team, a machine...) that tasks are assigned to.

  * `:id` - identifier referenced by task assignments. Required.
  * `:text` - display name.
  * `:capacity` - how many units it can work per working day (8 hours by
    default). Assignments use the same units.
  * `:color` - an optional CSS color.

Tasks reference resources in their `:resources` field (see
`cast_assignments/1`), and `GanttEx.ResourceLoad` computes how loaded each
resource is.

    iex> {:ok, resource} = GanttEx.Resource.new(%{"id" => "ana", "text" => "Ana", "capacity" => "6"})
    iex> {resource.id, resource.text, resource.capacity}
    {"ana", "Ana", 6}

    iex> GanttEx.Resource.new(text: "Nobody")
    {:error, {:missing, :id}}

# `assignment`

```elixir
@type assignment() :: %{id: GanttEx.Task.id(), value: number() | nil}
```

A task assignment: the resource and the units per working day (nil = full capacity).

# `t`

```elixir
@type t() :: %GanttEx.Resource{
  capacity: number(),
  color: String.t() | nil,
  id: GanttEx.Task.id(),
  text: String.t()
}
```

# `cast_assignments`

```elixir
@spec cast_assignments(term()) :: {:ok, [assignment()]} | :error
```

Casts task assignments: a list of resource ids, or of maps with an id and a
value (`%{resource_id: 1, value: 4}`, `%{"id" => 1, "value" => "4"}`...).

    iex> GanttEx.Resource.cast_assignments([1, %{resource_id: 2, value: 4}, %{"id" => "3", "value" => "2.5"}])
    {:ok, [%{id: 1, value: nil}, %{id: 2, value: 4}, %{id: "3", value: 2.5}]}

    iex> GanttEx.Resource.cast_assignments(nil)
    {:ok, []}

    iex> GanttEx.Resource.cast_assignments([%{value: 1}])
    :error

# `new`

```elixir
@spec new(map() | keyword() | t()) :: {:ok, t()} | {:error, term()}
```

Builds a resource from a map, keyword list or struct.

# `new!`

```elixir
@spec new!(map() | keyword() | t()) :: t()
```

Like `new/1` but raises `ArgumentError`.

---

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