Class: SecId::CUSIP
Overview
Constant Summary collapse
- ID_REGEX =
/\A (?<identifier> (?<cusip6>[A-Z0-9]{5}[A-Z0-9*@#]) (?<issue>[A-Z0-9*@#]{2})) (?<check_digit>\d)? \z/x.freeze
Constants inherited from Base
Base::CHAR_TO_DIGIT, Base::CHAR_TO_DIGITS
Instance Attribute Summary collapse
-
#cusip6 ⇒ Object
readonly
Returns the value of attribute cusip6.
-
#issue ⇒ Object
readonly
Returns the value of attribute issue.
Attributes inherited from Base
#check_digit, #full_number, #identifier
Instance Method Summary collapse
- #calculate_check_digit ⇒ Object
-
#initialize(cusip) ⇒ CUSIP
constructor
A new instance of CUSIP.
Methods inherited from Base
check_digit, restore!, #restore!, #to_s, valid?, #valid?, valid_format?, #valid_format?
Constructor Details
#initialize(cusip) ⇒ CUSIP
Returns a new instance of CUSIP.
15 16 17 18 19 20 21 |
# File 'lib/sec_id/cusip.rb', line 15 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 ⇒ Object (readonly)
Returns the value of attribute cusip6.
13 14 15 |
# File 'lib/sec_id/cusip.rb', line 13 def cusip6 @cusip6 end |
#issue ⇒ Object (readonly)
Returns the value of attribute issue.
13 14 15 |
# File 'lib/sec_id/cusip.rb', line 13 def issue @issue end |
Instance Method Details
#calculate_check_digit ⇒ Object
23 24 25 26 27 |
# File 'lib/sec_id/cusip.rb', line 23 def calculate_check_digit return mod_10(modified_luhn_sum) if valid_format? raise InvalidFormatError, "CUSIP '#{full_number}' is invalid and check-digit cannot be calculated!" end |