Class: Faker::Indian::Phone

Inherits:
Object
  • Object
show all
Defined in:
lib/faker/indian/phone.rb

Constant Summary collapse

OPERATORS =
data.fetch(:operators).freeze
STD_CODES =
data.fetch(:std_codes).freeze

Class Method Summary collapse

Class Method Details

.landlineObject



22
23
24
25
26
# File 'lib/faker/indian/phone.rb', line 22

def landline
  std = STD_CODES.sample(random: random)
  number = random.rand(1_000_000..9_999_999)
  "0#{std}-#{number}"
end

.mobile_number(formatted: true) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/faker/indian/phone.rb', line 14

def mobile_number(formatted: true)
  first_digit = random.rand(6..9)
  remaining = random.rand(0..999_999_999)
  digits = "#{first_digit}#{format('%09d', remaining)}"

  formatted ? "+91 #{digits}" : digits
end

.operatorObject



28
29
30
# File 'lib/faker/indian/phone.rb', line 28

def operator
  OPERATORS.sample(random: random)
end

.whatsapp_number(formatted: true) ⇒ Object



32
33
34
# File 'lib/faker/indian/phone.rb', line 32

def whatsapp_number(formatted: true)
  mobile_number(formatted: formatted)
end