Class: GovCodes::Dafecd::ShredoutDegluer
- Inherits:
-
Object
- Object
- GovCodes::Dafecd::ShredoutDegluer
- Defined in:
- lib/gov_codes/dafecd/shredout_degluer.rb
Overview
Applies verified de-glued shredout values.
pdf-reader drops spaces inside shredout meanings exactly as it does inside specialty titles ("ImageryAnalyst", "TacticalAir Control Party Officer"). The deterministic extractor keeps those verbatim and cannot safely re-insert the missing spaces. The clean values are produced out of band and shipped in per-publication files under shredout_overrides/ (mirroring title_overrides/).
The data is nested one level deeper than the title overrides: a specialty maps to a suffix => clean-value map, e.g.
:1A1X8:
:A: C-32/C-40B/C Flight Attendant
:C: C-37A/B Flight Attendant
The de-gluing invariant — enforced at build time by IndexBuilder — is that an override may only change SPACING and CASE relative to the raw extracted value; no letter, digit, or punctuation may change. Any drift (or an override targeting a shredout absent from the source) fails the build loudly rather than silently applying a stale value.
Class Method Summary collapse
-
.empty ⇒ Object
An empty de-gluer applies no overrides (keeps the verbatim values).
-
.for(publication) ⇒ ShredoutDegluer
Loaded from +publication+'s overrides file, or an empty de-gluer when that file does not exist.
-
.load(path) ⇒ ShredoutDegluer
Loaded from
path.
Instance Method Summary collapse
- #any? ⇒ Boolean
-
#each_override ⇒ Object
Yields every declared override so the build can verify each targets a shredout that actually exists (completeness gate).
-
#initialize(overrides = {}) ⇒ ShredoutDegluer
constructor
A new instance of ShredoutDegluer.
-
#overrides_for(specialty) ⇒ Hash{Symbol=>String}?
Suffix => clean value for
specialty.
Constructor Details
#initialize(overrides = {}) ⇒ ShredoutDegluer
Returns a new instance of ShredoutDegluer.
48 49 50 |
# File 'lib/gov_codes/dafecd/shredout_degluer.rb', line 48 def initialize(overrides = {}) @overrides = overrides end |
Class Method Details
.empty ⇒ Object
An empty de-gluer applies no overrides (keeps the verbatim values).
42 43 44 |
# File 'lib/gov_codes/dafecd/shredout_degluer.rb', line 42 def self.empty new({}) end |
.for(publication) ⇒ ShredoutDegluer
Returns loaded from +publication+'s overrides file, or an empty de-gluer when that file does not exist.
36 37 38 39 |
# File 'lib/gov_codes/dafecd/shredout_degluer.rb', line 36 def self.for(publication) path = publication.shredout_overrides_path File.exist?(path) ? load(path) : empty end |
.load(path) ⇒ ShredoutDegluer
Returns loaded from path.
29 30 31 32 |
# File 'lib/gov_codes/dafecd/shredout_degluer.rb', line 29 def self.load(path) overrides = YAML.safe_load_file(path, permitted_classes: [Symbol]) || {} new(overrides) end |
Instance Method Details
#any? ⇒ Boolean
68 69 70 |
# File 'lib/gov_codes/dafecd/shredout_degluer.rb', line 68 def any? !@overrides.empty? end |
#each_override ⇒ Object
Yields every declared override so the build can verify each targets a shredout that actually exists (completeness gate).
59 60 61 62 63 64 65 66 |
# File 'lib/gov_codes/dafecd/shredout_degluer.rb', line 59 def each_override return enum_for(:each_override) unless block_given? @overrides.each do |specialty, suffixes| suffixes.each do |suffix, value| yield specialty, suffix, value end end end |
#overrides_for(specialty) ⇒ Hash{Symbol=>String}?
Returns suffix => clean value for specialty.
53 54 55 |
# File 'lib/gov_codes/dafecd/shredout_degluer.rb', line 53 def overrides_for(specialty) @overrides[specialty] end |