Class: SecId::Base
- Inherits:
-
Object
- Object
- SecId::Base
- Defined in:
- lib/sec_id/base.rb
Overview
Base class for securities identifiers that provides a common interface for validation 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.
Instance Attribute Summary collapse
-
#full_number ⇒ String
readonly
The original input after normalization (stripped and uppercased).
-
#identifier ⇒ String?
readonly
The main identifier portion (without check digit).
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(_sec_id_number) ⇒ Base
constructor
Subclasses must override this method.
- #to_s ⇒ String (also: #to_str)
- #valid? ⇒ Boolean
-
#valid_format? ⇒ Boolean
Override in subclasses for additional format validation.
Constructor Details
#initialize(_sec_id_number) ⇒ Base
Subclasses must override this method.
66 67 68 |
# File 'lib/sec_id/base.rb', line 66 def initialize(_sec_id_number) raise NotImplementedError end |
Instance Attribute Details
#full_number ⇒ String (readonly)
Returns the original input after normalization (stripped and uppercased).
43 44 45 |
# File 'lib/sec_id/base.rb', line 43 def full_number @full_number end |
#identifier ⇒ String? (readonly)
Returns the main identifier portion (without check digit).
46 47 48 |
# File 'lib/sec_id/base.rb', line 46 def identifier @identifier end |
Class Method Details
.valid?(id) ⇒ Boolean
51 52 53 |
# File 'lib/sec_id/base.rb', line 51 def valid?(id) new(id).valid? end |
.valid_format?(id) ⇒ Boolean
57 58 59 |
# File 'lib/sec_id/base.rb', line 57 def valid_format?(id) new(id).valid_format? end |
Instance Method Details
#to_s ⇒ String Also known as: to_str
83 84 85 |
# File 'lib/sec_id/base.rb', line 83 def to_s identifier.to_s end |
#valid? ⇒ Boolean
71 72 73 |
# File 'lib/sec_id/base.rb', line 71 def valid? valid_format? end |
#valid_format? ⇒ Boolean
Override in subclasses for additional format validation.
78 79 80 |
# File 'lib/sec_id/base.rb', line 78 def valid_format? !identifier.nil? end |