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.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/security_identifiers/isin.rb', line 3 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 fix! if @original_check_digit.nil? end |
Instance Method Details
#check_digit ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/security_identifiers/isin.rb', line 15 def check_digit @check_digit ||= begin first_group = digit_groups[0].map { |d| d * 2 } second_group = digit_groups[1] sum = (first_group + second_group).join.each_char.inject(0) { |result, i| result + i.to_i } mod_10(sum) end end |