View Source ExPomodoro (ExPomodoro v0.1.0)
Documentation for ExPomodoro
.
Link to this section Summary
Functions
Returns the Elixir.ExPomodoro
child spec. It is intended for appliations to
add an Elixir.ExPomodoro
child spec to their application trees to have an
Elixir.ExPomodoro.Supervisor
started before interacting with the rest of the
Elixir.ExPomodoro
commands.
Generally this function is used to check whether a Pomodoro exists or not.
The Pomodoro timer can be paused using this function. While this function
will cause a pomodoro to pause, it can still finish by timeout, defined in the
Elixir.ExPomodoro.PomodoroServer
implementation.
This is the main function to start a pomodoro.
Link to this section Types
@type already_finished_response() :: {:ok, {:already_finished, ExPomodoro.Pomodoro.t()}}
@type already_started_response() :: {:ok, {:already_started, ExPomodoro.Pomodoro.t()}}
@type not_found_response() :: {:error, :not_found}
@type resumed_response() :: {:ok, {:resumed, ExPomodoro.Pomodoro.t()}}
@type started_response() :: {:ok, {:started, pid()}}
@type success_response() :: {:ok, ExPomodoro.Pomodoro.t()}
Link to this section Functions
@spec child_spec(keyword()) :: Supervisor.child_spec()
Returns the Elixir.ExPomodoro
child spec. It is intended for appliations to
add an Elixir.ExPomodoro
child spec to their application trees to have an
Elixir.ExPomodoro.Supervisor
started before interacting with the rest of the
Elixir.ExPomodoro
commands.
@spec get(ExPomodoro.Pomodoro.id()) :: success_response() | not_found_response()
Generally this function is used to check whether a Pomodoro exists or not.
Given an id
, if a Pomodoro exists, a Elixir.ExPomodoro.Pomodoro
struct is returned,
othwerise returns an error tuple.
examples
Examples:
# Return a pomodoro.
iex> ExPomodoro.get("some id")
{:ok, %ExPomodoro.Pomodoro{id: "some id"}}
# Get a pomodoro that does not exist.
iex> ExPomodoro.get("some other id")
{:error, :not_found}
@spec pause(ExPomodoro.Pomodoro.id()) :: success_response() | not_found_response()
The Pomodoro timer can be paused using this function. While this function
will cause a pomodoro to pause, it can still finish by timeout, defined in the
Elixir.ExPomodoro.PomodoroServer
implementation.
Given an id
, returns a Elixir.ExPomodoro.Pomodoro
struct or an error tuple if the
pomodoro does not exist.
examples
Examples:
# Pause a pomodoro and returns the remaining timeleft to complete the
# current activity.
iex> ExPomodoro.pause("some id")
{:ok, %Pomodoro{id: "some id", activity: :idle, current_duration: timeleft}}
# Pause a pomodoro that does not exist.
iex> ExPomodoro.pause("some id")
{:error, :not_found}
@spec start(ExPomodoro.Pomodoro.id(), ExPomodoro.Pomodoro.opts()) :: success_response() | already_started_response() | already_finished_response() | resumed_response()
This is the main function to start a pomodoro.
Given an id
and an optional keyword of options returns a successful response
if a Pomodoro has been started or resumed. Every successful responses returns
the current Elixir.ExPomodoro.Pomodoro
struct.
options
Options
exercise_duration
: The duration in minutes of the exercise duration,non_negative_integer()
.break_duration
: The duration in minutes of the break duration,non_negative_integer()
.rounds
: The number of rounds until a long break,non_negative_integer()
.
examples
Examples:
# Start a pomodoro with default options.
iex> ExPomodoro.start("some id")
{:ok, %ExPomodoro.Pomodoro{
id: "some id",
activity: :exercise,
exercise_duration: 1_500_000,
break_duration: 300_000,
rounds: 4
}}
# Start a pomodoro with some options.
iex> ExPomodoro.start("some id", [
...> exercise_duration: 150_000,
...> break_duration: 25_000,
...> rounds: 8
...> ])
{:ok, %ExPomodoro.Pomodoro{
id: "some id",
activity: :exercise,
exercise_duration: 150_000,
break_duration: 25_000,
rounds: 8
}}
# Start a pomodoro that is already running.
iex> ExPomodoro.start("some_id")
{:ok, {:already_started, %Pomodoro{id: "some id"}}}
# Start a pomodoro that already finished.
iex> ExPomodoro.start("some_id")
{:ok, {:already_finished, %Pomodoro{id: "some id"}}}
# Start a pomodoro that was paused or finished a break.
iex> ExPomodoro.start("some_id")
{:ok, {:resumed, %Pomodoro{id: "some id"}}}