Class: SecID::CEI

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

Overview

CUSIP Entity Identifier (CEI) - a 10-character alphanumeric code that identifies legal entities in the syndicated loan market.

Format: 1 alpha + 1 digit + 7 alphanumeric + 1 check digit

Examples:

Validate a CEI

SecID::CEI.valid?('A0BCDEFGH1')  #=> true

See Also:

Constant Summary collapse

FULL_NAME =

Human-readable name of the standard.

'CUSIP Entity Identifier'
ID_LENGTH =

Valid length(s) of a normalized identifier.

10
EXAMPLE =

A representative valid identifier.

'A0BCDEFGH1'
VALID_CHARS_REGEX =

Pattern matching the identifier's permitted character set.

/\A[A-Z0-9]+\z/
ID_REGEX =

Regular expression for parsing CEI components.

/\A
  (?<identifier>
    (?<prefix>[A-Z])
    (?<numeric>[0-9])
    (?<entity_id>[A-Z0-9]{7}))
  (?<check_digit>\d)?
\z/x

Constants included from Checkable

SecID::Checkable::CHAR_TO_DIGIT, SecID::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_pretty_s, #to_s, #to_str

Constructor Details

#initialize(cei) ⇒ CEI

Returns a new instance of CEI.

Parameters:

  • cei (String)

    the CEI string to parse



44
45
46
47
48
49
50
51
# File 'lib/sec_id/cei.rb', line 44

def initialize(cei)
  cei_parts = parse cei
  @identifier = cei_parts[:identifier]
  @prefix = cei_parts[:prefix]
  @numeric = cei_parts[:numeric]
  @entity_id = cei_parts[:entity_id]
  @check_digit = cei_parts[:check_digit]&.to_i
end

Instance Attribute Details

#entity_idString? (readonly)

Returns the 7-character entity identifier.

Returns:

  • (String, nil)

    the 7-character entity identifier



41
42
43
# File 'lib/sec_id/cei.rb', line 41

def entity_id
  @entity_id
end

#numericString? (readonly)

Returns the second character (numeric).

Returns:

  • (String, nil)

    the second character (numeric)



38
39
40
# File 'lib/sec_id/cei.rb', line 38

def numeric
  @numeric
end

#prefixString? (readonly)

Returns the first character (alphabetic).

Returns:

  • (String, nil)

    the first character (alphabetic)



35
36
37
# File 'lib/sec_id/cei.rb', line 35

def prefix
  @prefix
end

Instance Method Details

#calculate_check_digitInteger

Returns the calculated check digit (0-9).

Returns:

  • (Integer)

    the calculated check digit (0-9)

Raises:



55
56
57
58
# File 'lib/sec_id/cei.rb', line 55

def calculate_check_digit
  validate_format_for_calculation!
  mod10(luhn_sum_double_add_double(reversed_digits_single(identifier)))
end