Module: Gnucash::ISIN
- Defined in:
- lib/gnucash/isin.rb
Overview
Helpers for ISIN (ISO 6166) strings as stored on GnuCash commodities.
Class Method Summary collapse
-
.normalize(str) ⇒ String
Uppercase ISIN with spaces and hyphens removed.
-
.valid_format?(str) ⇒ Boolean
Rough format check: 12 alphanumeric characters after normalization.
Class Method Details
.normalize(str) ⇒ String
Returns Uppercase ISIN with spaces and hyphens removed.
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.
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 |