Class: Faker::PhoneNumber
- Defined in:
- lib/faker/default/phone_number.rb
Constant Summary
Constants inherited from Base
Base::Letters, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.area_code ⇒ Object
US and Canada only.
- .cell_phone ⇒ Object
- .cell_phone_with_country_code ⇒ Object
- .country_code ⇒ Object
-
.exchange_code ⇒ Object
US and Canada only.
- .phone_number ⇒ Object
- .phone_number_with_country_code ⇒ Object
-
.subscriber_number(length = 4) ⇒ Object
(also: extension)
US and Canada only Can be used for both extensions and last four digits of phone 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 ⇒ Object
US and Canada only
27 28 29 30 31 |
# File 'lib/faker/default/phone_number.rb', line 27 def area_code fetch('phone_number.area_code') rescue I18n::MissingTranslationData nil end |
.cell_phone ⇒ Object
10 11 12 |
# File 'lib/faker/default/phone_number.rb', line 10 def cell_phone parse('cell_phone.formats') end |
.cell_phone_with_country_code ⇒ Object
22 23 24 |
# File 'lib/faker/default/phone_number.rb', line 22 def cell_phone_with_country_code "#{country_code} #{cell_phone}" end |
.country_code ⇒ Object
14 15 16 |
# File 'lib/faker/default/phone_number.rb', line 14 def country_code "+#{fetch('country_code')}" end |
.exchange_code ⇒ Object
US and Canada only
34 35 36 37 38 |
# File 'lib/faker/default/phone_number.rb', line 34 def exchange_code fetch('phone_number.exchange_code') rescue I18n::MissingTranslationData nil end |
.phone_number ⇒ Object
6 7 8 |
# File 'lib/faker/default/phone_number.rb', line 6 def phone_number parse('phone_number.formats') end |
.phone_number_with_country_code ⇒ Object
18 19 20 |
# File 'lib/faker/default/phone_number.rb', line 18 def phone_number_with_country_code "#{country_code} #{phone_number}" end |
.subscriber_number(length = 4) ⇒ Object Also known as: extension
US and Canada only Can be used for both extensions and last four digits of phone number. Since extensions can be of variable length, this method taks a length parameter
43 44 45 |
# File 'lib/faker/default/phone_number.rb', line 43 def subscriber_number(length = 4) rand.to_s[2..(1 + length)] end |