Class: Faker::Code

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/code.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_in_range, regexify, translate, with_locale

Class Method Details

.asinObject

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



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

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



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

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.



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

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



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

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)



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

def npi
  Random.new.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.



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

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



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

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