From a10b8a4288ba2c3a1a28ceeed69c3dfe48857f1e Mon Sep 17 00:00:00 2001 From: Jessie Keck Date: Mon, 29 Feb 2016 15:13:41 -0800 Subject: [PATCH] Do not render blacklisted subfields in MARC contributor data. --- app/helpers/marc_helper.rb | 60 +++++++++---------- .../marc_records/marc_metadata_fixtures.rb | 7 +++ spec/helpers/marc_helper_spec.rb | 7 +++ 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/app/helpers/marc_helper.rb b/app/helpers/marc_helper.rb index eaacceef0..e3a7fccb9 100644 --- a/app/helpers/marc_helper.rb +++ b/app/helpers/marc_helper.rb @@ -96,28 +96,27 @@ def contributors_and_works_from_marc(marc) href_text = [] extra_href = [] field.each do |subfield| - unless ["?","="].include?(subfield.code) - # $e $i $4 - if subfield.code == "t" - subt = :now - end - if subfield.code == "i" and subt == :none - before_text << subfield.value - elsif subt == :none - href_text << subfield.value unless ["e","i","4"].include?(subfield.code) - link_text << subfield.value - elsif subt == :now or (subt == :passed and subfield.value.strip =~ /[\.|;]$/) - href_text << subfield.value unless ["e","i","4"].include?(subfield.code) - link_text << subfield.value - subt = :passed - subt = :done if subfield.value.strip =~ /[\.|;]$/ - elsif subt == :done - extra_href << subfield.value unless ["e","i","4"].include?(subfield.code) - extra_text << subfield.value - else - href_text << subfield.value unless ["e","i","4"].include?(subfield.code) - link_text << subfield.value - end + next if Constants::EXCLUDE_FIELDS.include?(subfield.code) + # $e $i $4 + if subfield.code == "t" + subt = :now + end + if subfield.code == "i" and subt == :none + before_text << subfield.value + elsif subt == :none + href_text << subfield.value unless ["e","i","4"].include?(subfield.code) + link_text << subfield.value + elsif subt == :now or (subt == :passed and subfield.value.strip =~ /[\.|;]$/) + href_text << subfield.value unless ["e","i","4"].include?(subfield.code) + link_text << subfield.value + subt = :passed + subt = :done if subfield.value.strip =~ /[\.|;]$/ + elsif subt == :done + extra_href << subfield.value unless ["e","i","4"].include?(subfield.code) + extra_text << subfield.value + else + href_text << subfield.value unless ["e","i","4"].include?(subfield.code) + link_text << subfield.value end end href = "\"#{href_text.join(" ")}\"" @@ -135,16 +134,13 @@ def contributors_and_works_from_marc(marc) temp_text = "" relator_text = [] field.each do |subfield| - unless ["?","="].include?(subfield.code) - if subfield.code == "e" - relator_text << subfield.value - elsif subfield.code == "4" and relator_text.blank? - relator_text << Constants::RELATOR_TERMS[subfield.value] - elsif subfield.code == "6" - nil - elsif subfield.code != "e" and subfield.code != "4" - link_text << "#{subfield.value} " - end + next if Constants::EXCLUDE_FIELDS.include?(subfield.code) + if subfield.code == "e" + relator_text << subfield.value + elsif subfield.code == "4" and relator_text.blank? + relator_text << Constants::RELATOR_TERMS[subfield.value] + elsif subfield.code != "e" and subfield.code != "4" + link_text << "#{subfield.value} " end end temp_text << link_to(link_text.strip, catalog_index_path(:q => "\"#{link_text}\"", :search_field => 'search_author')) diff --git a/spec/fixtures/marc_records/marc_metadata_fixtures.rb b/spec/fixtures/marc_records/marc_metadata_fixtures.rb index 2fcc9f09c..87b6627bb 100644 --- a/spec/fixtures/marc_records/marc_metadata_fixtures.rb +++ b/spec/fixtures/marc_records/marc_metadata_fixtures.rb @@ -134,6 +134,7 @@ def metadata2 Subject2 + 880-04 Farruk̲h̲ī, Āṣif, 1959- @@ -432,6 +433,11 @@ def contributor_fixture Actor prf + + 880-00 + Contributor4 + Contributor $t + xml end @@ -865,6 +871,7 @@ def marc_characteristics_fixture xml end + def marc_sections_fixture <<-xml diff --git a/spec/helpers/marc_helper_spec.rb b/spec/helpers/marc_helper_spec.rb index ac350420a..4a4626a99 100644 --- a/spec/helpers/marc_helper_spec.rb +++ b/spec/helpers/marc_helper_spec.rb @@ -203,6 +203,13 @@ it "should not display anything when no contributors are available" do expect(link_to_contributor_from_marc(nil_document.to_marc)).to be_nil end + + it 'should not display blacklisted fields' do + link = contributors_and_works_from_marc(contributor.to_marc) + link.each do |_, value| + expect(value).to_not match(/880-00/) + end + end end describe "#get_toc" do let(:bad_toc) { SolrDocument.new(marcxml: bad_toc_fixture) }