Class: Synthra::Types::FinanceBanking::Iban
- Defined in:
- lib/synthra/types/finance_banking/banking.rb
Overview
Iban type
Constant Summary collapse
- IBAN_FORMATS =
IBAN format specifications by country
Maps country codes to their IBAN format specifications including country code and total length.
{ gb: { code: "GB", length: 22 }, de: { code: "DE", length: 22 }, fr: { code: "FR", length: 27 }, it: { code: "IT", length: 27 }, es: { code: "ES", length: 24 }, nl: { code: "NL", length: 18 }, be: { code: "BE", length: 16 }, us: { code: "US", length: 22 } # Not standard, but sometimes used }.freeze
Instance Method Summary collapse
- #generate_edge(rng, context, args) ⇒ Object
- #generate_invalid(rng, context, args) ⇒ Object
-
#generate_random(rng, context, args) ⇒ String
Generate random IBAN.
Instance Method Details
#generate_edge(rng, context, args) ⇒ Object
310 311 312 |
# File 'lib/synthra/types/finance_banking/banking.rb', line 310 def generate_edge(rng, context, args) ["GB00000000000000000000", "DE00000000000000000000"].sample(random: rng.instance_variable_get(:@random)) end |
#generate_invalid(rng, context, args) ⇒ Object
314 315 316 |
# File 'lib/synthra/types/finance_banking/banking.rb', line 314 def generate_invalid(rng, context, args) [nil, "invalid", "123", [], {}].sample(random: rng.instance_variable_get(:@random)) end |
#generate_random(rng, context, args) ⇒ String
Generate random IBAN
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/synthra/types/finance_banking/banking.rb', line 292 def generate_random(rng, context, args) country = (args[:country] || :gb).to_sym format = IBAN_FORMATS[country] || IBAN_FORMATS[:gb] country_code = format[:code] length = format[:length] # Generate check digits (2 digits) check_digits = format("%02d", rng.int(0, 99)) # Generate BBAN (Basic Bank Account Number) - alphanumeric bban_length = length - 4 # -4 for country code and check digits chars = ("A".."Z").to_a + ("0".."9").to_a bban = bban_length.times.map { rng.sample(chars) }.join "#{country_code}#{check_digits}#{bban}" end |