Class: GovCodes::Dafecd::ShredoutParser
- Inherits:
-
Object
- Object
- GovCodes::Dafecd::ShredoutParser
- Defined in:
- lib/gov_codes/dafecd/shredout_parser.rb
Overview
Parses a "Specialty Shredouts" table into a suffix => name map.
The table is laid out in two side-by-side columns, e.g. (enlisted):
Suffix Primary Aircraft Suffix Primary Aircraft
A C-5 Flight Engineer L C-130H Flight Engineer
B C-5 Loadmaster N C-130H Loadmaster
The officer directory uses the same two-column interleave under a different heading ("Suffix ... Portion of AFS to Which Related"). Both columns are captured. Values that wrap onto a continuation line are captured only up to the wrap (a documented, minor limitation). The table header is publication-specific (injected Publication); the default is enlisted.
Constant Summary collapse
- PAIR =
A single suffix/name cell. The suffix is one capital letter followed by 2+ spaces; the name runs until 2+ spaces precede the next column's suffix or the line ends.
/\b([A-Z])\s{2,}([A-Z0-9][A-Za-z0-9 \/().-]{2,45}?)(?=\s{2,}[A-Z]\s{2,}|\s*$)/- RI_SDI_PAIR =
A more permissive variant used by the RI/SDI extractor, whose values carry punctuation the AFSC tables never do: a colon ("8W1XX WSMs w/PAFSC: 2W0X1" in the Space Force 8W tables) and a comma ("Graduated, Flight Chief" in the 8R300 recruiter table). The AFSC ladder pipeline keeps the stricter PAIR (its default), so the shipped enlisted/officer artifacts are unaffected.
/\b([A-Z])\s{2,}([A-Z0-9][A-Za-z0-9 \/().:,-]{2,45}?)(?=\s{2,}[A-Z]\s{2,}|\s*$)/
Instance Method Summary collapse
-
#initialize(text, publication: Publication.dafecd, pair: PAIR) ⇒ ShredoutParser
constructor
A new instance of ShredoutParser.
-
#parse ⇒ Hash{Symbol=>String}
Suffix letter => shredout name.
Constructor Details
#initialize(text, publication: Publication.dafecd, pair: PAIR) ⇒ ShredoutParser
Returns a new instance of ShredoutParser.
35 36 37 38 39 |
# File 'lib/gov_codes/dafecd/shredout_parser.rb', line 35 def initialize(text, publication: Publication.dafecd, pair: PAIR) @text = text @header = publication.shredout_header @pair = pair end |
Instance Method Details
#parse ⇒ Hash{Symbol=>String}
Returns suffix letter => shredout name.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gov_codes/dafecd/shredout_parser.rb', line 42 def parse result = {} table_lines.each do |line| # Strip stray decorative glyphs that would otherwise break the column # lookahead (e.g. a U+F0EA bullet sitting in a between-column gap). line.gsub(Patterns::DECORATIVE, " ").scan(@pair) do |suffix, name| result[suffix.to_sym] = name.strip end end result end |