From 6f523d0059cf84f27be4d91828e2578dce36a32e Mon Sep 17 00:00:00 2001 From: Janos Brauer Date: Tue, 13 Mar 2018 10:35:47 +0100 Subject: [PATCH 1/5] Splits phone numbers correctly and approves only phone numbers of Telma, Orange and Airtel --- lib/phony/countries.rb | 30 ++++++++++++++++------------ spec/functional/plausibility_spec.rb | 16 +++++++++++---- spec/lib/phony/countries_spec.rb | 7 ++++--- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/lib/phony/countries.rb b/lib/phony/countries.rb index 09e82ede..bf8b674c 100644 --- a/lib/phony/countries.rb +++ b/lib/phony/countries.rb @@ -486,19 +486,23 @@ # Madagascar http://www.wtng.info/wtng-261-mg.html # http://www.itu.int/oth/T020200007F/en country '261', - none >> matched_split( - /\A200\d+\z/ => [2,3,3,3], # Telecom Malagasy (Telma) - /\A20\d+\z/ => [2,3,4], # Telecom Malagasy (Telma) - /\A23\d+\z/ => [2,3,4], # Digitel - /\A30\d+\z/ => [2,3,4], # mobile Madamobil (CDMA2000) - /\A31\d+\z/ => [2,3,4], # mobile Airtel Madagascar - /\A32\d+\z/ => [2,3,4], # mobile Orange Madagascar - /\A33\d+\z/ => [2,3,4], # mobile Airtel Madagascar - /\A34\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) - /\A5\d+\z/ => [3,3,3], # pager - /\A22\d+\z/ => [3,3,3], # satellite GULFSAT Téléphonie - /\A6\d+\z/ => [3,3,3] # satellite - ) + # none >> matched_split( + # /\A200\d+\z/ => [2,3,3,3], # Telecom Malagasy (Telma) + # /\A20\d+\z/ => [2,3,4], # Telecom Malagasy (Telma) + # /\A23\d+\z/ => [2,3,4], # Digitel + # /\A30\d+\z/ => [2,3,4], # mobile Madamobil (CDMA2000) + # /\A31\d+\z/ => [2,3,4], # mobile Airtel Madagascar + # /\A32\d+\z/ => [2,3,4], # mobile Orange Madagascar + # /\A33\d+\z/ => [2,3,4], # mobile Airtel Madagascar + # /\A34\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) + # /\A5\d+\z/ => [3,3,3], # pager + # /\A22\d+\z/ => [3,3,3], # satellite GULFSAT Téléphonie + # /\A6\d+\z/ => [3,3,3] # satellite + # ), + match(/\A(31)\d+\z/) >> split(3,4) | # mobile Airtel Madagascar + match(/\A(32)\d+\z/) >> split(3,4) | # mobile Orange Madagascar + match(/\A(33)\d+\z/) >> split(3,4) | # mobile Airtel Madagascar + match(/\A(34)\d+\z/) >> split(3,4) # mobile Telecom Malagasy (Telma) country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html trunk('0') | diff --git a/spec/functional/plausibility_spec.rb b/spec/functional/plausibility_spec.rb index 0c573847..0f381359 100644 --- a/spec/functional/plausibility_spec.rb +++ b/spec/functional/plausibility_spec.rb @@ -187,10 +187,18 @@ def self.it_is_correct_for(country_name, options={}) it_is_correct_for 'Macedonia', :samples => ['+389 2 123 4567', '+389 7 124 3456', '+389 7 234 5678'] - it_is_correct_for 'Madagascar', :samples => ['+261 20 012 345 678', - '+261 20 124 3456', - '+261 512 345 678', - '+261 33 345 678'] + it_is_correct_for 'Madagascar', :samples => ['+261 31 345 4678', + '+261 32 345 4678', + '+261 33 345 4678', + '+261 34 345 4678'] + it 'is incorrect for Madagascar' do + Phony.plausible?('+261 20 012 345 678').should be_falsey + Phony.plausible?('+261 20 124 3456').should be_falsey + Phony.plausible?('+261 512 345 678').should be_falsey + Phony.plausible?('+261 34 345 46789').should be_falsey + Phony.plausible?('+261 34 345 467').should be_falsey + end + it_is_correct_for 'Malawi', :samples => ['+265 1725 123', '+265 213 456 789', '+265 9123 456', diff --git a/spec/lib/phony/countries_spec.rb b/spec/lib/phony/countries_spec.rb index 5e4c2a80..bf3c4af3 100644 --- a/spec/lib/phony/countries_spec.rb +++ b/spec/lib/phony/countries_spec.rb @@ -990,9 +990,10 @@ def self.it_splits number, expected it_splits '218911234456', %w(218 91 1234 456) end describe 'Madagascar' do - it_splits '26120012345678', ['261', false, '20', '012', '345', '678'] - it_splits '261201243456', ['261', false, *%w(20 124 3456)] - it_splits '261512345678', ['261', false, *%w(512 345 678)] + it_splits '261310254716', ['261', '31', *%w(025 4716)] + it_splits '261320254716', ['261', '32', *%w(025 4716)] + it_splits '261330254716', ['261', '33', *%w(025 4716)] + it_splits '261340254716', ['261', '34', *%w(025 4716)] end describe 'Malawi' do it_splits '2651725123', ['265', false, '1725', '123'] From 99bad2c5bb392cb6cf8a8c84d67007c2a168dc17 Mon Sep 17 00:00:00 2001 From: ht9 Date: Mon, 24 Jan 2022 11:44:11 +0300 Subject: [PATCH 2/5] Update Madagascar number prefixes --- lib/phony/countries.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/phony/countries.rb b/lib/phony/countries.rb index e4966d64..825bda9a 100644 --- a/lib/phony/countries.rb +++ b/lib/phony/countries.rb @@ -487,26 +487,26 @@ match(/^(800)/) >> split(3,3) | # Toll free match(/^(21[1-8])/) >> split(6) # Fixed - # Madagascar http://www.wtng.info/wtng-261-mg.html + # Madagascar + # http://www.wtng.info/wtng-261-mg.html [very old and not up to date] # http://www.itu.int/oth/T020200007F/en country '261', # none >> matched_split( # /\A200\d+\z/ => [2,3,3,3], # Telecom Malagasy (Telma) # /\A20\d+\z/ => [2,3,4], # Telecom Malagasy (Telma) # /\A23\d+\z/ => [2,3,4], # Digitel - # /\A30\d+\z/ => [2,3,4], # mobile Madamobil (CDMA2000) - # /\A31\d+\z/ => [2,3,4], # mobile Airtel Madagascar # /\A32\d+\z/ => [2,3,4], # mobile Orange Madagascar # /\A33\d+\z/ => [2,3,4], # mobile Airtel Madagascar # /\A34\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) + # /\A38\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) # /\A5\d+\z/ => [3,3,3], # pager # /\A22\d+\z/ => [3,3,3], # satellite GULFSAT Téléphonie # /\A6\d+\z/ => [3,3,3] # satellite # ), - match(/\A(31)\d+\z/) >> split(3,4) | # mobile Airtel Madagascar match(/\A(32)\d+\z/) >> split(3,4) | # mobile Orange Madagascar match(/\A(33)\d+\z/) >> split(3,4) | # mobile Airtel Madagascar - match(/\A(34)\d+\z/) >> split(3,4) # mobile Telecom Malagasy (Telma) + match(/\A(34)\d+\z/) >> split(3,4) | # mobile Telecom Malagasy (Telma) + match(/\A(38)\d+\z/) >> split(3,4) # mobile Telecom Malagasy (Telma) country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html trunk('0') | From c11976d6c42192400b336e8a870bcce8afba6402 Mon Sep 17 00:00:00 2001 From: ht9 Date: Mon, 24 Jan 2022 14:01:07 +0300 Subject: [PATCH 3/5] more update on existing number & prefixes --- lib/phony/countries.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/phony/countries.rb b/lib/phony/countries.rb index 825bda9a..e3a8c3f2 100644 --- a/lib/phony/countries.rb +++ b/lib/phony/countries.rb @@ -488,25 +488,23 @@ match(/^(21[1-8])/) >> split(6) # Fixed # Madagascar - # http://www.wtng.info/wtng-261-mg.html [very old and not up to date] + # https://en.wikipedia.org/wiki/Telephone_numbers_in_Madagascar # http://www.itu.int/oth/T020200007F/en country '261', # none >> matched_split( - # /\A200\d+\z/ => [2,3,3,3], # Telecom Malagasy (Telma) # /\A20\d+\z/ => [2,3,4], # Telecom Malagasy (Telma) - # /\A23\d+\z/ => [2,3,4], # Digitel # /\A32\d+\z/ => [2,3,4], # mobile Orange Madagascar # /\A33\d+\z/ => [2,3,4], # mobile Airtel Madagascar # /\A34\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) # /\A38\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) - # /\A5\d+\z/ => [3,3,3], # pager - # /\A22\d+\z/ => [3,3,3], # satellite GULFSAT Téléphonie - # /\A6\d+\z/ => [3,3,3] # satellite + # /\A39\d+\z => [2,3,4] # mobile Blueline # ), + match(/\A(20)\d+\z/) >> split(3,4) | # fix Telecom Malagasy (Telma) match(/\A(32)\d+\z/) >> split(3,4) | # mobile Orange Madagascar match(/\A(33)\d+\z/) >> split(3,4) | # mobile Airtel Madagascar match(/\A(34)\d+\z/) >> split(3,4) | # mobile Telecom Malagasy (Telma) - match(/\A(38)\d+\z/) >> split(3,4) # mobile Telecom Malagasy (Telma) + match(/\A(38)\d+\z/) >> split(3,4) | # mobile Telecom Malagasy (Telma) + match(/\A(39)\d+\z/) >> split(3,4) # mobile Blueline Madagascar country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html trunk('0') | From 14eb9065a7a9d92f9b85e11144da18cd3f5ceeaa Mon Sep 17 00:00:00 2001 From: ht9 Date: Mon, 24 Jan 2022 15:25:10 +0300 Subject: [PATCH 4/5] fix madagascar format --- lib/phony/countries.rb | 24 ++++++++++++------------ spec/functional/plausibility_spec.rb | 13 +++++++------ spec/lib/phony/countries_spec.rb | 8 ++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/phony/countries.rb b/lib/phony/countries.rb index e3a8c3f2..657bac92 100644 --- a/lib/phony/countries.rb +++ b/lib/phony/countries.rb @@ -492,19 +492,19 @@ # http://www.itu.int/oth/T020200007F/en country '261', # none >> matched_split( - # /\A20\d+\z/ => [2,3,4], # Telecom Malagasy (Telma) - # /\A32\d+\z/ => [2,3,4], # mobile Orange Madagascar - # /\A33\d+\z/ => [2,3,4], # mobile Airtel Madagascar - # /\A34\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) - # /\A38\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma) - # /\A39\d+\z => [2,3,4] # mobile Blueline + # /\A20\d+\z/ => [2,2,3,2], # Telecom Malagasy (Telma) + # /\A32\d+\z/ => [2,2,3,2], # mobile Orange Madagascar + # /\A33\d+\z/ => [2,2,3,2], # mobile Airtel Madagascar + # /\A34\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma) + # /\A38\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma) + # /\A39\d+\z => [2,2,3,2] # mobile Blueline # ), - match(/\A(20)\d+\z/) >> split(3,4) | # fix Telecom Malagasy (Telma) - match(/\A(32)\d+\z/) >> split(3,4) | # mobile Orange Madagascar - match(/\A(33)\d+\z/) >> split(3,4) | # mobile Airtel Madagascar - match(/\A(34)\d+\z/) >> split(3,4) | # mobile Telecom Malagasy (Telma) - match(/\A(38)\d+\z/) >> split(3,4) | # mobile Telecom Malagasy (Telma) - match(/\A(39)\d+\z/) >> split(3,4) # mobile Blueline Madagascar + match(/\A(20)\d+\z/) >> split(2,3,2) | # fix Telecom Malagasy (Telma) + match(/\A(32)\d+\z/) >> split(2,3,2) | # mobile Orange Madagascar + match(/\A(33)\d+\z/) >> split(2,3,2) | # mobile Airtel Madagascar + match(/\A(34)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma) + match(/\A(38)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma) + match(/\A(39)\d+\z/) >> split(2,3,2) # mobile Blueline Madagascar country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html trunk('0') | diff --git a/spec/functional/plausibility_spec.rb b/spec/functional/plausibility_spec.rb index b36b385d..589dde01 100644 --- a/spec/functional/plausibility_spec.rb +++ b/spec/functional/plausibility_spec.rb @@ -317,14 +317,15 @@ def self.it_is_correct_for(country_name, options={}) it_is_correct_for 'Macedonia', :samples => ['+389 2 123 4567', '+389 7 124 3456', '+389 7 234 5678'] - it_is_correct_for 'Madagascar', :samples => ['+261 31 345 4678', - '+261 32 345 4678', - '+261 33 345 4678', - '+261 34 345 4678'] + it_is_correct_for 'Madagascar', :samples => ['+261 20 23 456 78', + '+261 32 34 546 78', + '+261 33 34 546 78', + '+261 34 34 546 78', + '+261 38 34 546 78'] it 'is incorrect for Madagascar' do Phony.plausible?('+261 20 012 345 678').should be_falsey - Phony.plausible?('+261 20 124 3456').should be_falsey - Phony.plausible?('+261 512 345 678').should be_falsey + Phony.plausible?('+261 20 12 434 569').should be_falsey + Phony.plausible?('+261 51 23 4567 8').should be_falsey Phony.plausible?('+261 34 345 46789').should be_falsey Phony.plausible?('+261 34 345 467').should be_falsey end diff --git a/spec/lib/phony/countries_spec.rb b/spec/lib/phony/countries_spec.rb index 609d929b..2d6a8c93 100644 --- a/spec/lib/phony/countries_spec.rb +++ b/spec/lib/phony/countries_spec.rb @@ -1048,10 +1048,10 @@ def self.it_splits number, expected it_splits '218911234456', %w(218 91 1234 456) end describe 'Madagascar' do - it_splits '261310254716', ['261', '31', *%w(025 4716)] - it_splits '261320254716', ['261', '32', *%w(025 4716)] - it_splits '261330254716', ['261', '33', *%w(025 4716)] - it_splits '261340254716', ['261', '34', *%w(025 4716)] + it_splits '261202254716', ['261', '20', *%w(22 547 16)] + it_splits '261320254716', ['261', '32', *%w(02 547 16)] + it_splits '261330254716', ['261', '33', *%w(02 547 16)] + it_splits '261340254716', ['261', '34', *%w(02 547 16)] end describe 'Malawi' do it_splits '2651725123', ['265', false, '1725', '123'] From a4ebe60401d742a9414ef106a41c5bdaf257ffd6 Mon Sep 17 00:00:00 2001 From: ht9 Date: Mon, 24 Jan 2022 23:53:38 +0300 Subject: [PATCH 5/5] update gem spec --- phony.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phony.gemspec b/phony.gemspec index 3014817c..aaa4513f 100644 --- a/phony.gemspec +++ b/phony.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'phony' - s.version = '2.18.15' + s.version = '2.18.16' s.authors = ['Florian Hanke'] s.email = 'florian.hanke+phony@gmail.com' s.homepage = 'http://github.com/floere/phony'