Class: SecurityIdentifiers::SEDOL
- Defined in:
- lib/security_identifiers/sedol.rb
Constant Summary collapse
- WEIGHTS =
[1, 3, 1, 7, 3, 9, 1].freeze
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 14 15 |
# 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 fix! if @original_check_digit.nil? end |
Instance Method Details
#check_digit ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/security_identifiers/sedol.rb', line 17 def check_digit sum = digits.each_with_index.inject(0) do |result, (i, idx)| result + WEIGHTS[idx] * i end mod_10(sum) end |
#to_isin(iso = 'GB') ⇒ Object
25 26 27 28 29 |
# File 'lib/security_identifiers/sedol.rb', line 25 def to_isin(iso = 'GB') raise InvalidConversion unless %w(GB IE).include?(iso) ISIN.new([iso, '00', @identifier, check_digit].join) end |