Class: Faker::Finance
Constant Summary collapse
- CREDIT_CARD_TYPES =
%i[visa mastercard discover american_express diners_club jcb switch solo dankort maestro forbrugsforeningen laser].freeze
- MARKET_LIST =
%i[nyse nasdaq].freeze
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.condominium_fiscal_code(country: 'IT') ⇒ String
Returns a random condominium fiscal code.
-
.credit_card(*types) ⇒ String
Produces a random credit card number.
-
.stock_market ⇒ String
Returns a randomly-selected stock market.
-
.ticker(*markets) ⇒ String
Returns a randomly-selected stock ticker from a specified market.
-
.vat_number(country: 'BR') ⇒ String
Produces a random vat number.
- .vat_number_keys ⇒ Object
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
.condominium_fiscal_code(country: 'IT') ⇒ String
Returns a random condominium fiscal code.
107 108 109 |
# File 'lib/faker/default/finance.rb', line 107 def condominium_fiscal_code(country: 'IT') numerify(fetch("finance.condominium_fiscal_code.#{country}")) end |
.credit_card(*types) ⇒ String
Produces a random credit card number.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/faker/default/finance.rb', line 24 def credit_card(*types) types = CREDIT_CARD_TYPES if types.empty? type = sample(types) template = numerify(fetch("finance.credit_card.#{type}")) # calculate the luhn checksum digit multiplier = 1 luhn_sum = template.gsub(/[^0-9]/, '').chars.reverse.map(&:to_i).inject(0) do |sum, digit| multiplier = (multiplier == 2 ? 1 : 2) sum + (digit * multiplier).to_s.chars.map(&:to_i).inject(0) { |digit_sum, cur| digit_sum + cur } end # the sum plus whatever the last digit is must be a multiple of 10. So, the # last digit must be 10 - the last digit of the sum. luhn_digit = (10 - (luhn_sum % 10)) % 10 template.gsub('L', luhn_digit.to_s) end |
.stock_market ⇒ String
Returns a randomly-selected stock market.
93 94 95 |
# File 'lib/faker/default/finance.rb', line 93 def stock_market fetch('finance.stock_market') end |
.ticker(*markets) ⇒ String
Returns a randomly-selected stock ticker from a specified market.
76 77 78 79 80 81 82 |
# File 'lib/faker/default/finance.rb', line 76 def ticker(*markets) markets = MARKET_LIST if markets.empty? market = sample(markets) fetch("finance.ticker.#{market}") rescue I18n::MissingTranslationData raise ArgumentError, "Could not find market named #{market}" end |
.vat_number(country: 'BR') ⇒ String
Produces a random vat number.
55 56 57 58 59 |
# File 'lib/faker/default/finance.rb', line 55 def vat_number(country: 'BR') numerify(fetch("finance.vat_number.#{country}")) rescue I18n::MissingTranslationData raise ArgumentError, "Could not find vat number for #{country}" end |
.vat_number_keys ⇒ Object
61 62 63 |
# File 'lib/faker/default/finance.rb', line 61 def vat_number_keys translate('faker.finance.vat_number').keys end |