Class: Faker::Bank

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

Constant Summary

Constants inherited from Base

Faker::Base::Letters, 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(digits = 10) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/faker/default/bank.rb', line 8

def (digits = 10)
  output = ''

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

  output[0...digits]
end

.iban(country_code = 'GB') ⇒ Object



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

def iban(country_code = 'GB')
  # Each country has it's 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
  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

.nameObject



33
34
35
# File 'lib/faker/default/bank.rb', line 33

def name
  fetch('bank.name')
end

.routing_numberObject



37
38
39
# File 'lib/faker/default/bank.rb', line 37

def routing_number
  valid_routing_number
end

.routing_number_with_formatObject



41
42
43
# File 'lib/faker/default/bank.rb', line 41

def routing_number_with_format
  compile_fraction(valid_routing_number)
end

.swift_bicObject



45
46
47
# File 'lib/faker/default/bank.rb', line 45

def swift_bic
  fetch('bank.swift_bic')
end