File: bank.rb

package info (click to toggle)
ruby-ffaker 2.25.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,852 kB
  • sloc: ruby: 13,136; makefile: 8; sh: 1
file content (130 lines) | stat: -rw-r--r-- 5,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# frozen_string_literal: true

module FFaker
  module Bank
    extend ModuleUtils
    extend self

    COUNTRIES = {
      'AA' => 'AL##########################', # Albania
      'AD' => 'AD######################', # Andorra
      'AT' => 'AT##################', # Austria
      'AZ' => 'AZ##????####################', # Azerbaijan
      'BH' => 'BH##????##############', # Bahrain
      'BY' => 'BY##????####################', # Belarus
      'BE' => 'BE##############', # Belgium
      'BA' => 'BA##################', # Bosnia and Herzegovina
      'BR' => 'BR#########################P#', # Brazil
      'BG' => 'BG##????##############', # Bulgaria
      'CR' => 'CR####################', # Costa Rica
      'HR' => 'HR###################', # Croatia
      'CY' => 'CY##########################', # Cyprus
      'CZ' => 'CZ######################', # Czech Republic
      'DK' => 'DK################', # Denmark
      'DO' => 'DO##????####################', # Dominican Republic
      'SV' => 'SV##????####################', # El Salvador
      'EE' => 'EE##################', # Estonia
      'FO' => 'FO################', # Faroe Islands
      'FI' => 'FI################', # Finland
      'FR' => 'FR#########################', # France
      'GE' => 'GE##??################', # Georgia
      'DE' => 'DE####################', # Germany
      'GI' => 'GI##????###############', # Gibraltar
      'GR' => 'GR#########################', # Greece
      'GL' => 'GL################', # Greenland
      'GT' => 'GT##AGRO####################', # Guatemala
      'VA' => 'VA####################', # Holy See
      'HU' => 'HU##########################', # Hungary
      'IS' => 'IS########################', # Iceland
      'IQ' => 'IQ##????###############', # Iraq
      'IE' => 'IE##????##############', # Ireland
      'IL' => 'IL#####################', # Israel
      'IT' => 'IT##X######################', # Italy
      'JO' => 'JO##????######################', # Jordan
      'KZ' => 'KZ##################', # Kazakhstan
      'XK' => 'XK##################', # Kosovo
      'KW' => 'KW##????######################', # Kuwait
      'LV' => 'LV##????#############', # Latvia
      'LB' => 'LB##########################', # Lebanon
      'LI' => 'LI###################', # Liechtenstein
      'LT' => 'LT##################', # Lithuania
      'LU' => 'LU##################', # Luxembourg
      'MT' => 'MT##MALT#######################', # Malta
      'MR' => 'MR#########################', # Mauritania
      'MU' => 'MU##????###################MUR', # Mauritius
      'MD' => 'MD##??##################', # Moldova
      'MC' => 'MC#########################', # Monaco
      'ME' => 'ME####################', # Montenegro
      'NL' => 'NL##????##########', # Netherlands
      'MK' => 'MK#################', # North Macedonia
      'NO' => 'NO#############', # Norway
      'PK' => 'PK##????################', # Pakistan
      'PS' => 'PS##PALS#####################', # Palestine
      'PL' => 'PL##########################', # Poland
      'PT' => 'PT#######################', # Portugal
      'QA' => 'QA##????#####################', # Qatar
      'RO' => 'RO##????################', # Romania
      'LC' => 'LC##????########################', # Saint Lucia
      'SM' => 'SM##P######################', # San Marino
      'ST' => 'ST#######################', # Sao Tome and Principe
      'SA' => 'SA######################', # Saudi Arabia
      'RS' => 'RS####################', # Serbia
      'SC' => 'SC##????####################USD', # Seychelles
      'SK' => 'SK######################', # Slovak Republic
      'SI' => 'SI#################', # Slovenia
      'ES' => 'ES######################', # Spain
      'SE' => 'SE######################', # Sweden
      'CH' => 'CH###################', # Switzerland
      'TL' => 'TL#####################', # Timor-Leste
      'TN' => 'TN######################', # Tunisia
      'TR' => 'TR########################', # Turkey
      'UA' => 'UA###########################', # Ukraine
      'AE' => 'AE#####################', # United Arab Emirates
      'GB' => 'GB##????##############', # United Kingdom
      'VG' => 'VG##????################' # Virgin Islands, British
    }.freeze

    def iban(country_code: nil)
      return formatify_iban(fetch_sample(COUNTRIES.values)) unless country_code

      check_country_existence(country_code)
      formatify_iban(COUNTRIES[country_code.upcase])
    end

    def card_number
      FFaker.numerify('#### #### #### ####')
    end

    def card_expiry_date(year_range: 5, year_latest: -5, format: '%m/%y')
      FFaker::Time.date({ year_range: year_range, year_latest: year_latest }).strftime(format)
    end

    def card_type
      fetch_sample(CARD_TYPES)
    end

    def loan_interest_rate(min_rate = 1.5, max_rate = 15.0)
      fetch_sample(min_rate..max_rate).round(2)
    end

    def loan_term
      fetch_sample([12, 24, 36, 48, 60, 72, 84])
    end

    def loan_amount(min_amount = 1_000, max_amount = 100_000)
      fetch_sample(min_amount..max_amount)
    end

    private

    def formatify_iban(code)
      FFaker.bothify(code).upcase
    end

    def check_country_existence(country_code)
      return if COUNTRIES.key?(country_code.upcase)

      raise ArgumentError, "Unexpected country code: '#{country_code}'"
    end
  end
end