Class: SecurityIdentifiers::SEDOL
- Defined in:
- lib/security_identifiers/sedol.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #check_digit ⇒ Object
-
#initialize(str) ⇒ SEDOL
constructor
A new instance of SEDOL.
- #to_isin(iso = 'GB') ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(str) ⇒ SEDOL
Returns a new instance of SEDOL.
5 6 7 8 9 10 11 12 13 |
# File 'lib/security_identifiers/sedol.rb', line 5 def initialize(str) raise InvalidFormat if str.nil? match_data = str.upcase.match(/^([A-Z0-9]{6})(\d{1})?$/) raise InvalidFormat if match_data.nil? @identifier, @original_check_digit = match_data.captures end |
Instance Method Details
#check_digit ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/security_identifiers/sedol.rb', line 15 def check_digit weights = [1, 3, 1, 7, 3, 9, 1] sum = 0 digits.each_with_index do |i, idx| sum += weights[idx] * i end (10 - sum % 10) % 10 end |
#to_isin(iso = 'GB') ⇒ Object
26 27 28 29 30 |
# File 'lib/security_identifiers/sedol.rb', line 26 def to_isin(iso='GB') raise InvalidConversion if !['GB', 'IE'].include?(iso) ISIN.new([iso, '00', @identifier, check_digit].join) end |