Skip to content

Commit

Permalink
Add trunk prefix and improve formatting for Zambia
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Nov 15, 2021
1 parent 82e0b26 commit b7ed4fc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/phony/countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,10 @@
# Zambia
# http://www.wtng.info/wtng-260-zm.html
# https://github.com/googlei18n/libphonenumber/
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
country '260',
match(/^([79][5678]\d)/) >> split(6) | # Mobile
trunk('0') |
match(/^(76|77|95|96|97)/) >> split(3, 4) | # Mobile
match(/^(800)/) >> split(3,3) | # Toll free
match(/^(21[1-8])/) >> split(6) # Fixed

Expand Down
5 changes: 5 additions & 0 deletions qed/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ With forced trunk.
Phony.format('41443643532', :format => :local).assert == '364 35 32'
Phony.format('493038625454', :format => :local).assert == '386 25454'

#### Zambia

Phony.format('260970212078').assert == '+260 97 021 2078'
Phony.format('260970212078', :format => :national).assert == '097 021 2078'

#### Zimbabwe

##### Mobile numbers
Expand Down
12 changes: 6 additions & 6 deletions spec/functional/plausibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,12 @@ def self.it_is_correct_for(country_name, options={})
'+967 58 1234']
it 'is correct for Zambia' do
Phony.plausible?('+260 211 123456').should be_truthy # Fixed
Phony.plausible?('+260 761 123456').should be_truthy # Mobile
Phony.plausible?('+260 772 123456').should be_truthy # Mobile
Phony.plausible?('+260 783 123456').should be_truthy # Mobile
Phony.plausible?('+260 955 123456').should be_truthy # Mobile
Phony.plausible?('+260 967 123456').should be_truthy # Mobile
Phony.plausible?('+260 978 123456').should be_truthy # Mobile
Phony.plausible?('+260 96 512 4567').should be_truthy # MTN Mobile
Phony.plausible?('+260 97 712 3456').should be_truthy # Airtel Mobile
Phony.plausible?('+260 95 512 4567').should be_truthy # Zamtel Mobile
Phony.plausible?('+260 96 512 456').should be_falsy # MTN Mobile (Too short)
Phony.plausible?('+260 97 812 345').should be_falsy # Airtel Mobile (Too short)
Phony.plausible?('+260 95 512 345').should be_falsy # Zamtel Mobile (Too short)
Phony.plausible?('+260 800 123 456').should be_truthy # Toll free
end
it_is_correct_for 'Zimbabwe', :samples => [['+263 2582 123 456', '+263 2582 123'],
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/phony/countries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,9 @@ def self.it_splits number, expected
end
describe 'Zambia' do
it_splits '260211123456', ['260', '211', '123456'] # Fixed
it_splits '260955123456', ['260', '955', '123456'] # Mobile
it_splits '260967123456', ['260', '967', '123456'] # Mobile
it_splits '260978123456', ['260', '978', '123456'] # Mobile
it_splits '260955123456', ['260', '95', '512', '3456'] # Mobile
it_splits '260967123456', ['260', '96', '712', '3456'] # Mobile
it_splits '260978123456', ['260', '97', '812', '3456'] # Mobile
it_splits '260800123456', ['260', '800', '123', '456'] # Toll free
end
describe 'New Zealand' do
Expand Down Expand Up @@ -1433,7 +1433,7 @@ def self.it_splits number, expected
describe 'Universal International Freephone' do
it_splits '80012345678', ['800', false, '12345678']
end

describe 'Shared-Cost Service' do
it_splits '80812345678', ['808', false, '12345678']
end
Expand Down

0 comments on commit b7ed4fc

Please sign in to comment.