Class: Faker::Bank

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/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, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.account_number(digits = 11) ⇒ Object



6
7
8
# File 'lib/faker/bank.rb', line 6

def (digits = 11)
  rand.to_s[2..digits]
end

.iban(country_code = 'GB') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/faker/bank.rb', line 10

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



27
28
29
# File 'lib/faker/bank.rb', line 27

def name
  fetch('bank.name')
end

.routing_numberObject



31
32
33
# File 'lib/faker/bank.rb', line 31

def routing_number
  valid_routing_number
end

.routing_number_with_formatObject



35
36
37
# File 'lib/faker/bank.rb', line 35

def routing_number_with_format
  compile_fraction(valid_routing_number)
end

.swift_bicObject



39
40
41
# File 'lib/faker/bank.rb', line 39

def swift_bic
  fetch('bank.swift_bic')
end