Class: Faker::PhoneNumber

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/phone_number.rb

Constant Summary

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, sample, shuffle, translate, unique, with_locale

Class Method Details

.area_codeObject

US only



13
14
15
16
17
18
19
# File 'lib/faker/phone_number.rb', line 13

def area_code
  begin
    fetch('phone_number.area_code')
  rescue I18n::MissingTranslationData
    nil
  end
end

.cell_phoneObject



8
9
10
# File 'lib/faker/phone_number.rb', line 8

def cell_phone
  parse('cell_phone.formats')
end

.exchange_codeObject

US only



22
23
24
25
26
27
28
# File 'lib/faker/phone_number.rb', line 22

def exchange_code
  begin
    fetch('phone_number.exchange_code')
  rescue I18n::MissingTranslationData
    nil
  end
end

.phone_numberObject



4
5
6
# File 'lib/faker/phone_number.rb', line 4

def phone_number
  parse('phone_number.formats')
end

.subscriber_number(length = 4) ⇒ Object Also known as: extension

US 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



33
34
35
36
37
38
39
# File 'lib/faker/phone_number.rb', line 33

def subscriber_number(length = 4)
  begin
    rand.to_s[2..(1 + length)]
  rescue I18n::MissingTranslationData
    nil
  end
end