Skip to content

Commit

Permalink
Make country_code_to_region_code_map public (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceful-james authored Nov 27, 2024
1 parent 5b8456f commit bd2d5bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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

0 comments on commit bd2d5bc

Please sign in to comment.