Module: FFaker::PhoneNumber
Instance Method Summary
collapse
const_missing, k, luhn_check, underscore, unique
#fetch_sample, #rand, #shuffle
Instance Method Details
#area_code ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/ffaker/phone_number.rb', line 29
def area_code
loop do
rand_area_code = rand(201..999)
return rand_area_code unless rand_area_code % 100 == 11
end
end
|
#exchange_code ⇒ Object
39
40
41
42
43
44
|
# File 'lib/ffaker/phone_number.rb', line 39
def exchange_code
area_code
end
|
#imei(serial_number = nil) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/ffaker/phone_number.rb', line 54
def imei(serial_number = nil)
characters = Array.new(15, 0)
rbi_codes = %w[01 10 30 33 35 44 45 49 50 51 52 53 54 86 91 98 99]
serial_number ||= rand(0...1_000_000)
serial_number = format('%06d', serial_number).chars.map(&:to_i)
first_two_chars = fetch_sample(rbi_codes)
characters[0, 2] = first_two_chars.chars.map(&:to_i)
2.upto(7) do |current_position|
characters[current_position] = fetch_sample((0..9).to_a)
end
8.upto(13) do |current_position|
characters[current_position] = serial_number[current_position - 8]
end
current_checksum = characters.reverse.each_with_index.inject(0) do |sum, (digit, i)|
digit *= 2 if i.odd?
digit -= 9 if digit > 9
sum + digit
end
final_digit = (10 - (current_checksum % 10)) % 10
characters[14] = final_digit
characters.join
end
|
#phone_calling_code ⇒ Object
50
51
52
|
# File 'lib/ffaker/phone_number.rb', line 50
def phone_calling_code
fetch_sample(PHONE_CALLING_CODE)
end
|
#phone_number ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ffaker/phone_number.rb', line 8
def phone_number
FFaker.numerify case rand(0..19)
when 0 then "#{area_code}-#{exchange_code}-#### x#####"
when 1 then "#{area_code}-#{exchange_code}-#### x####"
when 2 then "#{area_code}-#{exchange_code}-#### x###"
when 3..4 then "#{area_code}-#{exchange_code}-####"
when 5 then "#{area_code}.#{exchange_code}.#### x#####"
when 6 then "#{area_code}.#{exchange_code}.#### x####"
when 7 then "#{area_code}.#{exchange_code}.#### x###"
when 8..9 then "#{area_code}.#{exchange_code}.####"
when 10 then "(#{area_code})#{exchange_code}-#### x#####"
when 11 then "(#{area_code})#{exchange_code}-#### x####"
when 12 then "(#{area_code})#{exchange_code}-#### x###"
when 13..14 then "(#{area_code})#{exchange_code}-####"
when 15 then "1-#{area_code}-#{exchange_code}-#### x#####"
when 16 then "1-#{area_code}-#{exchange_code}-#### x####"
when 17 then "1-#{area_code}-#{exchange_code}-#### x###"
when 18..19 then "1-#{area_code}-#{exchange_code}-####"
end
end
|
#short_phone_number ⇒ Object
46
47
48
|
# File 'lib/ffaker/phone_number.rb', line 46
def short_phone_number
FFaker.numerify("#{area_code}-#{exchange_code}-####")
end
|