Class: Faker::Code
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.asin ⇒ String
Retrieves a real Amazon ASIN code from archive.org/details/asin_listing.
-
.ean(base: 13) ⇒ String
Produces a random EAN (European Article Number) code.
-
.imei ⇒ String
Produces a random IMEI (International Mobile Equipment Number) code.
-
.isbn(base: 10) ⇒ String
Produces a random ISBN (International Standard Book Number) code.
-
.npi ⇒ String
Produces a random NPI (National Provider Identifier) code.
-
.nric(min_age: 18, max_age: 65) ⇒ String
Produces a random NRIC (National Registry Identity Card) code.
-
.rut ⇒ String
Produces a random RUT (Rol Unico Nacional) code.
-
.sin ⇒ String
Produces a random SIN (Social Insurance Number for Canada) code.
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
.asin ⇒ String
Retrieves a real Amazon ASIN code from archive.org/details/asin_listing
125 126 127 |
# File 'lib/faker/default/code.rb', line 125 def asin fetch('code.asin') end |
.ean(base: 13) ⇒ String
Produces a random EAN (European Article Number) code.
52 53 54 55 56 57 58 |
# File 'lib/faker/default/code.rb', line 52 def ean(base: 13) case base when 8 then generate_base8_ean when 13 then generate_base13_ean else raise ArgumentError, 'base must be 8 or 13' end end |
.imei ⇒ String
Produces a random IMEI (International Mobile Equipment Number) code.
112 113 114 |
# File 'lib/faker/default/code.rb', line 112 def imei generate_imei end |
.isbn(base: 10) ⇒ String
Produces a random ISBN (International Standard Book Number) code.
32 33 34 35 36 37 38 |
# File 'lib/faker/default/code.rb', line 32 def isbn(base: 10) case base when 10 then generate_base10_isbn when 13 then generate_base13_isbn else raise ArgumentError, 'base must be 10 or 13' end end |
.npi ⇒ String
Produces a random NPI (National Provider Identifier) code.
16 17 18 |
# File 'lib/faker/default/code.rb', line 16 def npi rand(10**10).to_s.rjust(10, '0') end |
.nric(min_age: 18, max_age: 65) ⇒ String
Produces a random NRIC (National Registry Identity Card) code. By default generates a Singaporean NRIC ID for someone who is born between the age of 18 and 65.
94 95 96 97 98 99 100 101 |
# File 'lib/faker/default/code.rb', line 94 def nric(min_age: 18, max_age: 65) birthyear = Date.birthday(min_age: min_age, max_age: max_age).year prefix = birthyear < 2000 ? 'S' : 'T' values = birthyear.to_s[-2..] values << regexify(/\d{5}/) check_alpha = generate_nric_check_alphabet(values, prefix) "#{prefix}#{values}#{check_alpha}" end |
.rut ⇒ String
Produces a random RUT (Rol Unico Nacional) code.
69 70 71 72 73 |
# File 'lib/faker/default/code.rb', line 69 def rut value = Number.number(digits: 8).to_s vd = rut_verificator_digit(value) value << "-#{vd}" end |
.sin ⇒ String
Produces a random SIN (Social Insurance Number for Canada) code.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/faker/default/code.rb', line 138 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 |