Skip to content

Commit

Permalink
Merge pull request floere#493 from mtomady/master
Browse files Browse the repository at this point in the history
Update Madagascar mobile numbers prefixes
  • Loading branch information
floere authored Jan 25, 2022
2 parents 0744f3b + 30338c0 commit cb8739f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
30 changes: 16 additions & 14 deletions lib/phony/countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,22 +493,24 @@
match(/^(800)/) >> split(3,3) | # Toll free
match(/^(21[1-8])/) >> split(6) # Fixed

# Madagascar http://www.wtng.info/wtng-261-mg.html
# Madagascar
# 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
/\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(
# /\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(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') |
Expand Down
17 changes: 13 additions & 4 deletions spec/functional/plausibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,19 @@ 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 6789']
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 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

it_is_correct_for 'Malawi', :samples => ['+265 1725 123',
'+265 213 456 789',
'+265 9123 456',
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/phony/countries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1053,9 +1053,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 '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']
Expand Down

0 comments on commit cb8739f

Please sign in to comment.