Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Faker::PhoneNumber.country_code #1426

Merged
merged 11 commits into from
Oct 22, 2018
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## HEAD Unreleased

### Bug/Fixes
- [PR #1425](https://github.com/stympy/faker/pull/1425) NHS: fix occasional bad numbers [@ChaoticBoredom](https://github.com/ChaoticBoredom)
- [PR #1421](https://github.com/stympy/faker/pull/1421) Faker::Internet.user_name can't handle UTF-8 arguments [@ivanoblomov](https://github.com/ivanoblomov)
- [PR #1423](https://github.com/stympy/faker/pull/1423) Add missing locale tests - Part II [@vbrazo](https://github.com/vbrazo)
- [PR #1389](https://github.com/stympy/faker/pull/1389) Load faker I18n using custom backend chaining [@pjohnmeyer](https://github.com/pjohnmeyer)
- [PR #1384](https://github.com/stympy/faker/pull/1384) Quick number method bugfix [@vbrazo](https://github.com/vbrazo)
Expand All @@ -26,6 +28,8 @@
- [PR #372](https://github.com/stympy/faker/pull/372) Add test_password_could_achieve_max_length [@oleksii-ti](https://github.com/oleksii-ti)

### Deprecation
- [PR #1424](https://github.com/stympy/faker/pull/1424) Add Faker::Creature namespace [@ChaoticBoredom](https://github.com/ChaoticBoredom)
- Deprecates `::Cat` and `::Dog`
- [PR #1420](https://github.com/stympy/faker/pull/1420) Add Faker::JapaneseMedia namespace [@boardfish](https://github.com/boardfish)
- Deprecates `::DragonBall`, `::OnePiece` and `::SwordArtOnline`
- [PR #803](https://github.com/stympy/faker/pull/803) Modify Faker::Educator, Fix #576 [@ghbooth12](https://github.com/ghbooth12)
Expand All @@ -44,6 +48,7 @@
- [PR #1329](https://github.com/stympy/faker/pull/1329) Update docs on behavior of price [@softwaregravy](https://github.com/softwaregravy)

### Feature Request
- [PR #1426](https://github.com/stympy/faker/pull/1426) Add Faker::PhoneNumber.country_code [@AmrAdelKhalil](https://github.com/AmrAdelKhalil)
- [PR #1427](https://github.com/stympy/faker/pull/1427) Add Faker::Games::SuperSmashBros [@boardfish](https://github.com/boardfish)
- [PR #1410](https://github.com/stympy/faker/pull/1410) Add Faker::Vehicle.singapore_license_plate [@anonoz](https://github.com/anonoz)
- [PR #1422](https://github.com/stympy/faker/pull/1422) Add Faker::Games::SonicTheHedgehog [@boardfish](https://github.com/boardfish)
Expand Down
6 changes: 6 additions & 0 deletions doc/phone_number.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ Faker::PhoneNumber.subscriber_number #=> "3873"
Faker::PhoneNumber.subscriber_number(2) #=> "39"

Faker::PhoneNumber.extension #=> "3764"

Faker::PhoneNumber.country_code #=> "+20"

Faker::PhoneNumber.phone_number_with_country_code #=> "+95 1-672-173-8153"

Faker::PhoneNumber.cell_phone_with_country_code #=> "+974 (190) 987-9034"
```
12 changes: 12 additions & 0 deletions lib/faker/phone_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ def cell_phone
parse('cell_phone.formats')
end

def country_code
"+#{fetch('country_code')}"
end

def phone_number_with_country_code
"#{country_code} #{phone_number}"
end

def cell_phone_with_country_code
"#{country_code} #{cell_phone}"
end

# US and Canada only
def area_code
fetch('phone_number.area_code')
Expand Down
1 change: 1 addition & 0 deletions lib/locales/en/phone_number.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ en:
formats: ['###-###-####', '(###) ###-####', '1-###-###-####', '###.###.####', '###-###-####', '(###) ###-####', '1-###-###-####', '###.###.####', '###-###-#### x###', '(###) ###-#### x###', '1-###-###-#### x###', '###.###.#### x###', '###-###-#### x####', '(###) ###-#### x####', '1-###-###-#### x####', '###.###.#### x####', '###-###-#### x#####', '(###) ###-#### x#####', '1-###-###-#### x#####', '###.###.#### x#####']
cell_phone:
formats: ['###-###-####', '(###) ###-####', '1-###-###-####', '###.###.####']
country_code: ["1", "1-242", "1-246", "1-264", "1-268", "1-284", "1-340", "1-345", "1-441", "1-473", "1-649", "1-670", "1-671", "1-684", "1-758", "1-784", "1-787", "1-868", "1-869", "1-876", "1-939", "20", "212", "213", "216", "218", "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "238", "238", "239", "240", "241", "242", "243", "244", "245", "247", "248", "249", "250", "251", "252", "253", "254", "255", "256", "257", "258", "260", "261", "262", "263", "264", "265", "266", "267", "268", "269", "269", "27", "290", "291", "297", "298", "299", "30", "31", "32", "33", "33", "34", "350", "351", "352", "353", "354", "355", "356", "357", "358", "359", "36", "370", "371", "372", "373", "374", "375", "376", "378", "380", "381", "381", "381", "385", "386", "387", "389", "39", "39", "40", "41", "420", "421", "423", "43", "44", "45", "46", "47", "48", "49", "500", "501", "502", "503", "504", "505", "506", "507", "508", "509", "51", "52", "53", "54", "55", "56", "57", "58", "591", "592", "593", "594", "595", "596", "596", "597", "598", "599", "60", "61", "61-8", "62", "63", "64", "65", "66", "670", "672", "673", "674", "675", "676", "677", "678", "679", "680", "681", "682", "683", "685", "686", "687", "688", "689", "690", "691", "692", "7", "7-6", "7-7", "767", "809", "809", "809", "81", "82", "84", "850", "850", "852", "853", "855", "855", "856", "86", "880", "886", "886", "90", "91", "92", "93", "94", "95", "960", "961", "962", "963", "964", "965", "966", "967", "968", "971", "972", "973", "974", "975", "976", "977", "98", "993", "994", "995", "996"]
21 changes: 21 additions & 0 deletions test/test_faker_phone_number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

require_relative 'test_helper'

class TestFakerPhone < Test::Unit::TestCase
def setup
@tester = Faker::PhoneNumber
@phone_with_country_code_regex = /\A\+[\s|\d|\-|\(|\)|x|\.]*\z/
end

def test_country_code
assert @tester.country_code.match(/\A\+[\d|-]+\z/)
end

def test_phone_number_with_country_code
assert @tester.phone_number_with_country_code.match(@phone_with_country_code_regex)
end

def test_cell_phone_with_country_code
assert @tester.cell_phone_with_country_code.match(@phone_with_country_code_regex)
end
end