Class: Faker::Code

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

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, 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



62
63
64
# File 'lib/faker/default/code.rb', line 62

def asin
  fetch('code.asin')
end

.ean(legacy_base = NOT_GIVEN, base: 13) ⇒ Object

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



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

def ean(legacy_base = NOT_GIVEN, base: 13)
  warn_for_deprecated_arguments do |keywords|
    keywords << :base if legacy_base != NOT_GIVEN
  end

  base == 8 ? generate_base8_ean : generate_base13_ean
end

.imeiObject

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



56
57
58
# File 'lib/faker/default/code.rb', line 56

def imei
  generate_imei
end

.isbn(legacy_base = NOT_GIVEN, 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
18
19
20
21
# File 'lib/faker/default/code.rb', line 15

def isbn(legacy_base = NOT_GIVEN, base: 10)
  warn_for_deprecated_arguments do |keywords|
    keywords << :base if legacy_base != NOT_GIVEN
  end

  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(legacy_min_age = NOT_GIVEN, legacy_max_age = NOT_GIVEN, 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.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/faker/default/code.rb', line 41

def nric(legacy_min_age = NOT_GIVEN, legacy_max_age = NOT_GIVEN, min_age: 18, max_age: 65)
  warn_for_deprecated_arguments do |keywords|
    keywords << :min_age if legacy_min_age != NOT_GIVEN
    keywords << :max_age if legacy_max_age != NOT_GIVEN
  end

  birthyear = Date.birthday(min_age: min_age, max_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



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

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

.sinObject

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/faker/default/code.rb', line 68

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