Class: Faker::Code

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

Constant Summary

Constants inherited from Base

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

Class Method Summary collapse

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

.asinObject

Retrieves a real Amazon ASIN code list taken from archive.org/details/asin_listing


49
50
51
# File 'lib/faker/default/code.rb', line 49

def asin
  fetch('code.asin')
end

.ean(base = 13) ⇒ Object

By default generates 13 sign ean code in format 1234567890123 You can pass 8 to generate ean8 code


21
22
23
# File 'lib/faker/default/code.rb', line 21

def ean(base = 13)
  base == 8 ? generate_base8_ean : generate_base13_ean
end

.imeiObject

Generate GSM modem, device or mobile phone 15 digit IMEI number.


43
44
45
# File 'lib/faker/default/code.rb', line 43

def imei
  generate_imei
end

.isbn(base = 10) ⇒ Object

By default generates 10 sign isbn code in format 123456789-X You can pass 13 to generate new 13 sign code


15
16
17
# File 'lib/faker/default/code.rb', line 15

def isbn(base = 10)
  base == 13 ? generate_base13_isbn : generate_base10_isbn
end

.npiObject

Generates a 10 digit NPI (National Provider Identifier issued to health care providers in the United States)


9
10
11
# File 'lib/faker/default/code.rb', line 9

def npi
  rand(10**10).to_s.rjust(10, '0')
end

.nric(min_age = 18, max_age = 65) ⇒ Object

By default generates a Singaporean NRIC ID for someone who is born between the age of 18 and 65.


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

def nric(min_age = 18, max_age = 65)
  birthyear = Date.birthday(min_age, max_age).year
  prefix = birthyear < 2000 ? 'S' : 'T'
  values = birthyear.to_s[-2..-1]
  values << regexify(/\d{5}/)
  check_alpha = generate_nric_check_alphabet(values, prefix)
  "#{prefix}#{values}#{check_alpha}"
end

.rutObject


25
26
27
28
29
# File 'lib/faker/default/code.rb', line 25

def rut
  value = Number.number(8)
  vd = rut_verificator_digit(value)
  value << "-#{vd}"
end

.sinObject

Generates Social Insurance Number issued in Canada en.wikipedia.org/wiki/Social_Insurance_Number


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/faker/default/code.rb', line 55

def sin
  # 1   - province or temporary resident
  # 2-8 - random numbers
  # 9   - checksum

  # 1st digit. 8,0 are not used
  registry = Faker::Base.sample([1, 2, 3, 4, 5, 6, 7, 9]).to_s

  # generate 2nd to 8th
  partial = Array.new(7) { Faker::Config.random.rand(0..9) }.join

  # Generate 9th digit
  check_digit = generate_sin_check_digit(registry + partial + '0').to_s

  registry + partial + check_digit
end