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

Make country_code_to_region_code_map public #87

Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions lib/ex_phone_number.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defmodule ExPhoneNumber do
alias ExPhoneNumber.Formatting
alias ExPhoneNumber.Parsing
alias ExPhoneNumber.Validation
alias ExPhoneNumber.Metadata

def format(%ExPhoneNumber.Model.PhoneNumber{} = phone_number, phone_number_format)
when is_atom(phone_number_format),
Expand All @@ -52,4 +53,9 @@ defmodule ExPhoneNumber do

def parse(number_to_parse, default_region),
do: Parsing.parse(number_to_parse, default_region)

@doc """
Returns a map of country codes to region codes.
"""
defdelegate country_code_to_region_code_map(), to: Metadata
end
3 changes: 2 additions & 1 deletion lib/ex_phone_number/metadata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ defmodule ExPhoneNumber.Metadata do
Map.put(acc, new_key, Keyword.get_values(list_cctrc, key))
end)

defp country_code_to_region_code_map() do
@doc false
def country_code_to_region_code_map() do
unquote(Macro.escape(map_cctrc))
end

Expand Down
8 changes: 8 additions & 0 deletions test/ex_phone_number/metadata_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,12 @@ defmodule ExPhoneNumber.MetadataTest do
end
end
end

describe "country_code_to_region_code_map" do
test "returns a map of country phone prefixes to region codes" do
result = country_code_to_region_code_map()
assert is_map(result)
assert Map.get(result, 1) == ["US", "CA", "BS", "BB"]
end
end
end