Extracts modules for different sections of the UI

This commit is contained in:
Felipe Sere
2016-05-13 11:03:53 +01:00
parent 8a8a0be771
commit af543d1b62
8 changed files with 141 additions and 4 deletions

View File

@@ -0,0 +1,18 @@
defmodule Display.ProgressBar do
@progress_bar_length 30
def progress_bar(%{current: current, total: total}) do
arrow = caluculate_progress(current, total) |> build_arrow
"|" <> String.ljust(arrow, @progress_bar_length) <> "| #{current} of #{total}"
end
defp caluculate_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