Class: SecID::Detector Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Detects which identifier types match a given string using a three-stage pipeline that eliminates most candidates before calling valid?.

Stage 1 — Special-character dispatch (O(1)):

Strings containing `/`, ` `, or `*@#` route to the only types accepting those chars.

Stage 2 — Length lookup (O(1) hash access):

Pre-computed table maps each possible length to candidate classes.

Stage 3 — Charset pre-filter:

Survivors are filtered by their VALID_CHARS_REGEX before calling `valid?`.

Typical result: 1-2 valid? calls instead of 13.

Instance Method Summary collapse

Constructor Details

#initialize(identifier_list) ⇒ Detector

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.

Returns a new instance of Detector.

Parameters:

  • identifier_list (Array<Class>)

    registered identifier classes



21
22
23
24
# File 'lib/sec_id/detector.rb', line 21

def initialize(identifier_list)
  @classes = identifier_list.dup.freeze
  precompute
end

Instance Method Details

#call(str) ⇒ Array<Symbol>

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.

Detects all matching identifier types for the given string.

Parameters:

  • str (String, nil)

    the identifier string to detect

Returns:

  • (Array<Symbol>)

    matching type symbols sorted by specificity



30
31
32
33
34
35
36
37
# File 'lib/sec_id/detector.rb', line 30

def call(str)
  input = str.to_s.strip
  return [] if input.empty?

  upcased = input.upcase
  candidates = filter_candidates(upcased)
  validate_and_sort(input, candidates)
end