Class: SecID::BIC
- Defined in:
- lib/sec_id/bic.rb,
lib/sec_id/bic/country_codes.rb
Overview
Business Identifier Code (BIC / SWIFT code) - an international standard for identifying financial and non-financial institutions (ISO 9362).
Format: 4-letter institution code + 2-letter country code + 2-alphanumeric location code, optionally followed by a 3-alphanumeric branch code (BIC8 or BIC11).
Validation confirms the structure and that the embedded country code is a real ISO 3166-1 / SWIFT-recognized country. It does not verify that the institution, location, or branch corresponds to a registered SWIFT participant — that requires the licensed SWIFT registry.
Constant Summary collapse
- FULL_NAME =
Human-readable name of the standard.
'Business Identifier Code'- ID_LENGTH =
Valid length(s) of a normalized identifier.
[8, 11].freeze
- EXAMPLE =
A representative valid identifier.
'DEUTDEFF500'- VALID_CHARS_REGEX =
Pattern matching the identifier's permitted character set.
/\A[A-Z0-9]+\z/- ID_REGEX =
Regular expression for parsing BIC components. The optional all-or-nothing branch code makes the length exactly 8 or 11.
/\A (?<bank_code>[A-Z]{4}) (?<country_code>[A-Z]{2}) (?<location_code>[A-Z0-9]{2}) (?<branch_code>[A-Z0-9]{3})? \z/x- COUNTRY_CODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Frozen set of country codes accepted in a BIC's positions 5-6.
The set is the ISO 3166-1 alpha-2 officially-assigned codes, extended with SWIFT-recognized codes that are not (yet) in ISO 3166-1 — currently
XK(Kosovo), which SWIFT assigns BICs under.rubocop:disable Metrics/CollectionLiteralLength
Set.new( %w[ AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW XK ] ).freeze
Constants included from Generatable
Generatable::ALPHA, Generatable::ALPHANUMERIC, Generatable::DIGITS
Constants included from Validatable
Constants included from Normalizable
Instance Attribute Summary collapse
-
#bank_code ⇒ String?
readonly
The 4-letter institution (bank) code.
-
#branch_code ⇒ String?
readonly
The 3-alphanumeric branch code, or nil for a BIC8.
-
#country_code ⇒ String?
readonly
The 2-letter ISO 3166-1 country code.
-
#location_code ⇒ String?
readonly
The 2-alphanumeric location code.
Attributes inherited from Base
Class Method Summary collapse
-
.countries ⇒ Array<String>
Returns the sorted array of all recognized country codes.
Instance Method Summary collapse
-
#initialize(bic) ⇒ BIC
constructor
A new instance of BIC.
Methods inherited from Base
#==, #as_json, example, full_name, has_check_digit?, #hash, id_length, length_specificity, length_values, short_name, #to_h
Methods included from Validatable
#errors, #valid?, #validate, #validate!
Methods included from Normalizable
#normalize!, #normalized, #to_pretty_s, #to_s, #to_str
Constructor Details
#initialize(bic) ⇒ BIC
Returns a new instance of BIC.
68 69 70 71 72 73 74 75 |
# File 'lib/sec_id/bic.rb', line 68 def initialize(bic) bic_parts = parse(bic) @bank_code = bic_parts[:bank_code] @country_code = bic_parts[:country_code] @location_code = bic_parts[:location_code] @branch_code = bic_parts[:branch_code] @identifier = "#{@bank_code}#{@country_code}#{@location_code}#{@branch_code}" if @bank_code end |
Instance Attribute Details
#bank_code ⇒ String? (readonly)
Returns the 4-letter institution (bank) code.
56 57 58 |
# File 'lib/sec_id/bic.rb', line 56 def bank_code @bank_code end |
#branch_code ⇒ String? (readonly)
Returns the 3-alphanumeric branch code, or nil for a BIC8.
65 66 67 |
# File 'lib/sec_id/bic.rb', line 65 def branch_code @branch_code end |
#country_code ⇒ String? (readonly)
Returns the 2-letter ISO 3166-1 country code.
59 60 61 |
# File 'lib/sec_id/bic.rb', line 59 def country_code @country_code end |
#location_code ⇒ String? (readonly)
Returns the 2-alphanumeric location code.
62 63 64 |
# File 'lib/sec_id/bic.rb', line 62 def location_code @location_code end |
Class Method Details
.countries ⇒ Array<String>
Returns the sorted array of all recognized country codes.
51 52 53 |
# File 'lib/sec_id/bic.rb', line 51 def self.countries @countries ||= COUNTRY_CODES.to_a.sort.freeze end |