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 area code.
-
.cell_phone ⇒ String
Produces a random cell phone number in a random format without the country code and it can have different dividers.
-
.cell_phone_in_e164 ⇒ String
Produces a random phone number in e164 format, i.e., without any dividers.
-
.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 exchange code.
-
.phone_number ⇒ String
Produces a phone number in a random format without the country code and it 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 extension / subscriber number.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.area_code ⇒ String
Produces a random area code.
107 108 109 |
# File 'lib/faker/default/phone_number.rb', line 107 def area_code fetch('phone_number.area_code') end |
.cell_phone ⇒ String
Produces a random cell phone number in a random format without the country code and it can have different dividers.
32 33 34 |
# File 'lib/faker/default/phone_number.rb', line 32 def cell_phone parse('cell_phone.formats') end |
.cell_phone_in_e164 ⇒ String
Produces a random phone number in e164 format, i.e., without any dividers.
92 93 94 |
# File 'lib/faker/default/phone_number.rb', line 92 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.
77 78 79 |
# File 'lib/faker/default/phone_number.rb', line 77 def cell_phone_with_country_code "#{country_code} #{cell_phone}" end |
.country_code ⇒ String
Produces a random country code.
47 48 49 |
# File 'lib/faker/default/phone_number.rb', line 47 def country_code "+#{fetch('phone_number.country_code')}" end |
.exchange_code ⇒ String
Produces a random exchange code.
122 123 124 |
# File 'lib/faker/default/phone_number.rb', line 122 def exchange_code fetch('phone_number.exchange_code') end |
.phone_number ⇒ String
Produces a phone number in a random format without the country code and it can have different dividers.
17 18 19 |
# File 'lib/faker/default/phone_number.rb', line 17 def phone_number parse('phone_number.formats') end |
.phone_number_with_country_code ⇒ String
Produces a random phone number with country code.
62 63 64 |
# File 'lib/faker/default/phone_number.rb', line 62 def phone_number_with_country_code "#{country_code} #{phone_number}" end |
.subscriber_number(length: 4) ⇒ String Also known as: extension
Produces a random extension / subscriber number. Can be used for both extensions and last four digits of phone number.
139 140 141 142 143 144 145 146 147 |
# File 'lib/faker/default/phone_number.rb', line 139 def subscriber_number(length: 4) if !length.is_a?(Integer) || length > 10 raise ArgumentError, 'length must be an Integer and be lesser than 10' end generate(:string) do |g| g.int(length: length) end end |