Class: SecID::Scanner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sec_id/scanner.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.

Finds securities identifiers in freeform text using regex candidate extraction, length/charset pre-filtering, and cursor-based overlap prevention.

Constant Summary collapse

CANDIDATE_RE =

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

Composite regex for candidate extraction.

Three named groups tried left-to-right via alternation:

  • fisn: contains / (unique FISN delimiter)

  • occ: contains structural spaces + date/type pattern

  • simple: common alphanumeric tokens (covers all other types)

%r{
  (?<![A-Za-z0-9*@\#/.$])
  (?:
    (?<fisn>[A-Za-z0-9](?:[A-Za-z0-9 ]{0,33}[A-Za-z0-9])?/[A-Za-z0-9](?:[A-Za-z0-9 ]{0,33}[A-Za-z0-9])?)
    |
    (?<occ>[A-Za-z]{1,6}\ {1,5}\d{6}[CcPp]\d{8})
    |
    (?<simple>[A-Za-z0-9*@\#](?:[A-Za-z0-9*@\#-]{0,40}[A-Za-z0-9*@\#])?)
  )
  (?![A-Za-z0-9*@\#.])
}x

Instance Method Summary collapse

Constructor Details

#initialize(identifier_list) ⇒ Scanner

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 Scanner.

Parameters:

  • identifier_list (Array<Class>)

    registered identifier classes



31
32
33
34
# File 'lib/sec_id/scanner.rb', line 31

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

Instance Method Details

#call(text, classes: nil) {|match| ... } ⇒ Enumerator<Match>

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.

Scans text for identifiers, yielding or returning matches.

Parameters:

  • text (String, nil)

    the text to scan

  • classes (Array<Class>, nil) (defaults to: nil)

    restrict to specific classes

Yield Parameters:

Returns:

  • (Enumerator<Match>)

    if no block given



42
43
44
45
46
47
48
49
# File 'lib/sec_id/scanner.rb', line 42

def call(text, classes: nil, &block)
  return enum_for(:call, text, classes: classes) unless block

  input = text.to_s
  return if input.empty?

  scan_text(input, classes || @classes, &block)
end