Class: GovCodes::Dafecd::RiSdi::SdiCardParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gov_codes/dafecd/ri_sdi/sdi_card_parser.rb

Overview

Parses ONE "SDI card" record block into per-code entries.

A card block is a run of one or more "SDI " anchor lines followed by a shared body: a title (on its own line, or inline after the code), a change-date annotation, numbered sections, and (occasionally) a "Specialty Shredouts" table. Enlisted codes are 5 chars ("8A200"); officer codes are 4 ("80C0"); the shape is supplied by the injected Config.

A multi-code block (e.g. the Air Advisor codes 8L100/8L200/8L300, each with its own inline title but one shared body) yields one entry per code.

A wrapped-prose false positive — an "SDI ," anchor whose inline "title" is actually the lowercase continuation of a sentence, e.g. "SDI 8P000, completion of a current T5 Investigation ..." — is rejected: its title fails the real-title test, leaving the block with no valid anchor, so #entries returns [].

Defined Under Namespace

Classes: Anchor

Constant Summary collapse

DECORATIVE =
Patterns::DECORATIVE
BARE_DATE =

A bare (keyword-less) date parenthetical, e.g. "(31 Oct 24)" — the date annotation on the officer 88X0 card carries no Changed/Established word.

/\(\s*(\d{1,2}\s*[A-Za-z]{3,9}\s*\d{2,4})\s*\)/
BARE_DATE_LINE =
/\A#{BARE_DATE}/
KEYWORD_DATE_LINE =

A keyword date annotation ("(Changed ...)"), open paren optional.

/\A\(?\s*(?:Changed|Established|Effective|Change)\b/

Instance Method Summary collapse

Constructor Details

#initialize(record, config: Config.dafecd) ⇒ SdiCardParser

Returns a new instance of SdiCardParser.



41
42
43
44
# File 'lib/gov_codes/dafecd/ri_sdi/sdi_card_parser.rb', line 41

def initialize(record, config: Config.dafecd)
  @config = config
  @lines = record.lines.reject { |line| line =~ config.header }
end

Instance Method Details

#entriesArray<Hash>

Returns one entry hash per code in the block.

Returns:

  • (Array<Hash>)

    one entry hash per code in the block



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gov_codes/dafecd/ri_sdi/sdi_card_parser.rb', line 47

def entries
  anchors = self.anchors
  return [] if anchors.empty?

  shared = shared_title
  date = changed_date
  shreds = shredouts

  anchors.map do |anchor|
    raw = anchor.inline_title || shared
    name = raw && Title.titleize(raw)
    {
      code: anchor.code,
      name: name,
      raw_title: raw,
      changed_date: date,
      glued_title: Title.glued?(name),
      shredouts: shreds
    }
  end
end