Class: SecID::UPI
- 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.
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
Constants included from Normalizable
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#calculate_checksum ⇒ String
The calculated check character.
-
#initialize(upi) ⇒ UPI
constructor
A new instance of UPI.
Methods included from Suggestable
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.
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_checksum ⇒ String
Returns the calculated check character.
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 |