Class: SecID::FIGI
Overview
Financial Instrument Global Identifier (FIGI) - a 12-character alphanumeric code that uniquely identifies financial instruments.
Format: 2-character prefix + 'G' + 8-character random part + 1-digit check digit Note: FIGI excludes vowels (A, E, I, O, U) from valid characters.
Constant Summary collapse
- FULL_NAME =
Human-readable name of the standard.
'Financial Instrument Global Identifier'- ID_LENGTH =
Valid length(s) of a normalized identifier.
12- EXAMPLE =
A representative valid identifier.
'BBG000BLNNH6'- VALID_CHARS_REGEX =
Pattern matching the identifier's permitted character set.
/\A[B-DF-HJ-NP-TV-Z0-9]+\z/- ID_REGEX =
Regular expression for parsing FIGI components. The third character must be 'G'. Excludes vowels from valid characters.
/\A (?<identifier> (?<prefix>[B-DF-HJ-NP-TV-Z0-9]{2}) G (?<random_part>[B-DF-HJ-NP-TV-Z0-9]{8})) (?<check_digit>\d)? \z/x- RESTRICTED_PREFIXES =
Country-code prefixes that are restricted from use in FIGI.
Set.new %w[BS BM GG GB GH KY VG]
- GENERATE_CHARSET =
Characters valid in a FIGI (alphanumeric excluding vowels).
ALPHANUMERIC.grep(VALID_CHARS_REGEX).freeze
Constants included from Checkable
Checkable::CHAR_TO_DIGIT, Checkable::CHAR_TO_DIGITS
Constants included from Generatable
Generatable::ALPHA, Generatable::ALPHANUMERIC, Generatable::DIGITS
Constants included from Validatable
Constants included from Normalizable
Instance Attribute Summary collapse
-
#prefix ⇒ String?
readonly
The 2-character prefix.
-
#random_part ⇒ String?
readonly
The 8-character random part.
Attributes inherited from Base
Instance Method Summary collapse
-
#calculate_check_digit ⇒ Integer
The calculated check digit (0-9).
-
#initialize(figi) ⇒ FIGI
constructor
A new instance of FIGI.
- #to_pretty_s ⇒ String?
Methods included from Checkable
#restore, #restore!, #to_s, #valid?
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_s, #to_str
Constructor Details
#initialize(figi) ⇒ FIGI
Returns a new instance of FIGI.
52 53 54 55 56 57 58 |
# File 'lib/sec_id/figi.rb', line 52 def initialize(figi) figi_parts = parse figi @identifier = figi_parts[:identifier] @prefix = figi_parts[:prefix] @random_part = figi_parts[:random_part] @check_digit = figi_parts[:check_digit]&.to_i end |
Instance Attribute Details
#prefix ⇒ String? (readonly)
Returns the 2-character prefix.
46 47 48 |
# File 'lib/sec_id/figi.rb', line 46 def prefix @prefix end |
#random_part ⇒ String? (readonly)
Returns the 8-character random part.
49 50 51 |
# File 'lib/sec_id/figi.rb', line 49 def random_part @random_part end |
Instance Method Details
#calculate_check_digit ⇒ Integer
Returns the calculated check digit (0-9).
69 70 71 72 |
# File 'lib/sec_id/figi.rb', line 69 def calculate_check_digit validate_format_for_calculation! mod10(luhn_sum_indexed(reversed_digits_single(identifier))) end |
#to_pretty_s ⇒ String?
61 62 63 64 65 |
# File 'lib/sec_id/figi.rb', line 61 def to_pretty_s return nil unless valid? "#{prefix}G #{random_part} #{check_digit}" end |