Class: PennMARC::HeadingControl
- Inherits:
-
Object
- Object
- PennMARC::HeadingControl
- Defined in:
- lib/pennmarc/heading_control.rb
Overview
Shared tools and values for controlling handling of subject or genre headings
Constant Summary collapse
- ALLOWED_SOURCE_CODES =
These codes are expected to be found in sf2 of a subject/genre field when the indicator2 value is 7, indicating “source specified”. There are some sources whose headings we don’t want to display.
%w[aat cct fast ftamc gmgpc gsafd homoit jlabsh lcgft lcsh lcstt lctgm local/osu mesh ndlsh nli nlksh rbbin rbgenr rbmscv rbpap rbpri rbprov rbpub rbtyp].freeze
- REMOVE_TERM_REGEX =
/#{Mappers.headings_to_remove&.join('|')}/i
- REPLACE_TERM_REGEX =
/(#{Mappers.heading_overrides.keys.join('|')})/i
Class Method Summary collapse
-
.term_override(values) ⇒ Array
Replace or remove any terms in provided values pursuant to the configuration in remove and override mappers.
Class Method Details
.term_override(values) ⇒ Array
Replace or remove any terms in provided values pursuant to the configuration in remove and override mappers. Used to remove or replace offensive or otherwise undesirable subject headings.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pennmarc/heading_control.rb', line 19 def term_override(values) values.filter_map do |value| # Remove values if they contain a remove term next nil if value.match?(REMOVE_TERM_REGEX) # return early if theres no terms to replace next value if value.match(REPLACE_TERM_REGEX).nil? # lookup and perform replacement value.sub(::Regexp.last_match.to_s, Mappers.heading_overrides[::Regexp.last_match.to_s.downcase]) end end |