Class: Faker::Bank

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/bank.rb

Constant Summary

Constants inherited from Base

Faker::Base::LLetters, Faker::Base::Letters, Faker::Base::NOT_GIVEN, Faker::Base::Numbers, Faker::Base::ULetters

Class Method Summary collapse

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

.account_number(legacy_digits = NOT_GIVEN, digits: 10) ⇒ String

Produces a bank account number.

Examples:

Faker::Bank. #=> 6738582379
Faker::Bank.(digits: 13) #=> 673858237902

Parameters:

  • digits (Integer) (defaults to: 10)

    Number of digits that the generated account number should have.

Returns:

  • (String)

Available since:

  • 1.9.1


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/faker/default/bank.rb', line 19

def (legacy_digits = NOT_GIVEN, digits: 10)
  warn_for_deprecated_arguments do |keywords|
    keywords << :digits if legacy_digits != NOT_GIVEN
  end

  output = ''

  output += rand.to_s[2..-1] while output.length < digits

  output[0...digits]
end

.bsb_numberString

Produces an Australian BSB (Bank-State-Branch) number

Examples:

Faker::Bank.bsb_number
  #=> "036616"

Returns:

  • (String)

Available since:

  • 2.13.0


141
142
143
# File 'lib/faker/default/bank.rb', line 141

def bsb_number
  compile_bsb_number
end

.iban(legacy_country_code = NOT_GIVEN, country_code: 'GB') ⇒ String

Produces a bank iban number.

Examples:

Faker::Bank.iban #=> "GB76DZJM33188515981979"
Faker::Bank.iban(country_code: "be") #=> "BE6375388567752043"
Faker::Bank.iban(country_code: nil) #=> "DE45186738071857270067"

Parameters:

  • country_code (String, nil) (defaults to: 'GB')

    Specifies what country prefix is used to generate the iban code. Providing `nil` will use a random country.

Returns:

  • (String)

Available since:

  • 1.7.0


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/faker/default/bank.rb', line 43

def iban(legacy_country_code = NOT_GIVEN, country_code: 'GB')
  # Each country has its own format for bank accounts
  # Many of them use letters in certain parts of the account
  # Using regex patterns we can create virtually any type of bank account
  warn_for_deprecated_arguments do |keywords|
    keywords << :country_code if legacy_country_code != NOT_GIVEN
  end

  country_code ||= iban_country_code

  begin
    pattern = fetch("bank.iban_details.#{country_code.downcase}.bban_pattern")
  rescue I18n::MissingTranslationData
    raise ArgumentError, "Could not find iban details for #{country_code}"
  end

  # Use Faker::Base.regexify for creating a sample from bank account format regex
   = Base.regexify(/#{pattern}/)

  # Add country code and checksum to the generated account to form valid IBAN
  country_code.upcase + iban_checksum(country_code, ) + 
end

.iban_country_codeString

Produces the ISO 3166 code of a country that uses the IBAN system.

Examples:

Faker::Bank.iban_country_code #=> "CH"

Returns:

  • (String)

Available since:

  • next


75
76
77
# File 'lib/faker/default/bank.rb', line 75

def iban_country_code
  sample(translate('faker.bank.iban_details').keys).to_s.upcase
end

.nameString

Produces a bank name.

Examples:

Faker::Bank.name #=> "ABN AMRO CORPORATE FINANCE LIMITED"

Returns:

  • (String)

Available since:

  • 1.7.0


88
89
90
# File 'lib/faker/default/bank.rb', line 88

def name
  fetch('bank.name')
end

.routing_numberString

Produces a routing number.

Examples:

Faker::Bank.routing_number #=> "729343831"

Returns:

  • (String)

Available since:

  • 1.9.1


101
102
103
# File 'lib/faker/default/bank.rb', line 101

def routing_number
  valid_routing_number
end

.routing_number_with_formatString

Produces a valid routing number.

Examples:

Faker::Bank.routing_number #=> "729343831"

Returns:

  • (String)

Available since:

  • 1.9.1


114
115
116
# File 'lib/faker/default/bank.rb', line 114

def routing_number_with_format
  compile_fraction(valid_routing_number)
end

.swift_bicString

Produces a swift / bic number.

Examples:

Faker::Bank.swift_bic #=> "AAFMGB21"

Returns:

  • (String)

Available since:

  • 1.7.0


127
128
129
# File 'lib/faker/default/bank.rb', line 127

def swift_bic
  fetch('bank.swift_bic')
end