From b56ce9d2ae985253967da057082624ba83de108f Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Thu, 29 Feb 2024 15:22:28 -0500 Subject: [PATCH 1/2] Don't fail on citations when the 700 only has punctuation and spaces Co-authored-by: Christina Chortaria Co-authored-by: Jane Sandberg --- .../blacklight/marc/document_export.rb | 2 ++ .../blacklight/marc/document_export_spec.rb | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app/models/concerns/blacklight/marc/document_export.rb b/app/models/concerns/blacklight/marc/document_export.rb index f3a7af6..8571bed 100644 --- a/app/models/concerns/blacklight/marc/document_export.rb +++ b/app/models/concerns/blacklight/marc/document_export.rb @@ -561,6 +561,7 @@ def get_publication_data(record) def abbreviate_name(name) name_parts = name.split(", ") + return "" if name_parts.empty? first_name_parts = name_parts.last.split(" ") temp_name = name_parts.first + ", " + first_name_parts.first[0,1] + "." first_name_parts.shift @@ -572,6 +573,7 @@ def name_reverse(name) name = clean_end_punctuation(name) return name unless name =~ /,/ temp_name = name.split(", ") + return name if temp_name.empty? return temp_name.last + " " + temp_name.first end end diff --git a/spec/models/concerns/blacklight/marc/document_export_spec.rb b/spec/models/concerns/blacklight/marc/document_export_spec.rb index 772e2d7..3900fa7 100644 --- a/spec/models/concerns/blacklight/marc/document_export_spec.rb +++ b/spec/models/concerns/blacklight/marc/document_export_spec.rb @@ -26,6 +26,19 @@ def to_marc end end +class MockClassInvalid700 + include Blacklight::Marc::DocumentExport + + def to_marc + fields = [ + { "100" => { "subfields" => [{ "a" => "Borja, Ronaldo I." }]}}, + { "245" => { "ind1" => " ", "ind2" => " ", "subfields" => [{ "a" => "Plasticity : ", "b" => "modeling & computation /", "c" => "Ronaldo I. Borja." }] } }, + { "700" => { "ind1" => " ", "ind2" => " ", "subfields" => [{ "a" => ", ." }] } } + ] + MARC::Record.new_from_hash('fields' => fields) + end +end + RSpec.describe Blacklight::Marc::DocumentExport do describe 'export citiations from 260 field' do it 'exports citations in apa format' do @@ -60,4 +73,21 @@ def to_marc expect(MockClass264.new.export_as_chicago_citation_txt).to include('Berlin: Springer,') end end + + describe 'when the 700 only has punctuation and spaces' do + it 'exports citations in apa format' do + expect(MockClassInvalid700.new.export_as_apa_citation_txt).to include('Borja, R. I') + expect(MockClassInvalid700.new.export_as_apa_citation_txt).to include('Plasticity') + end + + it 'exports citations in mla format' do + expect(MockClassInvalid700.new.export_as_mla_citation_txt).to include('Borja, Ronaldo I') + expect(MockClassInvalid700.new.export_as_mla_citation_txt).to include('Plasticity') + end + + it 'exports citations in Chicago format' do + expect(MockClassInvalid700.new.export_as_chicago_citation_txt).to include('Borja, Ronaldo I') + expect(MockClassInvalid700.new.export_as_chicago_citation_txt).to include('Plasticity') + end + end end From 511c6b7903133cc5dd7df1ae2e68b784f9331458 Mon Sep 17 00:00:00 2001 From: Beck Davis Date: Fri, 1 Mar 2024 16:50:14 -0500 Subject: [PATCH 2/2] Incorporate feedback from review Co-authored-by: Jane Sandberg Co-authored-by: Christina Chortaria --- app/models/concerns/blacklight/marc/document_export.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/concerns/blacklight/marc/document_export.rb b/app/models/concerns/blacklight/marc/document_export.rb index 8571bed..1e21fe9 100644 --- a/app/models/concerns/blacklight/marc/document_export.rb +++ b/app/models/concerns/blacklight/marc/document_export.rb @@ -571,9 +571,8 @@ def abbreviate_name(name) def name_reverse(name) name = clean_end_punctuation(name) - return name unless name =~ /,/ + return name if name == ", " || !(name =~ /,/) temp_name = name.split(", ") - return name if temp_name.empty? return temp_name.last + " " + temp_name.first end end