Skip to content

Commit

Permalink
Merge pull request #65 from fcevado/correct_sao_paulo_area
Browse files Browse the repository at this point in the history
Correct São Paulo number validation.
  • Loading branch information
fcevado authored Aug 2, 2016
2 parents b647024 + b2f6046 commit e779d0a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Changelog

##v0.3.3:
* Correct number validation to São Paulo - BR.

##v0.3.2:
* Area codes for Brazil.
* Updated all regular expressions for NANP, to enforce end of line.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Add to your depencies like any other hex package.

```elixir
defp deps do
[{:phone, "0.1.1"}]
[{:phone, "0.3.3"}]
end
```

Expand Down
12 changes: 9 additions & 3 deletions lib/helpers/area.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ defmodule Helper.Area do
end

def builder(number) do
[_ | country] = Module.split(__MODULE__) |> Enum.reverse
country = Enum.reverse(country) |> Module.concat
[_ | country] =
__MODULE__
|> Module.split
|> Enum.reverse
country =
country
|> Enum.reverse
|> Module.concat

[[_, code, area, number]] = Regex.scan(regex,number)
[[_, code, area, number]] = Regex.scan(regex, number)

%{
country: country.country,
Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/country.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ defmodule Helper.Country do
defp modules_matcher do
quote do
def match?(number) do
ms = Enum.filter(modules, fn(m)-> m.match?(number) end)
ms = Enum.filter(modules, fn m -> m.match?(number) end)
length(ms) > 0
end

def build(number) do
if match?(number) do
[module] = Enum.filter(modules, fn(m)-> m.match?(number) end)
[module] = Enum.filter(modules, fn m -> m.match?(number) end)
module.build(number)
else
{:error, "Not a valid phone number."}
Expand All @@ -68,7 +68,7 @@ defmodule Helper.Country do

def build!(number) do
if match?(number) do
[module] = Enum.filter(modules, fn(m)-> m.match?(number) end)
[module] = Enum.filter(modules, fn m -> m.match?(number) end)
module.build!(number)
else
raise ArgumentError, message: "Not a valid phone number."
Expand Down
2 changes: 1 addition & 1 deletion lib/phone.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defmodule Phone do

number
|> String.graphemes
|> Enum.filter(fn(n)-> ! Enum.any?(remove,fn(r)-> r == n end) end)
|> Enum.filter(fn n -> ! Enum.any?(remove, fn r -> r == n end) end)
|> Enum.join("")
end

Expand Down
2 changes: 1 addition & 1 deletion lib/phone/br/sp.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Phone.BR.SP do
use Helper.Area
field :regex, ~r/^(55)(1[1-9])([2-5|89].{7}|9[89].{7}|7[07-9].{6})$/
field :regex, ~r/^(55)(1[1-9])([2-5|89].{7}|9.{8}|7[07-9].{6})$/
field :area_name, "São Paulo"
field :area_type, "state"
field :area_abbreviation, "SP"
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Phonex.Mixfile do

def project do
[app: :phone,
version: "0.3.2",
version: "0.3.3",
elixir: ">= 1.1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down Expand Up @@ -47,6 +47,7 @@ defmodule Phonex.Mixfile do

defp deps do
[
{:credo, "0.4.7", only: [:dev, :test]},
{:earmark, "0.2.1", only: :dev},
{:ex_doc, "0.11.4", only: :dev},
{:inch_ex, "0.5.1", only: :docs}
Expand Down
4 changes: 3 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%{"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
"credo": {:hex, :credo, "0.4.7", "1516ebd3c6099eff74ed0ef50637f0a43113c3f65338a9e1792efc03dff34855", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.11.4", "a064bdb720594c3745b94709b17ffb834fd858b4e0c1f48f37c0d92700759e02", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
"inch_ex": {:hex, :inch_ex, "0.5.1", "c1c18966c935944cbb2d273796b36e44fab3c54fd59f906ff026a686205b4e14", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
"poison": {:hex, :poison, "2.1.0", "f583218ced822675e484648fa26c933d621373f01c6c76bd00005d7bd4b82e27", [:mix], []}}

0 comments on commit e779d0a

Please sign in to comment.