Module: SecID::Generatable

Included in:
Base
Defined in:
lib/sec_id/concerns/generatable.rb

Overview

Note:

Generated identifiers are valid in format only — they are not real, registered securities. Country codes, prefixes, dates, and attributes are random.

Provides generation of new, format-valid identifiers for use as test fixtures.

Including classes define a class-level generate_body(random) returning a valid body (the identifier without its check digit). The default ClassMethods#generate builds an instance from that body and restores the check digit for check-digit types. Types whose shape is not "body (+ check digit)" compose the full identifier in generate_body (CFI, FISN) or override generate entirely (OCC).

Examples:

Generate a fixture

SecID::ISIN.generate           #=> #<SecID::ISIN ...> (valid?)
SecID::ISIN.generate.valid?    #=> true

Reproducible output via a seeded Random

SecID::ISIN.generate(random: Random.new(42)) == SecID::ISIN.generate(random: Random.new(42))

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

ALPHA =

Uppercase letters A-Z.

('A'..'Z').to_a.freeze
DIGITS =

Decimal digits 0-9.

('0'..'9').to_a.freeze
ALPHANUMERIC =

Alphanumeric characters (digits then uppercase letters).

(DIGITS + ALPHA).freeze