Stopwatch v0.0.4 Stopwatch.Watch
Methods for creating, working and accessing a Watch struct
All methods that starts with a get_* reads the watch status, while the others manipulate it.
For every method that accepts a unit parameter refer to the timex library docs
Summary
Functions
extract lap names from a watch
get a single lap time by its name, if the name do not exists returns nil
get a single lap time by its name, if the name do not exists raises an exception
extract all laps from a watch
gets a timer total time
create a lap by givint it a name and an optional end time
create the last lap by giving it a name, and then stop the watch
create a new Watch
stop the watch, if the watch has already been stopped don’t do nothing
stop the watch and throws and exception if the watch is already stopped
Functions
Specs
get_lap_names(Stopwatch.Watch) :: [binary]
extract lap names from a watch
Examples
iex> Stopwatch.Watch.new |> Stopwatch.Watch.lap(:test) |> Stopwatch.Watch.lap(:test2) |> Stopwatch.Watch.get_lap_names
[:test, :test2]
iex> Stopwatch.Watch.new |> Stopwatch.Watch.get_lap_names
[]
Specs
get_lap_time(Stopwatch.Watch, any, atom) ::
number |
nil
get a single lap time by its name, if the name do not exists returns nil
Examples
iex> use Stopwatch
...> watch = Watch.new({0, 0, 100_000}) |> Watch.last_lap(:test, {0, 0, 200000})
...> Watch.get_lap_time(watch, :not_existent)
nil
iex> use Stopwatch
...> watch = Watch.new({0, 0, 100_000}) |> Watch.lap(:first, {0, 0, 150_000}) |> Watch.last_lap(:test, {0, 0, 200_000})
...> Watch.get_lap_time(watch, :test, :secs)
0.05
Specs
get_lap_time!(Stopwatch.Watch, any, atom) :: number
get a single lap time by its name, if the name do not exists raises an exception
Examples
iex> Stopwatch.Watch.new |> Stopwatch.Watch.last_lap(:test) |> Stopwatch.Watch.get_lap_time!(:not_existent)
** (ArgumentError) the lap named not_existent was not found
Specs
get_laps(Stopwatch.Watch, atom) :: [{binary, {integer, integer, integer}}]
extract all laps from a watch
the output is a list of tuples with {name, {start_time, finish_time}}
Specs
get_total_time(Stopwatch.Watch, atom) ::
float |
integer
gets a timer total time
Specs
lap(Stopwatch.Watch, any, Timex.Time) :: Stopwatch.Watch
create a lap by givint it a name and an optional end time
Specs
last_lap(Stopwatch.Watch, any, Timex.Time) :: Stopwatch.Watch
create the last lap by giving it a name, and then stop the watch
Specs
stop(Stopwatch.Watch, Timex.Time) :: Stopwatch.Watch
stop the watch, if the watch has already been stopped don’t do nothing