class Faker::Finance

def condominium_fiscal_code(country: 'IT')

Returns:
  • (String) -

Parameters:
  • country (String) -- Two capital letter country code to use for the vat number.
def condominium_fiscal_code(country: 'IT')
  numerify(fetch("finance.condominium_fiscal_code.#{country}"))
end

def credit_card(*types)

Returns:
  • (String) -

Parameters:
  • types (String) -- Specific credit card type.
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

def stock_market

Returns:
  • (String) -
def stock_market
  fetch('finance.stock_market')
end

def ticker(*markets)

Returns:
  • (String) -

Parameters:
  • markets (String) -- The name of the market to choose the ticker from (e.g. NYSE, NASDAQ)
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

def vat_number(country: 'BR')

Returns:
  • (String) -

Parameters:
  • country (String) -- Two capital letter country code to use for the vat number.
def vat_number(country: 'BR')
  numerify(fetch("finance.vat_number.#{country}"))
rescue I18n::MissingTranslationData
  raise ArgumentError, "Could not find vat number for #{country}"
end

def vat_number_keys

def vat_number_keys
  translate('faker.finance.vat_number').keys
end