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, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.asin ⇒ String
Retrieves a real Amazon ASIN code from archive.org/details/asin_listing
137 138 139 |
# File 'lib/faker/default/code.rb', line 137 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.
124 125 126 |
# File 'lib/faker/default/code.rb', line 124 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 102 103 104 105 106 107 108 109 110 111 112 113 |
# 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 generate(:string) do |g| g.computed(name: :prefix) do if birthyear < 2000 'S' else 'T' end end g.computed(name: :yy) do birthyear.to_s[-2..] end g.int(name: :values, length: 5) g.computed(name: :check, deps: %i[prefix yy values]) do |prefix, yy, values| generate_nric_check_alphabet("#{yy}#{values}", prefix) end end 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.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/faker/default/code.rb', line 150 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 |