Class: SecId::SEDOL
Overview
Constant Summary collapse
- ID_REGEX =
/\A (?<identifier>[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}) (?<check_digit>\d)? \z/x.freeze
- CHARACTER_WEIGHTS =
[1, 3, 1, 7, 3, 9].freeze
Instance Attribute Summary
Attributes inherited from Base
#check_digit, #full_number, #identifier
Instance Method Summary collapse
- #calculate_check_digit ⇒ Object
-
#initialize(sedol) ⇒ SEDOL
constructor
A new instance of SEDOL.
Methods inherited from Base
check_digit, restore!, #restore!, #to_s, valid?, #valid?, valid_format?, #valid_format?
Constructor Details
#initialize(sedol) ⇒ SEDOL
Returns a new instance of SEDOL.
13 14 15 16 17 |
# File 'lib/sec_id/sedol.rb', line 13 def initialize(sedol) sedol_parts = parse sedol @identifier = sedol_parts[:identifier] @check_digit = sedol_parts[:check_digit]&.to_i end |
Instance Method Details
#calculate_check_digit ⇒ Object
19 20 21 22 23 |
# File 'lib/sec_id/sedol.rb', line 19 def calculate_check_digit return mod_10(weighted_sum) if valid_format? raise InvalidFormatError, "SEDOL '#{full_number}' is invalid and check-digit cannot be calculated!" end |