class SecId::SEDOL
Constants
- CHARACTER_WEIGHTS
- ID_REGEX
Public Class Methods
new(sedol)
click to toggle source
# 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
Public Instance Methods
calculate_check_digit()
click to toggle source
# 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
Private Instance Methods
id_digits()
click to toggle source
# File lib/sec_id/sedol.rb, line 40 def id_digits @id_digits ||= identifier.each_char.map(&method(:char_to_digit)) end
weighted_sum()
click to toggle source
NOTE: I know this isn't the most idiomatic Ruby code, but it's the fastest one
# File lib/sec_id/sedol.rb, line 28 def weighted_sum index = 0 sum = 0 while index < id_digits.size sum += id_digits[index] * CHARACTER_WEIGHTS[index] index += 1 end sum end