Class: SecID::Valoren
Overview
Valoren identifiers have no check digit and validation is based solely on format.
Valoren (Swiss Security Number) - a numeric identifier for securities in Switzerland, Liechtenstein, and Belgium.
Format: 5-9 numeric digits
Constant Summary collapse
- FULL_NAME =
Human-readable name of the standard.
'Valoren Number'- ID_LENGTH =
Valid length(s) of a normalized identifier.
(5..9)
- EXAMPLE =
A representative valid identifier.
'3886335'- VALID_CHARS_REGEX =
Pattern matching the identifier's permitted character set.
/\A[0-9]+\z/- ID_REGEX =
Regular expression for parsing Valoren components.
/\A (?=\d{5,9}\z)(?<padding>0*)(?<identifier>[1-9]\d{4,8}) \z/x- ISIN_COUNTRY_CODES =
Valid country codes for Valoren to ISIN conversion.
Set.new(%w[CH LI]).freeze
Constants included from Generatable
Generatable::ALPHA, Generatable::ALPHANUMERIC, Generatable::DIGITS
Constants included from Validatable
Constants included from Normalizable
Instance Attribute Summary collapse
-
#padding ⇒ String?
readonly
The leading zeros in the Valoren.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(valoren) ⇒ Valoren
constructor
A new instance of Valoren.
- #normalize! ⇒ self
-
#normalized ⇒ String
The normalized 9-digit Valoren.
-
#to_isin(country_code = 'CH') ⇒ ISIN
A new ISIN instance with calculated check digit.
- #to_pretty_s ⇒ String?
- #to_s ⇒ String
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
Constructor Details
#initialize(valoren) ⇒ Valoren
Returns a new instance of Valoren.
41 42 43 44 45 |
# File 'lib/sec_id/valoren.rb', line 41 def initialize(valoren) valoren_parts = parse(valoren) @padding = valoren_parts[:padding] @identifier = valoren_parts[:identifier] end |
Instance Attribute Details
#padding ⇒ String? (readonly)
Returns the leading zeros in the Valoren.
38 39 40 |
# File 'lib/sec_id/valoren.rb', line 38 def padding @padding end |
Instance Method Details
#normalize! ⇒ self
74 75 76 77 78 |
# File 'lib/sec_id/valoren.rb', line 74 def normalize! super @padding = @full_id[0, self.class::ID_LENGTH.max - @identifier.length] self end |
#normalized ⇒ String
Returns the normalized 9-digit Valoren.
67 68 69 70 |
# File 'lib/sec_id/valoren.rb', line 67 def normalized validate! @identifier.rjust(self.class::ID_LENGTH.max, '0') end |
#to_isin(country_code = 'CH') ⇒ ISIN
Returns a new ISIN instance with calculated check digit.
57 58 59 60 61 62 63 |
# File 'lib/sec_id/valoren.rb', line 57 def to_isin(country_code = 'CH') unless ISIN_COUNTRY_CODES.include?(country_code) raise InvalidFormatError, "'#{country_code}' is not a valid Valoren country code!" end ISIN.new(country_code + normalized).restore! end |
#to_pretty_s ⇒ String?
48 49 50 51 52 |
# File 'lib/sec_id/valoren.rb', line 48 def to_pretty_s return nil unless valid? identifier.reverse.scan(/.{1,3}/).join(' ').reverse end |
#to_s ⇒ String
81 82 83 |
# File 'lib/sec_id/valoren.rb', line 81 def to_s full_id end |