Class: SecurityIdentifiers::SEDOL

Inherits:
Base
  • Object
show all
Defined in:
lib/security_identifiers/sedol.rb

Instance Attribute Summary

Attributes inherited from Base

#original_check_digit

Instance Method Summary collapse

Methods inherited from Base

#fix!, #to_s, #valid?

Constructor Details

#initialize(str) ⇒ SEDOL

Returns a new instance of SEDOL.

Raises:



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_digitObject



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

Raises:



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