Skip to content

Commit

Permalink
Polish up center
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunya Kirkali committed Jan 24, 2018
1 parent 1d9d949 commit c7bffd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end
## Roadmap

- [x] Swapcase
- [ ] Center
- [x] Center
- [ ] Next
- [ ] Squeeze

Expand Down
10 changes: 6 additions & 4 deletions lib/tanga.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,23 @@ defmodule Tanga do
## Examples
iex> Tanga.center("fin", 9, "~")
"~~~fin~~~"
iex> Tanga.center("fin", 9, "~")
"~~~fin~~~"
"""
@spec center(t, t, t) :: t
@spec center(t, float, t) :: t
@spec center(t, integer, t) :: t
def center(string, char_count, chars \\ " ")

def center(string, char_count, chars) when is_binary(char_count) do
int_char_count = String.to_integer(char_count)
center(string, int_char_count, chars)
do_center(string, int_char_count, chars)
end

def center(string, char_count, chars) when is_float(char_count) do
int_char_count = trunc(char_count)
center(string, int_char_count, chars)
do_center(string, int_char_count, chars)
end

def center(string, char_count, chars) when is_integer(char_count) do
Expand Down

0 comments on commit c7bffd4

Please sign in to comment.