Skip to content

Commit

Permalink
Do not render blacklisted subfields in MARC contributor data.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeck committed Feb 29, 2016
1 parent 7989972 commit a10b8a4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
60 changes: 28 additions & 32 deletions app/helpers/marc_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")}\""
Expand All @@ -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'))
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/marc_records/marc_metadata_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def metadata2
<subfield code="d">Subject2</subfield>
</datafield>
<datafield tag="700" ind1="1" ind2=" ">
<subfield code="6">880-04</subfield>
<subfield code="a">Farruk̲h̲ī, Āṣif,</subfield>
<subfield code="d">1959-</subfield>
</datafield>
Expand Down Expand Up @@ -432,6 +433,11 @@ def contributor_fixture
<subfield code="e">Actor</subfield>
<subfield code="4">prf</subfield>
</datafield>
<datafield tag="700" ind1="1" ind2=" ">
<subfield code="6">880-00</subfield>
<subfield code="a">Contributor4</subfield>
<subfield code="t">Contributor $t</subfield>
</datafield>
</record>
xml
end
Expand Down Expand Up @@ -865,6 +871,7 @@ def marc_characteristics_fixture
</record>
xml
end

def marc_sections_fixture
<<-xml
<record>
Expand Down
7 changes: 7 additions & 0 deletions spec/helpers/marc_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit a10b8a4

Please sign in to comment.