Skip to content

Commit

Permalink
No need for backward compatibility
Browse files Browse the repository at this point in the history
Since it will be release on a new major version
  • Loading branch information
kelvinst committed Sep 5, 2017
1 parent f38acb9 commit 1dc0807
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
11 changes: 2 additions & 9 deletions lib/progress_bar/determinate.ex
Expand Up @@ -7,7 +7,6 @@ defmodule ProgressBar.Determinate do
left: "|",
right: "|",
percent: true,
bytes: false,
suffix: false,
bar_color: [],
blank_color: [],
Expand All @@ -16,16 +15,13 @@ defmodule ProgressBar.Determinate do

def render(current, total, custom_format \\ @default_format)
def render(current, total, custom_format) when current <= total do
format =
@default_format
|> Keyword.merge(custom_format)
|> Enum.into(%{})
format = Keyword.merge(@default_format, custom_format)

percent = current / total * 100 |> round

suffix = [
formatted_percent(format[:percent], percent),
format |> get_suffix() |> formatted_suffix(current, total),
formatted_suffix(format[:suffix], current, total),
newline_if_complete(current, total),
]

Expand All @@ -39,9 +35,6 @@ defmodule ProgressBar.Determinate do

# Private

defp get_suffix(%{suffix: false, bytes: true}), do: :bytes
defp get_suffix(%{suffix: suffix}), do: suffix

defp formatted_percent(false, _) do
""
end
Expand Down
4 changes: 2 additions & 2 deletions test/determinate_test.exs
Expand Up @@ -102,8 +102,8 @@ defmodule DeterminateTest do
test "suffix: :count" do
mb = 100
format = [suffix: :count, width: @width]
assert_bar ProgressBar.render(0, mb, format) == "| | 0% (0/100)"
assert_bar ProgressBar.render(0, mb, format) == "| | 0% (0/100)"
assert_bar ProgressBar.render(50, mb, format) == "|================================================== | 50% (50/100)"
assert_bar ProgressBar.render(mb, mb, format) == "|====================================================================================================| 100% (100)"
assert_bar ProgressBar.render(mb, mb, format) == "|====================================================================================================| 100% (100)"
end
end

0 comments on commit 1dc0807

Please sign in to comment.