Class: GovCodes::Dafecd::RiSdi::Config

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

Overview

Per-publication configuration for the RI/SDI extractor.

The DAFECD (enlisted) and DAFOCD (officer) directories publish their Reporting Identifiers (RI) and Special Duty Identifiers (SDI) in the same two record formats (the SDI "card" and the flat numbered RI list). They differ only in the code SHAPE (enlisted codes are 5 chars, "8A200"; officer codes are 4 chars, "80C0"), the running page header, and where the combined artifact is written. A Config captures exactly those differences and is injected into every stage.

Constant Summary collapse

ENLISTED_CODE =

Enlisted RI/SDI code: a digit, a letter, three digits (8A200, 9Z200, 5I000, 5Z700). Space Force RI reuses the same shape.

/\d[A-Z]\d{3}/
OFFICER_CODE =

Officer RI/SDI code: two digits, a letter, a level digit (80C0, 90G0). The trailing character is a DIGIT — never "X" — which is what rejects the academic CIP codes ("05XX", "14.10XX") that share the officer RI list's page real estate.

/\d\d[A-Z]\d/
DAFECD_HEADER =
/^\s*DAFECD,\s+\d/
DAFOCD_HEADER =
/^\s*DAFOCD,\s+\d/
SHREDOUT_HEADER =

Both directories head the shredout table with "Suffix ... Portion of <AFS|RI> to Which Related"; the leading "Suffix " is common to every variant, so the existing header regex matches them all.

/Suffix\s+\w/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, directory_name:, code:, header:, release_dir:, sections:, acronym_exclusions:) ⇒ Config

Returns a new instance of Config.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 90

