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
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
-
#cins? ⇒ Boolean
CUSIP International Numbering System.
-
#initialize(cusip) ⇒ CUSIP
constructor
A new instance of CUSIP.
- #to_isin(country_code) ⇒ Object
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 28 29 |
# File 'lib/sec_id/cusip.rb', line 23 def calculate_check_digit unless valid_format? raise InvalidFormatError, "CUSIP '#{full_number}' is invalid and check-digit cannot be calculated!" end mod10(modified_luhn_sum) end |
#cins? ⇒ Boolean
CUSIP International Numbering System
43 44 45 |
# File 'lib/sec_id/cusip.rb', line 43 def cins? cusip6[0] < '0' || cusip6[0] > '9' end |
#to_isin(country_code) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sec_id/cusip.rb', line 31 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 |