Class: SecId::CUSIP
Overview
Committee on Uniform Securities Identification Procedures (CUSIP) - a 9-character alphanumeric code that identifies North American securities.
Format: 6-character issuer code (CUSIP-6) + 2-character issue number + 1-digit check digit
Constant Summary collapse
- ID_REGEX =
Regular expression for parsing CUSIP components.
/\A (?<identifier> (?<cusip6>[A-Z0-9]{5}[A-Z0-9*@#]) (?<issue>[A-Z0-9*@#]{2})) (?<check_digit>\d)? \z/x
Instance Attribute Summary collapse
-
#cusip6 ⇒ String?
readonly
The 6-character issuer code.
-
#issue ⇒ String?
readonly
The 2-character issue number.
Attributes inherited from Base
#check_digit, #full_number, #identifier
Instance Method Summary collapse
-
#calculate_check_digit ⇒ Integer
The calculated check digit (0-9).
-
#cins? ⇒ Boolean
True if first character is a letter (CINS identifier).
-
#initialize(cusip) ⇒ CUSIP
constructor
A new instance of CUSIP.
-
#to_isin(country_code) ⇒ ISIN
A new ISIN instance.
Methods inherited from Base
check_digit, #has_check_digit?, restore!, #restore!, #to_s, valid?, #valid?, #valid_format?, valid_format?
Constructor Details
#initialize(cusip) ⇒ CUSIP
33 34 35 36 37 38 39 |
# File 'lib/sec_id/cusip.rb', line 33 def initialize(cusip) cusip_parts = parse cusip @identifier = cusip_parts[:identifier] @cusip6 = cusip_parts[:cusip6] @issue = cusip_parts[:issue] @check_digit = cusip_parts[:check_digit]&.to_i end |
Instance Attribute Details
#cusip6 ⇒ String? (readonly)
27 28 29 |
# File 'lib/sec_id/cusip.rb', line 27 def cusip6 @cusip6 end |
#issue ⇒ String? (readonly)
30 31 32 |
# File 'lib/sec_id/cusip.rb', line 30 def issue @issue end |
Instance Method Details
#calculate_check_digit ⇒ Integer
Returns the calculated check digit (0-9).
43 44 45 46 |
# File 'lib/sec_id/cusip.rb', line 43 def calculate_check_digit validate_format_for_calculation! mod10(modified_luhn_sum) end |
#cins? ⇒ Boolean
63 64 65 |
# File 'lib/sec_id/cusip.rb', line 63 def cins? cusip6[0] < '0' || cusip6[0] > '9' end |
#to_isin(country_code) ⇒ ISIN
Returns a new ISIN instance.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sec_id/cusip.rb', line 51 def to_isin(country_code) unless ISIN::CGS_COUNTRY_CODES.include?(country_code) raise(InvalidFormatError, "'#{country_code}' is not a CGS country code!") end restore! isin = ISIN.new(country_code + full_number) isin.restore! isin end |