Files
elixir-koans/lib/display/progress_bar.ex
Ahmed Ismail edf50fdf80 Add credo to the project and:
- Run mix credo --all to identify possible code optimizations
 - Resolve most of the errors generated by credo such as:
   - Numbers larger than 9999 should be written with underscores: 58_127
   - Modules should have a @moduledoc tag
   - Comparison will always return true
2023-11-10 00:57:21 +05:00

21 lines
514 B
Elixir

defmodule Display.ProgressBar do
@moduledoc false
@progress_bar_length 30
def progress_bar(%{current: current, total: total}) do
arrow = calculate_progress(current, total) |> build_arrow
"|" <> String.pad_trailing(arrow, @progress_bar_length) <> "| #{current} of #{total}"
end
defp calculate_progress(current, total) do
round(current / total * @progress_bar_length)
end
defp build_arrow(0), do: ""
defp build_arrow(length) do
String.duplicate("=", length - 1) <> ">"
end
end