Class: SecID::UPI

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

Overview

Unique Product Identifier (UPI, ISO 4914) - a 12-character code that identifies OTC derivative products for regulatory reporting, issued by the ANNA Derivatives Service Bureau.

Format: fixed 'QZ' prefix + 9-character body + 1 check character, drawn from a 30-symbol alphabet (digits 0-9 plus consonants; vowels and 'Y' never appear). Validated fully offline via ISO 7064 hybrid MOD 31,30 over the 11 preceding characters.

Examples:

Validate a UPI

SecID::UPI.valid?('QZRBG6ZTKS42')  #=> true

Restore check character

SecID::UPI.restore('QZRBG6ZTKS4')  #=> 'QZRBG6ZTKS42'

See Also:

Constant Summary collapse

FULL_NAME =

Human-readable name of the standard.

'Unique Product Identifier'
ID_LENGTH =

Valid length of a normalized identifier.

12
EXAMPLE =

A representative valid identifier.

'QZRBG6ZTKS42'
VALID_CHARS_REGEX =

Pattern matching the identifier's permitted character set (digits + consonants, no vowels/Y).

/\A[0-9B-DF-HJ-NP-TV-XZ]+\z/
ID_REGEX =

Regular expression for parsing UPI components: fixed 'QZ' prefix, 9-character body, optional check character.

/\A
  (?<identifier>QZ[0-9B-DF-HJ-NP-TV-XZ]{9})
  (?<checksum>[0-9B-DF-HJ-NP-TV-XZ])?
\z/x
ALPHABET =

The 30-symbol UPI alphabet, ordered by check-character value (0-29).

'0123456789BCDFGHJKLMNPQRSTVWXZ'.chars.freeze
ALPHABET_VALUE =

Maps each alphabet character to its check-character value (0-29).

ALPHABET.each_with_index.to_h.freeze
GENERATE_CHARSET =

Characters valid in a UPI body (same alphabet as VALID_CHARS_REGEX).

ALPHANUMERIC.grep(VALID_CHARS_REGEX).freeze

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

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_pretty_s, #to_s, #to_str

Constructor Details

#initialize(upi) ⇒ UPI

Returns a new instance of UPI.

Parameters:

  • upi (String)

    the UPI string to parse



49
50
51
52
53
# File 'lib/sec_id/upi.rb', line 49

def initialize(upi)
  upi_parts = parse upi
  @identifier = upi_parts[:identifier]
  @checksum = upi_parts[:checksum]
end

Instance Method Details

#calculate_checksumString

Returns the calculated check character.

Returns:

  • (String)

    the calculated check character

Raises:



57
58
59
60
# File 'lib/sec_id/upi.rb', line 57

def calculate_checksum
  validate_format_for_calculation!
  mod31_30_check_char(identifier, ALPHABET, ALPHABET_VALUE)
end