Class: Faker::PhoneNumber
- Defined in:
- lib/faker/default/phone_number.rb
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.area_code ⇒ String
Produces a random US or Canada-based area code.
-
.cell_phone ⇒ String
Produces a random cell phone number in a random format (may or may not have a country code and can have different dividers).
-
.cell_phone_in_e164 ⇒ String
Produces a random phone number in e164 format.
-
.cell_phone_with_country_code ⇒ String
Produces a random cell phone number with country code.
-
.country_code ⇒ String
Produces a random country code.
-
.exchange_code ⇒ String
Produces a random US or Canada-based exchange code.
-
.phone_number ⇒ String
Produces a random phone number in a random format (may or may not have a country code, extension and can have different dividers).
-
.phone_number_with_country_code ⇒ String
Produces a random phone number with country code.
-
.subscriber_number(length: 4) ⇒ String
(also: extension)
Produces a random US or Canada-based extension / subscriber number.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.area_code ⇒ String
Produces a random US or Canada-based area code.
93 94 95 96 97 |
# File 'lib/faker/default/phone_number.rb', line 93 def area_code fetch('phone_number.area_code') rescue I18n::MissingTranslationData nil end |
.cell_phone ⇒ String
Produces a random cell phone number in a random format (may or may not have a country code and can have different dividers).
28 29 30 |
# File 'lib/faker/default/phone_number.rb', line 28 def cell_phone parse('cell_phone.formats') end |
.cell_phone_in_e164 ⇒ String
Produces a random phone number in e164 format.
80 81 82 |
# File 'lib/faker/default/phone_number.rb', line 80 def cell_phone_in_e164 cell_phone_with_country_code.delete('^+0-9') end |
.cell_phone_with_country_code ⇒ String
Produces a random cell phone number with country code.
67 68 69 |
# File 'lib/faker/default/phone_number.rb', line 67 def cell_phone_with_country_code "#{country_code} #{cell_phone}" end |
.country_code ⇒ String
Produces a random country code.
41 42 43 |
# File 'lib/faker/default/phone_number.rb', line 41 def country_code "+#{fetch('country_code')}" end |
.exchange_code ⇒ String
Produces a random US or Canada-based exchange code.
108 109 110 111 112 |
# File 'lib/faker/default/phone_number.rb', line 108 def exchange_code fetch('phone_number.exchange_code') rescue I18n::MissingTranslationData nil end |
.phone_number ⇒ String
Produces a random phone number in a random format (may or may not have a country code, extension and can have different dividers).
15 16 17 |
# File 'lib/faker/default/phone_number.rb', line 15 def phone_number parse('phone_number.formats') end |
.phone_number_with_country_code ⇒ String
Produces a random phone number with country code.
54 55 56 |
# File 'lib/faker/default/phone_number.rb', line 54 def phone_number_with_country_code "#{country_code} #{phone_number}" end |
.subscriber_number(length: 4) ⇒ String Also known as: extension
Produces a random US or Canada-based extension / subscriber number. Can be used for both extensions and last four digits of phone number.
126 127 128 |
# File 'lib/faker/default/phone_number.rb', line 126 def subscriber_number(length: 4) rand.to_s[2..(1 + length)] end |