phony 2.22.7 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +117 -0
- data/lib/phony/countries.rb +5 -3
- metadata +7 -6
- data/README.textile +0 -116
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e5491894cacb9480a995f6019cee2bc68b3d3e02b8e18f5263e014478b2877e4
|
|
4
|
+
data.tar.gz: 11c7378a92034ac69617aaa0dd5e0ce2a4da0b1cc29b5ae88a7ee471a8e3c546
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7be10b412c69bb4e034b2fdba3968c25191205d89a6c861468169f799d0a28e5d555a1c5a2a3f8a96b957ab0ac5c625c826001f048b6b4055f5da63872329b46
|
|
7
|
+
data.tar.gz: '0619a41caaaeb7d1a72d1688811355bcc6343fdac0c5e54d19fec4e2d90049eb0a73ed04eec0c432f74940ac5c7ba765a7adb7f9d893588b0cdc73d3ec9f7a74'
|
data/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
[](http://travis-ci.org/floere/phony)
|
|
2
|
+
[](https://coveralls.io/r/floere/phony?branch=master)
|
|
3
|
+
[](https://codeclimate.com/github/floere/phony)
|
|
4
|
+
[](http://inch-ci.org/github/floere/phony)
|
|
5
|
+
|
|
6
|
+
# Phony
|
|
7
|
+
|
|
8
|
+
Disclaimer: Phony works with international numbers only, such as `61 412 345 678`!
|
|
9
|
+
|
|
10
|
+
The (admittedly crazy) goal of this Gem is to be able to normalize/format/split all phone numbers in the world.
|
|
11
|
+
|
|
12
|
+
Used in: [airbnb.com](http://airbnb.com), [socialcam.com](http://socialcam.com), [zendesk.com](http://www.zendesk.com/) (and many, many others).
|
|
13
|
+
|
|
14
|
+
## Runtime Memory Usage {#memory}
|
|
15
|
+
|
|
16
|
+
According to [memory_profiler](https://github.com/SamSaffron/memory_profiler), the Phony gem uses roughly 1MB of memory per Ruby process.
|
|
17
|
+
Usage was generated using (look for `Total retained`): `ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'`
|
|
18
|
+
|
|
19
|
+
## Description
|
|
20
|
+
|
|
21
|
+
This gem normalizes, formats and splits "**E164 phone numbers**". A valid E164 phone number **must** include a country code.
|
|
22
|
+
|
|
23
|
+
E164 numbers are international numbers with a country dial prefix, usually an area code and a subscriber number. For example, the Australian number `+61 412 345 678` can be broken down into the following components:
|
|
24
|
+
* Country Code (CC): a country code of `61`
|
|
25
|
+
* National Destination Code (NDC): a mobile number denoted by the `4` (specific to Australia)
|
|
26
|
+
* Local Number Part: a subscriber number of `12 345 678`
|
|
27
|
+
|
|
28
|
+
It currently handles the countries listed at the end of this README.
|
|
29
|
+
|
|
30
|
+
It is covered by roughly 2,250 tests that run in 2 seconds (April 2019).
|
|
31
|
+
If it doesn't work, please [enter an issue](http://github.com/floere/phony/issues) or better, fork and [send a pull request](http://github.com/floere/phony/pulls).
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
With Rails? Check out: https://github.com/joost/phony_rails.
|
|
36
|
+
|
|
37
|
+
With Bundler: Append `gem 'phony'` to your `Gemfile` and `bundle install` it.
|
|
38
|
+
|
|
39
|
+
Without Bundler: Run `gem install phony` from your command line.
|
|
40
|
+
|
|
41
|
+
## Usage docs {#usage}
|
|
42
|
+
|
|
43
|
+
Phony uses [qed](https://github.com/rubyworks/qed) as docs and to run its functional tests. Start here for usage docs: [Usage index](./qed/index.md).
|
|
44
|
+
|
|
45
|
+
### Phony.normalize(number) {#normalizing}
|
|
46
|
+
|
|
47
|
+
Normalize intelligently removes all non-numeric characters of a number. Do it before storing a number in a DB.
|
|
48
|
+
|
|
49
|
+
[Phony.normalize docs](./qed/normalize.md)
|
|
50
|
+
|
|
51
|
+
`Phony.normalize('1-888-407-4747').assert == '18884074747'`
|
|
52
|
+
|
|
53
|
+
### Phony.format(number, options = {}) {#formatting}
|
|
54
|
+
|
|
55
|
+
Format formats a normalized number according to a country's predominant formatting. Lots of options for int'l, national, local formatting.
|
|
56
|
+
|
|
57
|
+
[Phony.format docs](./qed/format.md)
|
|
58
|
+
|
|
59
|
+
`Phony.format('41443643532').assert == '+41 44 364 35 32'`
|
|
60
|
+
|
|
61
|
+
### Phony.plausible?(number, options = {}) {#plausibility}
|
|
62
|
+
|
|
63
|
+
Is a number plausible?
|
|
64
|
+
|
|
65
|
+
[Phony.plausible? docs](./qed/plausibility.md)
|
|
66
|
+
|
|
67
|
+
`Phony.assert.plausible?('+41 44 111 22 33')`
|
|
68
|
+
|
|
69
|
+
### Phony.split(number) {#splitting}
|
|
70
|
+
|
|
71
|
+
Split a number into its parts: CC, NDC, local.
|
|
72
|
+
|
|
73
|
+
[Phony.split docs](./qed/split.md)
|
|
74
|
+
|
|
75
|
+
`Phony.split('3928061371').assert == ['39', '2', '806', '1371']`
|
|
76
|
+
|
|
77
|
+
NB If a country does not have an NDC, `#split` will return `false` in the NDC position, for example for Denmark:
|
|
78
|
+
|
|
79
|
+
`Phony.split('4512121212').assert == ['45', false, '12', '12', '12', '12']`
|
|
80
|
+
|
|
81
|
+
### Loading only a country subset (Phony 2.18.0+). {#loading}
|
|
82
|
+
|
|
83
|
+
Use this in case you'd like to save [memory](#memory) that is used by Phony's CC rules.
|
|
84
|
+
|
|
85
|
+
[Phony::Config.load docs](./qed/config.md)
|
|
86
|
+
|
|
87
|
+
First, `require 'phony/config'`.
|
|
88
|
+
Then, one of the following, which will load the rest of Phony.
|
|
89
|
+
|
|
90
|
+
Load only these CCs:
|
|
91
|
+
`Phony::Config.load(only: ['41', '44'])`
|
|
92
|
+
|
|
93
|
+
Loads everything except these CCs:
|
|
94
|
+
`Phony::Config.load(except: ['41', '44'])`
|
|
95
|
+
|
|
96
|
+
Convenience form of `only`:
|
|
97
|
+
`Phony::Config.load('41', '44')`
|
|
98
|
+
|
|
99
|
+
Each of these loads the rest of Phony.
|
|
100
|
+
|
|
101
|
+
Memory usage can be checked using (look for `Total retained`):
|
|
102
|
+
`ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony/config"; Phony::Config.load("1") }.pretty_print'`
|
|
103
|
+
For example, when just loading the NANP CC, the retained memory usage is ~63kB.
|
|
104
|
+
|
|
105
|
+
## List of Handled Countries
|
|
106
|
+
|
|
107
|
+
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Japanese, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mauritian, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
|
|
108
|
+
|
|
109
|
+
## Proud Sponsors
|
|
110
|
+
|
|
111
|
+
* Renuo AG (July 2022 – January 2025): [Github](https://github.com/renuo), [Homepage](https://www.renuo.ch). Much appreciated!
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT.
|
|
116
|
+
See [LICENSE](./LICENSE) file.
|
|
117
|
+
|
data/lib/phony/countries.rb
CHANGED
|
@@ -101,7 +101,7 @@ Phony.define do
|
|
|
101
101
|
match(/^(800|90\d)\d+$/) >> split(2, 3) | # Toll free service and premium numbers
|
|
102
102
|
match(/^(46[056789])\d{6}$/) >> split(2, 2, 2) | # Mobile (Lycamobile, Telenet, Join Experience, Proximus 0460)
|
|
103
103
|
match(/^(4[789]\d)\d{6}$/) >> split(2, 2, 2) | # Mobile
|
|
104
|
-
match(/^(45[156])\d{6}$/)
|
|
104
|
+
match(/^(45[156])\d{6}$/) >> split(2, 2, 2) | # Mobile Vikings, Digi and Voo
|
|
105
105
|
one_of('2', '3', '4', '9') >> split(3, 2, 2) | # Short NDCs
|
|
106
106
|
fixed(2) >> split(2, 2, 2) # 2-digit NDCs
|
|
107
107
|
|
|
@@ -251,7 +251,7 @@ Phony.define do
|
|
|
251
251
|
match(/^(13)\d+$/) >> split(2, 2) | # 13 local rate
|
|
252
252
|
fixed(1) >> split(4, 4) # Rest
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
# country '62' # Indonesia (Republic of), see special file
|
|
255
255
|
|
|
256
256
|
# Philippines (Republic of the)
|
|
257
257
|
# https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PH
|
|
@@ -279,7 +279,9 @@ Phony.define do
|
|
|
279
279
|
|
|
280
280
|
# Singapore (Republic of).
|
|
281
281
|
#
|
|
282
|
+
# There is no trunk code for this country and some numbers start with 0.
|
|
282
283
|
country '65',
|
|
284
|
+
trunk('', normalize: false) |
|
|
283
285
|
none >> matched_split(
|
|
284
286
|
/^(800)\d{7}$/ => [3, 3, 4], # International Toll Free Service (ITFS) and Home Country Direct Service (HCDS) Numbers
|
|
285
287
|
/^\d{8}$/ => [4, 4] # TODO: Short Codes
|
|
@@ -375,7 +377,7 @@ Phony.define do
|
|
|
375
377
|
|
|
376
378
|
# Benin http://www.itu.int/oth/T0202000017/en
|
|
377
379
|
#
|
|
378
|
-
# There is no trunk code for this country and prefixes start with 0
|
|
380
|
+
# There is no trunk code for this country and prefixes start with 0.
|
|
379
381
|
country '229',
|
|
380
382
|
trunk('', normalize: false) |
|
|
381
383
|
none >> matched_split(
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: phony
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Hanke
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-12-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 'Fast international phone number (E164 standard) normalizing, splitting
|
|
14
14
|
and formatting. Lots of formatting options: International (+.., 00..), national
|
|
@@ -17,9 +17,9 @@ email: florian.hanke+phony@gmail.com
|
|
|
17
17
|
executables: []
|
|
18
18
|
extensions: []
|
|
19
19
|
extra_rdoc_files:
|
|
20
|
-
- README.
|
|
20
|
+
- README.md
|
|
21
21
|
files:
|
|
22
|
-
- README.
|
|
22
|
+
- README.md
|
|
23
23
|
- lib/phony.rb
|
|
24
24
|
- lib/phony/config.rb
|
|
25
25
|
- lib/phony/countries.rb
|
|
@@ -82,7 +82,8 @@ files:
|
|
|
82
82
|
homepage: https://github.com/floere/phony
|
|
83
83
|
licenses:
|
|
84
84
|
- MIT
|
|
85
|
-
metadata:
|
|
85
|
+
metadata:
|
|
86
|
+
rubygems_mfa_required: 'true'
|
|
86
87
|
post_install_message:
|
|
87
88
|
rdoc_options: []
|
|
88
89
|
require_paths:
|
|
@@ -91,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
91
92
|
requirements:
|
|
92
93
|
- - ">="
|
|
93
94
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: '2
|
|
95
|
+
version: '3.2'
|
|
95
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
97
|
requirements:
|
|
97
98
|
- - ">="
|
data/README.textile
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"!{float:right}https://secure.travis-ci.org/floere/phony.png!":http://travis-ci.org/floere/phony
|
|
2
|
-
!https://coveralls.io/repos/floere/phony/badge.svg?branch=master(Coverage Status)!:https://coveralls.io/r/floere/phony?branch=master
|
|
3
|
-
"!https://codeclimate.com/github/floere/phony.png!":https://codeclimate.com/github/floere/phony
|
|
4
|
-
!http://inch-ci.org/github/floere/phony.png!:http://inch-ci.org/github/floere/phony
|
|
5
|
-
|
|
6
|
-
h1. Phony
|
|
7
|
-
|
|
8
|
-
Disclaimer: Phony works with international numbers only, such as @61 412 345 678@!
|
|
9
|
-
|
|
10
|
-
The (admittedly crazy) goal of this Gem is to be able to normalize/format/split all phone numbers in the world.
|
|
11
|
-
|
|
12
|
-
Used in: "airbnb.com":http://airbnb.com, "socialcam.com":http://socialcam.com, "zendesk.com":http://www.zendesk.com/ (and many, many others).
|
|
13
|
-
|
|
14
|
-
h2(#memory). Runtime Memory Usage
|
|
15
|
-
|
|
16
|
-
According to "memory_profiler":https://github.com/SamSaffron/memory_profiler, the Phony gem uses roughly 1MB of memory per Ruby process.
|
|
17
|
-
Usage was generated using (look for @Total retained@): @ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'@
|
|
18
|
-
|
|
19
|
-
h2. Description
|
|
20
|
-
|
|
21
|
-
This gem normalizes, formats and splits "*E164 phone numbers*":http://en.wikipedia.org/wiki/E.164. A valid E164 phone number *must* include a country code.
|
|
22
|
-
|
|
23
|
-
E164 numbers are international numbers with a country dial prefix, usually an area code and a subscriber number. For example, the Australian number @+61 412 345 678@ can be broken down into the following components:
|
|
24
|
-
* Country Code (CC): a country code of @61@
|
|
25
|
-
* National Destination Code (NDC): a mobile number denoted by the @4@ (specific to Australia)
|
|
26
|
-
* Local Number Part: a subscriber number of @12 345 678@
|
|
27
|
-
|
|
28
|
-
It currently handles the countries listed at the end of this README.
|
|
29
|
-
|
|
30
|
-
It is covered by roughly 2,250 tests that run in 2 seconds (April 2019).
|
|
31
|
-
If it doesn't work, please "enter an issue":http://github.com/floere/phony/issues or better, fork and "send a pull request":http://github.com/floere/phony/pulls.
|
|
32
|
-
|
|
33
|
-
h2. Installation
|
|
34
|
-
|
|
35
|
-
With Rails? Check out: https://github.com/joost/phony_rails.
|
|
36
|
-
|
|
37
|
-
With Bundler: Append @gem 'phony'@ to your @Gemfile@ and @bundle install@ it.
|
|
38
|
-
|
|
39
|
-
Without Bundler: Run @gem install phony@ from your command line.
|
|
40
|
-
|
|
41
|
-
h2(#usage). Usage docs
|
|
42
|
-
|
|
43
|
-
Phony uses "qed":https://github.com/rubyworks/qed as docs and to run its functional tests. Start here for usage docs: "Usage index":./qed/index.md.
|
|
44
|
-
|
|
45
|
-
h3(#normalizing). Phony.normalize(number)
|
|
46
|
-
|
|
47
|
-
Normalize intelligently removes all non-numeric characters of a number. Do it before storing a number in a DB.
|
|
48
|
-
|
|
49
|
-
"Phony.normalize docs":./qed/normalize.md
|
|
50
|
-
|
|
51
|
-
@Phony.normalize('1-888-407-4747').assert == '18884074747'@
|
|
52
|
-
|
|
53
|
-
h3(#formatting). Phony.format(number, options = {})
|
|
54
|
-
|
|
55
|
-
Format formats a normalized number according to a country's predominant formatting. Lots of options for int'l, national, local formatting.
|
|
56
|
-
|
|
57
|
-
"Phony.format docs":./qed/format.md
|
|
58
|
-
|
|
59
|
-
@Phony.format('41443643532').assert == '+41 44 364 35 32'@
|
|
60
|
-
|
|
61
|
-
h3(#plausibility). Phony.plausible?(number, options = {})
|
|
62
|
-
|
|
63
|
-
Is a number plausible?
|
|
64
|
-
|
|
65
|
-
"Phony.plausible? docs":./qed/plausibility.md
|
|
66
|
-
|
|
67
|
-
@Phony.assert.plausible?('+41 44 111 22 33')@
|
|
68
|
-
|
|
69
|
-
h3(#splitting). Phony.split(number)
|
|
70
|
-
|
|
71
|
-
Split a number into its parts: CC, NDC, local.
|
|
72
|
-
|
|
73
|
-
"Phony.split docs":./qed/split.md
|
|
74
|
-
|
|
75
|
-
@Phony.split('3928061371').assert == ['39', '2', '806', '1371']@
|
|
76
|
-
|
|
77
|
-
NB If a country does not have an NDC, @#split@ will return @false@ in the NDC position, for example for Denmark:
|
|
78
|
-
|
|
79
|
-
@Phony.split('4512121212').assert == ['45', false, '12', '12', '12', '12']@
|
|
80
|
-
|
|
81
|
-
h3(#loading). Loading only a country subset (Phony 2.18.0+).
|
|
82
|
-
|
|
83
|
-
Use this in case you'd like to save "memory":#memory that is used by Phony's CC rules.
|
|
84
|
-
|
|
85
|
-
"Phony::Config.load docs":./qed/config.md
|
|
86
|
-
|
|
87
|
-
First, @require 'phony/config'@.
|
|
88
|
-
Then, one of the following, which will load the rest of Phony.
|
|
89
|
-
|
|
90
|
-
Load only these CCs:
|
|
91
|
-
@Phony::Config.load(only: ['41', '44'])@
|
|
92
|
-
|
|
93
|
-
Loads everything except these CCs:
|
|
94
|
-
@Phony::Config.load(except: ['41', '44'])@
|
|
95
|
-
|
|
96
|
-
Convenience form of @only@:
|
|
97
|
-
@Phony::Config.load('41', '44')@
|
|
98
|
-
|
|
99
|
-
Each of these loads the rest of Phony.
|
|
100
|
-
|
|
101
|
-
Memory usage can be checked using (look for @Total retained@):
|
|
102
|
-
@ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony/config"; Phony::Config.load("1") }.pretty_print'@
|
|
103
|
-
For example, when just loading the NANP CC, the retained memory usage is ~63kB.
|
|
104
|
-
|
|
105
|
-
h2. List of Handled Countries
|
|
106
|
-
|
|
107
|
-
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Japanese, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mauritian, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
|
|
108
|
-
|
|
109
|
-
h2. Proud Sponsors
|
|
110
|
-
|
|
111
|
-
* Renuo AG (July 2022 – January 2025): "Github":https://github.com/renuo, "Homepage":https://www.renuo.ch. Much appreciated!
|
|
112
|
-
|
|
113
|
-
h2. License
|
|
114
|
-
|
|
115
|
-
MIT.
|
|
116
|
-
See "LICENSE":./LICENSE file.
|