Skip to content

Commit

Permalink
Update contributing guide
Browse files Browse the repository at this point in the history
  • Loading branch information
fcevado committed Apr 22, 2017
1 parent 6d543a8 commit dfcb507
Showing 1 changed file with 26 additions and 38 deletions.
64 changes: 26 additions & 38 deletions CONTRIBUTING.md
Expand Up @@ -5,7 +5,7 @@ There are a couple of ways you can help this project grow, like:
### Helpers Modules

#### Area Modules
The helper for area module prepare everything for the expected behavior of this kind of modules, so you just need to write some static functions that will be overwritten and helps to identify information of what that module describes. The expected functions are: `regex\0`, `area_name\0`, `area_type\0`and `area_abbreviation\0`. There is the `matcher\1` macro, that will create the functions that makes heavy use of pattern matching, the argument is a list of values that will be pattern matched on calling functions, they're the combination of the country code and all the possible area code.
The helper for area module prepare everything for the expected behavior of this kind of modules, so you just need to write some static functions that will be overwritten and helps to identify information of what that module describes. The expected functions are: `regex/0`, `area_name/0`, `area_type/0`and `area_abbreviation/0`. There is the `matcher/1` macro, that will create the functions that makes heavy use of pattern matching, the argument is a list of values that will be pattern matched on calling functions, they're the combination of the country code and all the possible area code.
```elixir
defmodule Phone.NANP.CA.AB do
use Helper.Area
Expand All @@ -19,45 +19,33 @@ defmodule Phone.NANP.CA.AB do
end
```

Required fields for an country module:
* regex, with the full regex for identifing that country. Not needed if has area modules.
* country, with the full country name.
* a2, two letter code for that country.
* a3, three letter code for that country.
* modules, list of area modules for that country.
* match, a macro to say if that country should match against regex or the list of area modules.

### Country Modules
Country modules works similar to area modules but there are two types of country modules. The first have the static functions to be overwritten, `regex/0`, `country/0`, `a2/0`, `a3/0`, and the macro `matcher/2`, the first parameter specifies that you must use `regex/0` to identify the number, the second works just as the list of pattern matchings you want to build to this module.
```elixir
defmodule Phone.NANP.AG do
use Helper.Country
field :regex, ~r/^(1)(268)([2-9].{6})/
field :country, "Antigua and Barbuda"
field :a2, "AG"
field :a3, "ATG"
match :regex
end
```
defmodule Phone.AE do
use Helper.Country

def regex, do: ~r/^(971)(.)(.{7})/
def country, do: "United Arab Emirates"
def a2, do: "AE"
def a3, do: "ARE"

```elixir
defmodule Phone.NANP.CA do
use Helper.Country
field :country, "Canada"
field :a2, "CA"
field :a3, "CAN"
field :modules, [
Phone.NANP.CA.AB,
Phone.NANP.CA.BC,
Phone.NANP.CA.MB,
Phone.NANP.CA.NB,
Phone.NANP.CA.NL,
Phone.NANP.CA.NS_PE,
Phone.NANP.CA.ON,
Phone.NANP.CA.QC,
Phone.NANP.CA.SK,
Phone.NANP.CA.Territory
]
match :modules
end
matcher :regex, ["971"]
end
```

The second just need to overwrite the functions, `country/0`, `a2/0` and `a3/0`. The macro `matcher/2` now specifies that you must use the list of modules in the second parameter to identify the number.
```elixir
defmodule Phone.NANP.CA do
use Helper.Country

def country, do: "Canada"
def a2, do: "CA"
def a3, do: "CAN"

matcher :modules, [Phone.NANP.CA.AB, Phone.NANP.CA.BC, Phone.NANP.CA.MB,
Phone.NANP.CA.NB, Phone.NANP.CA.NL, Phone.NANP.CA.NS_PE,
Phone.NANP.CA.ON, Phone.NANP.CA.QC, Phone.NANP.CA.SK,
Phone.NANP.CA.Territory]
end
```

0 comments on commit dfcb507

Please sign in to comment.