Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documents error response for Phone.parse/1 and Phone.parse/2 in specs #136

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/phone.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ defmodule Phone do

```
"""
@spec parse(String.t()) :: {:ok, Map.t()}
@spec parse(pos_integer | String.t()) :: {:ok, Map.t()} | {:error, String.t()}
def parse(number) when is_bitstring(number) do
number
|> prepare_number
|> Phone.Countries.build()
end

@spec parse(pos_integer) :: {:ok, Map.t()}
def parse(number) when is_integer(number) do
number = Integer.to_string(number)
parse(number)
Expand Down Expand Up @@ -91,7 +90,7 @@ defmodule Phone do

```
"""
@spec parse!(String.t()) :: Map.t()
@spec parse!(pos_integer | String.t()) :: Map.t()
def parse!(number) when is_bitstring(number) do
number = clear(number)

Expand All @@ -105,7 +104,6 @@ defmodule Phone do
Phone.Countries.build!(number)
end

@spec parse!(pos_integer) :: Map.t()
def parse!(number) when is_integer(number) do
number = Integer.to_string(number)
parse!(number)
Expand All @@ -115,10 +113,8 @@ defmodule Phone do
raise ArgumentError, message: "Not a valid parameter, only string or integer."
end

@spec parse(String.t(), Atom.t()) :: {:ok, Map.t()}
@spec parse(pos_integer, Atom.t()) :: {:ok, Map.t()}
@spec parse!(String.t(), Atom.t()) :: Map.t()
@spec parse!(pos_integer, Atom.t()) :: Map.t()
@spec parse(pos_integer | String.t(), Atom.t()) :: {:ok, Map.t()} | {:error, String.t()}
@spec parse!(pos_integer | String.t(), Atom.t()) :: Map.t()
country_parser()

@doc """
Expand All @@ -139,14 +135,13 @@ defmodule Phone do

```
"""
@spec parse(String.t()) :: boolean
@spec valid?(pos_integer | String.t()) :: boolean
def valid?(number) when is_bitstring(number) do
number
|> prepare_number
|> Phone.Countries.match?()
end

@spec parse(pos_integer) :: boolean
def valid?(number) when is_integer(number) do
number
|> to_string
Expand Down