Module: Gnucash::ISIN

Defined in:
lib/gnucash/isin.rb

Overview

Helpers for ISIN (ISO 6166) strings as stored on GnuCash commodities.

Since:

  • 1.6.0

Class Method Summary collapse

Class Method Details

.normalize(str) ⇒ String

Returns Uppercase ISIN with spaces and hyphens removed.

Parameters:

  • str (String, nil)

Returns:

  • (String)

    Uppercase ISIN with spaces and hyphens removed.

Since:

  • 1.6.0



10
11
12
13
# File 'lib/gnucash/isin.rb', line 10

def normalize(str)
  return "" if str.nil? || str.to_s.empty?
  str.to_s.gsub(/[\s-]/, "").upcase
end

.valid_format?(str) ⇒ Boolean

Rough format check: 12 alphanumeric characters after normalization.

Parameters:

  • str (String, nil)

Returns:

  • (Boolean)

Since:

  • 1.6.0



19
20
21
22
23
# File 'lib/gnucash/isin.rb', line 19

def valid_format?(str)
  s = normalize(str)
  return false if s.length != 12
  s.match?(/\A[A-Z0-9]{12}\z/)
end