Class: SecID::LEI

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

Overview

Legal Entity Identifier (LEI) - a 20-character alphanumeric code that uniquely identifies legal entities participating in financial transactions.

Format: 4-character LOU ID + 2-character reserved + 12-character entity ID + 2-digit checksum

Examples:

Validate a LEI

SecID::LEI.valid?('529900T8BM49AURSDO55')  #=> true

Calculate checksum

SecID::LEI.checksum('529900T8BM49AURSDO')  #=> 55

See Also:

Constant Summary collapse

FULL_NAME =

Human-readable name of the standard.

'Legal Entity Identifier'
ID_LENGTH =

Valid length(s) of a normalized identifier.

20
EXAMPLE =

A representative valid identifier.

'7LTWFZYICNSX8D621K86'
VALID_CHARS_REGEX =

Pattern matching the identifier's permitted character set.

/\A[0-9A-Z]+\z/
ID_REGEX =

Regular expression for parsing LEI components.

/\A
  (?<identifier>
    (?<lou_id>[0-9A-Z]{4})
    (?<reserved>[0-9A-Z]{2})
    (?<entity_id>[0-9A-Z]{12}))
  (?<checksum>\d{2})?
\z/x

Constants included from Suggestable

Suggestable::HOMOGLYPHS, Suggestable::RANK

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 Suggestable

#suggest

Methods included from Checkable

#calculate_check_digit, #check_digit, #restore, #restore!, #to_s, #valid?

Methods inherited from Base

#==, #as_json, #deconstruct_keys, detection_priority, example, full_name, has_check_digit?, has_checksum?, #hash, id_length, length_specificity, length_values, short_name, #to_h, type_key

Methods included from Validatable

#errors, #valid?, #validate, #validate!

Methods included from Normalizable

#normalize!, #normalized, #to_s, #to_str

Constructor Details

#initialize(lei) ⇒ LEI

Returns a new instance of LEI.

Parameters:

  • lei (String)

    the LEI string to parse



49
50
51
52
53
54
55
56
# File 'lib/sec_id/lei.rb', line 49

def initialize(lei)
  lei_parts = parse lei
  @identifier = lei_parts[:identifier]
  @lou_id = lei_parts[:lou_id]
  @reserved = lei_parts[:reserved]
  @entity_id = lei_parts[:entity_id]
  @checksum = lei_parts[:checksum]&.to_i
end

Instance Attribute Details

#entity_idString? (readonly)

Returns the 12-character entity-specific identifier.

Returns:

  • (String, nil)

    the 12-character entity-specific identifier



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

def entity_id
  @entity_id
end

#lou_idString? (readonly)

Returns the 4-character Local Operating Unit (LOU) identifier.

Returns:

  • (String, nil)

    the 4-character Local Operating Unit (LOU) identifier



40
41
42
# File 'lib/sec_id/lei.rb', line 40

def lou_id
  @lou_id
end

#reservedString? (readonly)

Returns the 2-character reserved field (typically '00').

Returns:

  • (String, nil)

    the 2-character reserved field (typically '00')



43
44
45
# File 'lib/sec_id/lei.rb', line 43

def reserved
  @reserved
end

Instance Method Details

#calculate_checksumInteger

Returns the calculated 2-digit checksum (1-98).

Returns:

  • (Integer)

    the calculated 2-digit checksum (1-98)

Raises:



67
68
69
70
# File 'lib/sec_id/lei.rb', line 67

def calculate_checksum
  validate_format_for_calculation!
  mod97("#{numeric_identifier}00")
end

#to_pretty_sString?

Returns:

  • (String, nil)


59
60
61
62
63
# File 'lib/sec_id/lei.rb', line 59

def to_pretty_s
  return nil unless valid?

  to_s.scan(/.{1,4}/).join(' ')
end