Class: Faker::Indian::Identity
- Inherits:
-
Object
- Object
- Faker::Indian::Identity
- Defined in:
- lib/faker/indian/identity.rb
Overview
Provides fake identity data specific to the Indian context such as Aadhar numbers, PAN card formats, GSTIN, voterID, passport number.
Constant Summary collapse
- LETTERS =
("A".."Z").to_a.freeze
- PAN_ENTITY_TYPES =
data.fetch(:pan_entity_types).freeze
- GSTIN_STATE_CODES =
data.fetch(:gstin_state_codes).freeze
- CHECKSUM_CHARS =
(("0".."9").to_a + LETTERS).freeze
Class Method Summary collapse
- .aadhaar ⇒ Object
- .aadhaar_masked ⇒ Object
- .driving_license(state: nil) ⇒ Object
- .gstin(pan: nil) ⇒ Object
- .pan ⇒ Object
- .passport ⇒ Object
- .voter_id ⇒ Object
Class Method Details
.aadhaar ⇒ Object
28 29 30 31 32 33 |
# File 'lib/faker/indian/identity.rb', line 28 def aadhaar Array.new(12) { random.rand(0..9) } .join .scan(/.{1,4}/) .join(" ") end |
.aadhaar_masked ⇒ Object
35 36 37 |
# File 'lib/faker/indian/identity.rb', line 35 def aadhaar_masked "XXXX XXXX #{format('%04d', random.rand(0..9999))}" end |
.driving_license(state: nil) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/faker/indian/identity.rb', line 56 def driving_license(state: nil) code = resolve_state_code(state) year = random.rand(2010..2024) series = format("%02d", random.rand(1..99)) number = random.rand(1_000_000..9_999_999) "#{code}-#{series}-#{year}-#{number}" end |
.gstin(pan: nil) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/faker/indian/identity.rb', line 39 def gstin(pan: nil) state = GSTIN_STATE_CODES.sample(random: random) entity_number = random.rand(1..9) checksum = CHECKSUM_CHARS.sample(random: random) pan_value = pan || self.pan "#{state}#{pan_value}#{entity_number}Z#{checksum}" end |
.pan ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/faker/indian/identity.rb', line 18 def pan first_three = Array.new(3) { sample_letter }.join entity_type = PAN_ENTITY_TYPES.sample(random: random) surname_initial = sample_letter numbers = random.rand(1000..9999) last = sample_letter "#{first_three}#{entity_type}#{surname_initial}#{numbers}#{last}" end |
.passport ⇒ Object
52 53 54 |
# File 'lib/faker/indian/identity.rb', line 52 def passport "#{sample_letter}#{random.rand(1_000_000..9_999_999)}" end |
.voter_id ⇒ Object
48 49 50 |
# File 'lib/faker/indian/identity.rb', line 48 def voter_id "#{Array.new(3) { sample_letter }.join}#{random.rand(1_000_000..9_999_999)}" end |