Class: SecID::Base
- Inherits:
-
Object
- Object
- SecID::Base
- Includes:
- IdentifierMetadata, Normalizable, Validatable
- Defined in:
- lib/sec_id/base.rb
Overview
Base class for securities identifiers that provides a common interface for validation, normalization, and parsing.
Subclasses must implement:
-
ID_REGEX constant with named capture groups for parsing
-
initialize method that calls parse and extracts components
Subclasses with check digits should also include the Checkable concern, which provides check-digit validation, calculation, and restoration.
Constant Summary
Constants included from Validatable
Constants included from Normalizable
Instance Attribute Summary collapse
-
#full_id ⇒ String
readonly
The original input after normalization (stripped and uppercased).
-
#identifier ⇒ String?
readonly
The main identifier portion (without check digit).
Class Method Summary collapse
- .inherited(subclass) ⇒ Object private
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
-
#as_json ⇒ Hash
Returns a JSON-compatible hash representation.
- #hash ⇒ Integer
-
#initialize(_sec_id_number) ⇒ Base
constructor
Subclasses must override this method.
-
#to_h ⇒ Hash
Returns a hash representation of this identifier for serialization.
Methods included from Validatable
#errors, included, #valid?, #validate, #validate!
Methods included from Normalizable
included, #normalize!, #normalized, #to_pretty_s, #to_s, #to_str
Methods included from IdentifierMetadata
Constructor Details
#initialize(_sec_id_number) ⇒ Base
Subclasses must override this method.
63 64 65 |
# File 'lib/sec_id/base.rb', line 63 def initialize(_sec_id_number) raise NotImplementedError end |
Instance Attribute Details
#full_id ⇒ String (readonly)
Returns the original input after normalization (stripped and uppercased).
47 48 49 |
# File 'lib/sec_id/base.rb', line 47 def full_id @full_id end |
#identifier ⇒ String? (readonly)
Returns the main identifier portion (without check digit).
50 51 52 |
# File 'lib/sec_id/base.rb', line 50 def identifier @identifier end |
Class Method Details
.inherited(subclass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 |
# File 'lib/sec_id/base.rb', line 53 def self.inherited(subclass) super # Skip anonymous classes and classes outside the SecID namespace (e.g. in tests) SecID.__send__(:register_identifier, subclass) if subclass.name&.start_with?('SecID::') end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
69 70 71 |
# File 'lib/sec_id/base.rb', line 69 def ==(other) other.class == self.class && comparison_id == other.comparison_id end |
#as_json ⇒ Hash
Returns a JSON-compatible hash representation.
96 97 98 |
# File 'lib/sec_id/base.rb', line 96 def as_json(*) to_h end |
#hash ⇒ Integer
76 77 78 |
# File 'lib/sec_id/base.rb', line 76 def hash [self.class, comparison_id].hash end |
#to_h ⇒ Hash
Returns a hash representation of this identifier for serialization.
83 84 85 86 87 88 89 90 91 |
# File 'lib/sec_id/base.rb', line 83 def to_h { type: self.class.short_name.downcase.to_sym, full_id: full_id, normalized: valid? ? normalized : nil, valid: valid?, components: components } end |