Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Kunz committed Jul 20, 2020
2 parents c542fab + e8f6924 commit bab3739
Show file tree
Hide file tree
Showing 72 changed files with 1,617 additions and 395 deletions.
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--format progress
--order rand
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- 2.6
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ group :test do
gem 'pippi', platforms: [:mri_20, :mri_21]
end

group :release do
gem 'gem-release'
end

platforms :rbx do
gem 'rubysl', '~> 2.0'
gem 'json'
Expand Down
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ GEM
diff-lcs (1.3)
docile (1.1.5)
ffi2-generators (0.1.1)
json (2.1.0)
gem-release (2.0.1)
json (2.3.0)
pippi (0.0.14)
qed (2.9.2)
ansi
brass
rake (12.3.0)
rake (12.3.3)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
Expand Down Expand Up @@ -253,6 +254,7 @@ PLATFORMS
DEPENDENCIES
ae
coveralls
gem-release
json
pippi
qed
Expand All @@ -262,4 +264,4 @@ DEPENDENCIES
rubysl (~> 2.0)

BUNDLED WITH
1.16.0
1.17.3
34 changes: 29 additions & 5 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

h1. Phony

Disclaimer: Phony works with international numbers only, such as @+61 412 345 678@!
Disclaimer: Phony works with international numbers only, such as @61 412 345 678@!

The (admittedly crazy) goal of this Gem is to be able to normalize/format/split all phone numbers in the world.

Used in: "airbnb.com":http://airbnb.com, "socialcam.com":http://socialcam.com, "zendesk.com":http://www.zendesk.com/ (and many, many others).

