Class: SecID::WKN

Inherits:
Base
  • Object
show all
Defined in:
lib/sec_id/wkn.rb

Overview

Wertpapierkennnummer (WKN) - a 6-character alphanumeric code used to identify securities in Germany.

Format: 6 alphanumeric characters (excluding I and O) Note: WKN excludes letters I and O to avoid confusion with 1 and 0.

Examples:

Validate a WKN

SecID::WKN.valid?('514000')  #=> true
SecID::WKN.valid?('CBK100')  #=> true

See Also:

Constant Summary collapse

FULL_NAME =

Human-readable name of the standard.

'Wertpapierkennnummer'
ID_LENGTH =

Valid length(s) of a normalized identifier.

6
EXAMPLE =

A representative valid identifier.

'514000'
VALID_CHARS_REGEX =

Pattern matching the identifier's permitted character set.

/\A[0-9A-HJ-NP-Z]+\z/
ID_REGEX =

Regular expression for parsing WKN components. Excludes letters I and O to avoid confusion with 1 and 0.

/\A
  (?<identifier>[0-9A-HJ-NP-Z]{6})
\z/x
GENERATE_CHARSET =

Characters valid in a WKN (alphanumeric excluding I and O).

ALPHANUMERIC.grep(VALID_CHARS_REGEX).freeze

Constants included from Generatable

Generatable::ALPHA, Generatable::ALPHANUMERIC, Generatable::DIGITS

Constants included from Validatable

Validatable::ERROR_MAP

Constants included from Normalizable

Normalizable::SEPARATORS

Instance Attribute Summary

Attributes inherited from Base

#full_id, #identifier

Instance Method Summary collapse

Methods inherited from Base

#==, #as_json, example, full_name, has_check_digit?, #hash, id_length, length_specificity, length_values, short_name, #to_h

Methods included from Validatable

#errors, #valid?, #validate, #validate!

Methods included from Normalizable

#normalize!, #normalized, #to_pretty_s, #to_s, #to_str

Constructor Details

#initialize(wkn) ⇒ WKN

Returns a new instance of WKN.

Parameters:

  • wkn (String)

    the WKN string to parse



35
36
37
38
# File 'lib/sec_id/wkn.rb', line 35

def initialize(wkn)
  wkn_parts = parse(wkn)
  @identifier = wkn_parts[:identifier]
end

Instance Method Details

#to_isin(country_code = 'DE') ⇒ ISIN

Returns a new ISIN instance with calculated check digit.

Parameters:

  • country_code (String) (defaults to: 'DE')

    the ISO 3166-1 alpha-2 country code (default: 'DE')

Returns:

  • (ISIN)

    a new ISIN instance with calculated check digit

Raises:



44
45
46
47
48
49
# File 'lib/sec_id/wkn.rb', line 44

def to_isin(country_code = 'DE')
  raise InvalidFormatError, "'#{country_code}' is not a valid WKN country code!" unless country_code == 'DE'
  raise InvalidFormatError, "WKN '#{full_id}' is invalid!" unless valid_format?

  ISIN.new("#{country_code}000#{identifier}").restore!
end