Module: GovCodes::Dafecd::ShredoutAcronyms
- Defined in:
- lib/gov_codes/dafecd/shredout_acronyms.rb
Overview
Extracts shredout-level acronyms for the officer directory from two deterministic sources (both grounded verbatim in the record source):
a. Shredout TABLE values whose meaning ends in a trailing "(ACR)", e.g.
"Air Liaison Officer (ALO)" -> {U: "ALO"}. The :shredouts value is kept
verbatim; only the acronym is lifted out.
b. A numbered in-record enumeration of the form
"<family>X<shred> (<Title> (<ACR>))", e.g. in the 19Z record:
"19ZXB (Tactical Air Control Party Officer (TACPO))" -> {B: "TACPO"}.
Only codes belonging to the record's own specialty family are accepted.
Constant Summary collapse
- TABLE_ACRONYM =
A shredout value's trailing parenthetical acronym.
/\(([A-Z][A-Z0-9]{1,7})\)\s*\z/
Class Method Summary collapse
-
.from_enumeration(record, family) ⇒ Hash{Symbol=>String}
Shred letter => acronym.
-
.from_table(shredouts) ⇒ Hash{Symbol=>String}
Suffix => trailing acronym.
Class Method Details
.from_enumeration(record, family) ⇒ Hash{Symbol=>String}
Returns shred letter => acronym.
36 37 38 39 40 41 42 43 44 |
# File 'lib/gov_codes/dafecd/shredout_acronyms.rb', line 36 def from_enumeration(record, family) return {} if family.nil? || family.empty? result = {} pattern = /#{Regexp.escape(family)}X([A-Z])\s*\([^()]*\(([A-Z][A-Z0-9]{1,7})\)\)/ record.scan(pattern) do |shred, acronym| result[shred.to_sym] = acronym end result end |
.from_table(shredouts) ⇒ Hash{Symbol=>String}
Returns suffix => trailing acronym.
24 25 26 27 28 29 30 31 |
# File 'lib/gov_codes/dafecd/shredout_acronyms.rb', line 24 def from_table(shredouts) result = {} shredouts.each do |suffix, meaning| match = meaning.match(TABLE_ACRONYM) result[suffix] = match[1] if match end result end |