def initialize(id:, directory_name:, code:, header:, release_dir:, sections:, acronym_exclusions:)
  @id = id
  @directory_name = directory_name
  @code = code
  @header = header
  @shredout_header = SHREDOUT_HEADER
  @release_dir = release_dir
  @sections = sections
  @acronym_exclusions = acronym_exclusions
  @index_filename = "ri.yml"
  # Human-verified de-glued titles, one file per publication, gated at
  # build time against the verbatim source (spacing/case only).
  @title_overrides_filename = "title_overrides/#{id}.yml"
  # A standalone SDI card anchor ("SDI 8A200") and an inline-title anchor
  # ("SDI 8L100,AirAdvisor - Basic"); group 1 is the code, group 2 (inline
  # only) the raw title text. The inline anchor's "SDI " keyword is
  # OPTIONAL: the officer Air Advisor cards (89A0-89I0) print as a bare
  # "CODE,Title" line with no prefix. False positives are still rejected
  # downstream by Title.real? (the inline "title" must start with a
  # capital/digit/paren, never a wrapped-prose lowercase continuation),
  # and the "^" anchor keeps the code at line start so mid-line codes
  # (e.g. "...10-4301V1, Air Advisor Training") never match.
  @sdi_anchor = /^\s*SDI\s+(#{code})\*?\s*$/
  @sdi_inline_anchor = /^\s*(?:SDI\s+)?(#{code})\*?,\s*(\S.*)$/
  # A flat-list RI anchor: a top-level list number, an optional decorative
  # star, then the code. Group 1 is the list number, group 2 the code,
  # group 3 the remainder of the line (title, possibly with a trailing
  # date). Tolerates a run of spaces or none after "<n>.", and a comma or
  # a bare space before the title.
  @ri_anchor =
    /^[ \t]*(\d{1,2})\.[ \t]*(?:#{Patterns::DECORATIVE}[ \t]*)*(#{code})\s*,?\s*(.*)$/
  # The one ladder record embedded in the enlisted AF SDI section
  # ("CEM Code 8G000", Premier Honor Guard) is handled by the AFSC
  # pipeline; the splitter uses this to isolate it from the cards.
  @cem = Patterns::CEM
  freeze
end

Instance Attribute Details

#acronym_exclusionsObject (readonly)

Returns the value of attribute acronym_exclusions.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def acronym_exclusions
  @acronym_exclusions
end

#cemObject (readonly)

Returns the value of attribute cem.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def cem
  @cem
end

#codeObject (readonly)

Returns the value of attribute code.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def code
  @code
end

#directory_nameObject (readonly)

Returns the value of attribute directory_name.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def directory_name
  @directory_name
end

#headerObject (readonly)

Returns the value of attribute header.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def header
  @header
end

#idObject (readonly)

Returns the value of attribute id.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def id
  @id
end

#index_filenameObject (readonly)

Returns the value of attribute index_filename.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def index_filename
  @index_filename
end

#release_dirObject (readonly)

Returns the value of attribute release_dir.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def release_dir
  @release_dir
end

#ri_anchorObject (readonly)

Returns the value of attribute ri_anchor.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def ri_anchor
  @ri_anchor
end

#sdi_anchorObject (readonly)

Returns the value of attribute sdi_anchor.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def sdi_anchor
  @sdi_anchor
end

#sdi_inline_anchorObject (readonly)

Returns the value of attribute sdi_inline_anchor.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def sdi_inline_anchor
  @sdi_inline_anchor
end

#sectionsObject (readonly)

Returns the value of attribute sections.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def sections
  @sections
end

#shredout_headerObject (readonly)

Returns the value of attribute shredout_header.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def shredout_header
  @shredout_header
end

#title_overrides_filenameObject (readonly)

Returns the value of attribute title_overrides_filename.



86
87
88
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 86

def title_overrides_filename
  @title_overrides_filename
end

Class Method Details

.dafecdObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 37

def dafecd
  @dafecd ||= new(
    id: :dafecd,
    directory_name: "Department of the Air Force Enlisted Classification Directory",
    code: ENLISTED_CODE,
    header: DAFECD_HEADER,
    release_dir: "dafecd",
    # Trailing parentheticals that abbreviate an embedded organization
    # or a sub-phrase — NOT the identifier's own name — and so must not
    # ship as the record's acronym. See the acronym classification in
    # the extractor report. (SWMS/AFSPECWAR/MEPCOM/etc. are mid-title or
    # length-excluded and never captured, so they need no listing here.)
    acronym_exclusions: %i[9B100 9H100 9M400],
    # AF SDI -> AF RI -> (skip SFSC) -> SF SDI -> SF RI
    sections: [
      {kind: :sdi, force: :af, header: /^\s*SPECIALDUTY IDENTIFIERS \(SDI\)/},
      {kind: :ri, force: :af, header: /^\s*AIR FORCE REPORTING IDENTIFIERS \(RI\)/},
      {kind: :skip, force: :sf, header: /^\s*SPACE FORCE SPECIALTY CODES \(SFSC\)/},
      {kind: :sdi, force: :sf, header: /^\s*SPACE FORCE SPECIAL ?DUTY IDENTIFIERS \(SDI\)/},
      {kind: :ri, force: :sf, header: /^\s*SPACE FORCE REPORTING IDENTIFIERS \(RI\)/}
    ]
  )
end

.dafocdObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 61

def dafocd
  @dafocd ||= new(
    id: :dafocd,
    directory_name: "Department of the Air Force Officer Classification Directory",
    code: OFFICER_CODE,
    header: DAFOCD_HEADER,
    release_dir: "dafocd",
    acronym_exclusions: [],
    # Officer SDI -> Officer RI (no AF/SF split in the officer directory)
    sections: [
      {kind: :sdi, force: :officer, header: /^\s*SPECIAL ?DUTY IDENTIFIERS \(SDI\)/},
      {kind: :ri, force: :officer, header: /^\s*REPORTING IDENTIFIERS \(RI\)/}
    ]
  )
end

.for(id) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 77

def for(id)
  by_id = {dafecd: dafecd, dafocd: dafocd}
  by_id.fetch(id.to_sym) do
    raise ArgumentError,
      "unknown publication #{id.inspect}; valid options are #{by_id.keys.map(&:inspect).join(", ")}"
  end
end

Instance Method Details

#title_overrides_pathObject

The absolute path to this publication's RI/SDI title-overrides file. Mirrors Publication#title_overrides_path so the shared TitleDegluer (its .for/#override_for/.matches_source? API) loads from a Config too.



131
132
133
# File 'lib/gov_codes/dafecd/ri_sdi/config.rb', line 131

def title_overrides_path
  File.expand_path(@title_overrides_filename, __dir__)
end