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(legacy_base = NOT_GIVEN, base: 13) ⇒ String
Produces a random EAN (European Article Number) code.
-
.imei ⇒ String
Produces a random IMEI (International Mobile Equipment Number) code.
-
.isbn(legacy_base = NOT_GIVEN, base: 10) ⇒ String
Produces a random ISBN (International Standard Book Number) code.
-
.npi ⇒ String
Produces a random NPI (National Provider Identifer) code.
-
.nric(legacy_min_age = NOT_GIVEN, legacy_max_age = NOT_GIVEN, 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
138 139 140 |
# File 'lib/faker/default/code.rb', line 138 def asin fetch('code.asin') end |
.ean(legacy_base = NOT_GIVEN, base: 13) ⇒ String
Produces a random EAN (European Article Number) code.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/faker/default/code.rb', line 56 def ean(legacy_base = NOT_GIVEN, base: 13) warn_for_deprecated_arguments do |keywords| keywords << :base if legacy_base != NOT_GIVEN end 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.
125 126 127 |
# File 'lib/faker/default/code.rb', line 125 def imei generate_imei end |
.isbn(legacy_base = NOT_GIVEN, base: 10) ⇒ String
Produces a random ISBN (International Standard Book Number) code.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/faker/default/code.rb', line 32 def isbn(legacy_base = NOT_GIVEN, base: 10) warn_for_deprecated_arguments do |keywords| keywords << :base if legacy_base != NOT_GIVEN end 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 Identifer) code.
16 17 18 |
# File 'lib/faker/default/code.rb', line 16 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) ⇒ 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.
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/faker/default/code.rb', line 102 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 |
.rut ⇒ String
Produces a random RUT (Rol Unico Nacional) code.
77 78 79 80 81 |
# File 'lib/faker/default/code.rb', line 77 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.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/faker/default/code.rb', line 151 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 |