Class: SecID::FIGI

Inherits:
Base
  • Object
show all
Includes:
Checkable
Defined in:
lib/sec_id/figi.rb

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.

Examples:

Validate a FIGI

SecID::FIGI.valid?('BBG000BLNQ16')  #=> true

Restore check digit

SecID::FIGI.restore!('BBG000BLNQ1')  #=> #<SecID::FIGI>

See Also:

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

Validatable::ERROR_MAP

Constants included from Normalizable

Normalizable::SEPARATORS

Instance Attribute Summary collapse

Attributes inherited from Base

#full_id, #identifier

Instance Method Summary collapse

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.

Parameters:

  • figi (String)

    the FIGI string to parse



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

#prefixString? (readonly)

Returns the 2-character prefix.

Returns:

  • (String, nil)

    the 2-character prefix



46
47
48
# File 'lib/sec_id/figi.rb', line 46

def prefix
  @prefix
end

#random_partString? (readonly)

Returns the 8-character random part.

Returns:

  • (String, nil)

    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_digitInteger

Returns the calculated check digit (0-9).

Returns:

  • (Integer)

    the calculated check digit (0-9)

Raises:



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_sString?

Returns:

  • (String, nil)


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