Skip to content

Commit

Permalink
Merge pull request #301 from gerardc/gerardc/add-special-file-for-sau…
Browse files Browse the repository at this point in the history
…di-arabia

Add special file for Saudi Arabia
  • Loading branch information
floere committed Jan 6, 2016
2 parents 8564b00 + 700cf2f commit 5ab3709
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/phony.rb
Expand Up @@ -48,6 +48,7 @@
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__
Expand Down
9 changes: 1 addition & 8 deletions lib/phony/countries.rb
Expand Up @@ -1048,14 +1048,7 @@
/\A8\d+\z/ => [3,3], # geographic
)

# Saudi Arabia (Kingdom of)
# http://www.wtng.info/wtng-966-sa.html
# http://www.citc.gov.sa/English/MediaCenter/awarenesscampaigns/Pages/PR_AWR_004.aspx
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Saudi_Arabia
# https://answers.yahoo.com/question/index?qid=20090303142622AAQBoZ0
country '966',
match(/\A(5[0-9])\d+\z/) >> split(3,4) | # mobile numbers
fixed(3) >> split(3,4)
# country '966' # Saudi Arabia (Kingdom of), see special file.

# Yemen (Republic of)
# https://www.numberingplans.com/?page=dialling&sub=areacodes
Expand Down
37 changes: 37 additions & 0 deletions lib/phony/countries/saudi_arabia.rb
@@ -0,0 +1,37 @@
# References:
# http://www.itu.int/oth/T02020000B7/en
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Saudi_Arabia

ndcs_with_7_subscriber_digits = [
'11', # Riyadh & the greater central region
'12', # Western region, includes Makkah, Jeddah, Taif, Rabigh
'13', # The Eastern Province, which includes, Dammam, Khobar, Qatif, Jubail, Dhahran, Hafar Al-Batin & others
'14', # Al-Madinah, Tabuk, Al-Jawf, Yanbu, Turaif, Skaka and Northern Borders Region
'16', # Al-Qassim, Buraidah, Majma & Hail
'17', # Southern regions like Asir, Al-Baha, Jizan, Najran & Khamis Mushait
'50', # Mobile: STC
'51', # Mobile: Trunking services
'53', # Mobile: STC
'54', # Mobile: Mobily
'55', # Mobile: STC
'56', # Mobile: Mobily
'57', # Mobile
'58', # Mobile: Zain
'59', # Mobile: Zain
]

toll_free = [
'800'
]

universal_access = [
'9200'
]

Phony.define do
country '966', trunk('0') |
one_of(ndcs_with_7_subscriber_digits) >> split(3,4) |
one_of(toll_free) >> split(3,4) |
one_of(universal_access) >> split(5) |
fixed(3) >> split(3,4)
end
7 changes: 5 additions & 2 deletions spec/lib/phony/countries_spec.rb
Expand Up @@ -1065,8 +1065,11 @@ def self.it_splits number, expected
it_splits '3785123456789', ['378', false, '512', '345', '6789']
end
describe 'Saudi Arabia (Kingdom of)' do
it_splits '9660208528423', %w(966 020 852 8423)
it_splits '966506306201', %w(966 50 630 6201)
it_splits '9660208528423', %w(966 020 852 8423) # Fixed
it_splits '966506306201', %w(966 50 630 6201) # NDC Mobile
it_splits '966112345678', %w(966 11 234 5678) # NDC Region
it_splits '9668001234567', %w(966 800 123 4567) # Toll Free
it_splits '966920012345', %w(966 9200 12345) # Univeral Access
end
describe 'Senegal' do
it_splits '221123456789', ['221', false, '1234', '56789']
Expand Down

0 comments on commit 5ab3709

Please sign in to comment.