h2. Runtime Memory Usage
h2(#memory). Runtime Memory Usage

According to "memory_profiler":https://github.com/SamSaffron/memory_profiler, the Phony gem uses roughly 1 MB of memory per Ruby process.
Usage was generated using: @ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'@
According to "memory_profiler":https://github.com/SamSaffron/memory_profiler, the Phony gem uses roughly 1MB of memory per Ruby process.
Usage was generated using (look for @Total retained@): @ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'@

h2. Description

Expand All @@ -27,7 +27,7 @@ E164 numbers are international numbers with a country dial prefix, usually an ar

It currently handles the countries listed at the end of this README.

It is covered by roughly 2,000 tests (January 2016).
It is covered by roughly 2,250 tests that run in 2 seconds (April 2019).
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.

h2. Installation
Expand Down Expand Up @@ -78,6 +78,30 @@ NB If a country does not have an NDC, @#split@ will return @false@ in the NDC po

@Phony.split('4512121212').assert == ['45', false, '12', '12', '12', '12']@

h3(#loading). Loading only a country subset (Phony 2.18.0+).

Use this in case you'd like to save "memory":#memory that is used by Phony's CC rules.

"Phony::Config.load docs":./qed/config.md

First, @require 'phony/config'@.
Then, one of the following, which will load the rest of Phony.

Load only these CCs:
@Phony::Config.load(only: ['41', '44'])@

Loads everything except these CCs:
@Phony::Config.load(except: ['41', '44'])@

Convenience form of @only@:
@Phony::Config.load('41', '44')@

Each of these loads the rest of Phony.

Memory usage can be checked using (look for @Total retained@):
@ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony/config"; Phony::Config.load("1") }.pretty_print'@
For example, when just loading the NANP CC, the retained memory usage is ~63kB.

h2. List of Handled Countries

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, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, 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.
Expand Down
1 change: 1 addition & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem release
1 change: 1 addition & 0 deletions bin/tag
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem tag -p
124 changes: 124 additions & 0 deletions history.textile
Original file line number Diff line number Diff line change
@@ -1,3 +1,127 @@
h2. Version 2.18.15

* Cambodia (#469)

h2. Version 2.18.14

* Philippines (#464)
* China (#465)

h2. Version 2.18.13

* China (#462)

h2. Version 2.18.12

* Remove an issue with the DSL code in Ruby 2.7 (#452 and #454).

h2. Version 2.18.11

* Japan (#453)

h2. Version 2.18.10

* Nigeria (#451)

h2. Version 2.18.9

* San Marino (#449)

h2. Version 2.18.8

* Austria (#448)

h2. Version 2.18.7

* Germany (#447)

h2. Version 2.18.6

* Argentina (#444)

h2. Version 2.18.5

* Argentina (#443)

h2. Version 2.18.4

* Egypt (#442)

h2. Version 2.18.3

* Germany (E-Plus has NDC 1577)

h2. Version 2.18.2

* Philippines (#438)

h2. Version 2.18.1

* Freeze Strings where useful.

h2. Version 2.18.0

* Add @Phony::Config.load@ as an option to only load part of the CCs of the library. See the README for details.

h2. Version 2.17.3

* Israel (#437)

h2. Version 2.17.2

* Ireland (#433 and #434)

h2. Version 2.17.1

* Hong Kong (#432)

h2. Version 2.17.0

* Fix issue reported in #428 where a missing local part caused an error.

h2. Version 2.16.11

* Malaysia (#427)

h2. Version 2.16.10

* Russia & Ukraine (#420)
* Vietnam (#423)
* Japan (#424)
* Germany (#425)

h2. Version 2.16.9

* Vietnam (#421)

h2. Version 2.16.8

* PNG (#419)

h2. Version 2.16.7

* UAE (#418)

h2. Version 2.16.6

* Bulgaria (#17)
* Malaysia (#414)
* UAE (#416)

h2. Version 2.16.5

* Bulgaria (#407)
* Kosovo (#410)
* Peru (#411)

h2. Version 2.16.4

* Madagascar (#399)
* New Zealand (#401)
* South Korea (#402)
* Remove dependency on #blank? (#403)
* Satellite phone support (#404, #405)

h2. Version 2.16.3

* Improvements for Austria (#397)
Expand Down
121 changes: 63 additions & 58 deletions lib/phony.rb
Original file line number Diff line number Diff line change
@@ -1,70 +1,75 @@
# frozen_string_literal: true

# NOTE We use Kernel.load here, as it's possible to redefine Phony via Phony::Config.

# Framework.
#
require File.expand_path '../phony/vanity', __FILE__
require File.expand_path '../phony/local_splitters/fixed', __FILE__
require File.expand_path '../phony/local_splitters/regex', __FILE__
require File.expand_path '../phony/national_splitters/dsl', __FILE__
require File.expand_path '../phony/national_splitters/fixed', __FILE__
require File.expand_path '../phony/national_splitters/variable', __FILE__
require File.expand_path '../phony/national_splitters/regex', __FILE__
require File.expand_path '../phony/national_splitters/default', __FILE__
require File.expand_path '../phony/national_splitters/none', __FILE__
require File.expand_path '../phony/national_code', __FILE__
require File.expand_path '../phony/country', __FILE__
require File.expand_path '../phony/trunk_code', __FILE__
require File.expand_path '../phony/country_codes', __FILE__

require File.expand_path '../phony/dsl', __FILE__
load File.expand_path '../phony/config.rb', __FILE__
load File.expand_path '../phony/vanity.rb', __FILE__
load File.expand_path '../phony/local_splitters/fixed.rb', __FILE__
load File.expand_path '../phony/local_splitters/regex.rb', __FILE__
load File.expand_path '../phony/national_splitters/dsl.rb', __FILE__
load File.expand_path '../phony/national_splitters/fixed.rb', __FILE__
load File.expand_path '../phony/national_splitters/variable.rb', __FILE__
load File.expand_path '../phony/national_splitters/regex.rb', __FILE__
load File.expand_path '../phony/national_splitters/default.rb', __FILE__
load File.expand_path '../phony/national_splitters/none.rb', __FILE__
load File.expand_path '../phony/national_code.rb', __FILE__
load File.expand_path '../phony/country.rb', __FILE__
load File.expand_path '../phony/trunk_code.rb', __FILE__
load File.expand_path '../phony/country_codes.rb', __FILE__
load File.expand_path '../phony/dsl.rb', __FILE__

# Countries.
#
# The ones that need more space to define.
#
require File.expand_path '../phony/countries/austria', __FILE__
require File.expand_path '../phony/countries/bangladesh', __FILE__
require File.expand_path '../phony/countries/belarus', __FILE__
require File.expand_path '../phony/countries/brazil', __FILE__
require File.expand_path '../phony/countries/cambodia', __FILE__
require File.expand_path '../phony/countries/croatia', __FILE__
require File.expand_path '../phony/countries/china', __FILE__
require File.expand_path '../phony/countries/georgia', __FILE__
require File.expand_path '../phony/countries/germany', __FILE__
require File.expand_path '../phony/countries/guinea', __FILE__
require File.expand_path '../phony/countries/india', __FILE__
require File.expand_path '../phony/countries/indonesia', __FILE__
require File.expand_path '../phony/countries/ireland', __FILE__
require File.expand_path '../phony/countries/italy', __FILE__
require File.expand_path '../phony/countries/japan', __FILE__
require File.expand_path '../phony/countries/kyrgyzstan', __FILE__
require File.expand_path '../phony/countries/latvia', __FILE__
require File.expand_path '../phony/countries/libya', __FILE__
require File.expand_path '../phony/countries/malaysia', __FILE__
require File.expand_path '../phony/countries/moldova', __FILE__
require File.expand_path '../phony/countries/montenegro', __FILE__
require File.expand_path '../phony/countries/myanmar', __FILE__
require File.expand_path '../phony/countries/namibia', __FILE__
require File.expand_path '../phony/countries/nepal', __FILE__
require File.expand_path '../phony/countries/netherlands', __FILE__
require File.expand_path '../phony/countries/pakistan', __FILE__
require File.expand_path '../phony/countries/paraguay', __FILE__
require File.expand_path '../phony/countries/russia_kazakhstan_abkhasia_south_ossetia', __FILE__
require File.expand_path '../phony/countries/saudi_arabia', __FILE__
require File.expand_path '../phony/countries/serbia', __FILE__
require File.expand_path '../phony/countries/somalia', __FILE__
require File.expand_path '../phony/countries/south_korea', __FILE__
require File.expand_path '../phony/countries/sweden', __FILE__
require File.expand_path '../phony/countries/taiwan', __FILE__
require File.expand_path '../phony/countries/tajikistan', __FILE__
require File.expand_path '../phony/countries/turkmenistan', __FILE__
require File.expand_path '../phony/countries/vietnam', __FILE__
require File.expand_path '../phony/countries/ukraine', __FILE__
require File.expand_path '../phony/countries/united_kingdom', __FILE__
require File.expand_path '../phony/countries/uruguay', __FILE__
require File.expand_path '../phony/countries/zimbabwe', __FILE__
load File.expand_path '../phony/countries/argentina.rb', __FILE__
load File.expand_path '../phony/countries/austria.rb', __FILE__
load File.expand_path '../phony/countries/bangladesh.rb', __FILE__
load File.expand_path '../phony/countries/belarus.rb', __FILE__
load File.expand_path '../phony/countries/brazil.rb', __FILE__
load File.expand_path '../phony/countries/cambodia.rb', __FILE__
load File.expand_path '../phony/countries/croatia.rb', __FILE__
load File.expand_path '../phony/countries/china.rb', __FILE__
load File.expand_path '../phony/countries/georgia.rb', __FILE__
load File.expand_path '../phony/countries/germany.rb', __FILE__
load File.expand_path '../phony/countries/guinea.rb', __FILE__
load File.expand_path '../phony/countries/india.rb', __FILE__
load File.expand_path '../phony/countries/indonesia.rb', __FILE__
load File.expand_path '../phony/countries/ireland.rb', __FILE__
load File.expand_path '../phony/countries/italy.rb', __FILE__
load File.expand_path '../phony/countries/japan.rb', __FILE__
load File.expand_path '../phony/countries/kyrgyzstan.rb', __FILE__
load File.expand_path '../phony/countries/latvia.rb', __FILE__
load File.expand_path '../phony/countries/libya.rb', __FILE__
load File.expand_path '../phony/countries/malaysia.rb', __FILE__
load File.expand_path '../phony/countries/moldova.rb', __FILE__
load File.expand_path '../phony/countries/montenegro.rb', __FILE__
load File.expand_path '../phony/countries/myanmar.rb', __FILE__
load File.expand_path '../phony/countries/namibia.rb', __FILE__
load File.expand_path '../phony/countries/nepal.rb', __FILE__
load File.expand_path '../phony/countries/netherlands.rb', __FILE__
load File.expand_path '../phony/countries/pakistan.rb', __FILE__
load File.expand_path '../phony/countries/paraguay.rb', __FILE__
load File.expand_path '../phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb', __FILE__
load File.expand_path '../phony/countries/saudi_arabia.rb', __FILE__
load File.expand_path '../phony/countries/serbia.rb', __FILE__
load File.expand_path '../phony/countries/somalia.rb', __FILE__
load File.expand_path '../phony/countries/south_korea.rb', __FILE__
load File.expand_path '../phony/countries/sweden.rb', __FILE__
load File.expand_path '../phony/countries/taiwan.rb', __FILE__
load File.expand_path '../phony/countries/tajikistan.rb', __FILE__
load File.expand_path '../phony/countries/turkmenistan.rb', __FILE__
load File.expand_path '../phony/countries/vietnam.rb', __FILE__
load File.expand_path '../phony/countries/ukraine.rb', __FILE__
load File.expand_path '../phony/countries/united_kingdom.rb', __FILE__
load File.expand_path '../phony/countries/uruguay.rb', __FILE__
load File.expand_path '../phony/countries/zimbabwe.rb', __FILE__

# All other countries.
#
require File.expand_path '../phony/countries', __FILE__
load File.expand_path '../phony/countries.rb', __FILE__

# Phony is the main module and is generally used to process
# E164 phone numbers directly.
Expand All @@ -89,7 +94,7 @@ def initialize
#
class SplittingError < ArgumentError
def initialize number
super %Q{Phony could not split the given number. Is #{number.blank? ? 'it' : number.inspect} a phone number?}
super %Q{Phony could not split the given number. Is #{(number.nil? || number == '') ? 'it' : number.inspect} a phone number?}
end
end

Expand Down
Loading

0 comments on commit bab3739

Please sign in to comment.