Class: SecurityIdentifiers::ISIN
- Defined in:
- lib/security_identifiers/isin.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #check_digit ⇒ Object
-
#initialize(str) ⇒ ISIN
constructor
A new instance of ISIN.
Methods inherited from Base
Constructor Details
#initialize(str) ⇒ ISIN
Returns a new instance of ISIN.
5 6 7 8 9 10 11 12 13 |
# File 'lib/security_identifiers/isin.rb', line 5 def initialize(str) raise InvalidFormat if str.nil? match_data = str.upcase.match(/^(([A-Z]{2})([A-Z0-9]{9}))(\d{1})?$/) raise InvalidFormat if match_data.nil? @identifier, @country_code, @nsin, @original_check_digit = match_data.captures end |
Instance Method Details
#check_digit ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/security_identifiers/isin.rb', line 15 def check_digit longest, shortest = if even_values.last == digits.last [even_values, odd_values] else [odd_values, even_values] end longest = longest.map { |i| i * 2 } values = (longest.concat(shortest)).to_s.scan(/./).map(&:to_i) sum = values.inject(&:+) (10 - (sum % 10)) % 10 end |