From 22219754a68b1d7b3d93da8cbd94400babac369a Mon Sep 17 00:00:00 2001 From: codycooperross <50597551+codycooperross@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:51:09 -0500 Subject: [PATCH] NoMethodError: undefined method `strip' for nil:NilClass Fixes #180 --- lib/bolognese/readers/datacite_reader.rb | 2 +- spec/fixtures/datacite_blank_publisher.xml | 18 ++++++++++++++++++ spec/readers/datacite_reader_spec.rb | 8 ++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/datacite_blank_publisher.xml diff --git a/lib/bolognese/readers/datacite_reader.rb b/lib/bolognese/readers/datacite_reader.rb index acc01c71..20fd6144 100644 --- a/lib/bolognese/readers/datacite_reader.rb +++ b/lib/bolognese/readers/datacite_reader.rb @@ -101,7 +101,7 @@ def read_datacite(string: nil, **options) { "name" => r.strip } elsif r.is_a?(Hash) { - "name" => r["__content__"].strip, + "name" => r["__content__"].present? ? r["__content__"].strip : nil, "publisherIdentifier" => r["publisherIdentifierScheme"] == "ROR" ? normalize_ror(r["publisherIdentifier"]) : r["publisherIdentifier"], "publisherIdentifierScheme" => r["publisherIdentifierScheme"], "schemeUri" => r["schemeURI"], diff --git a/spec/fixtures/datacite_blank_publisher.xml b/spec/fixtures/datacite_blank_publisher.xml new file mode 100644 index 00000000..9ca719ee --- /dev/null +++ b/spec/fixtures/datacite_blank_publisher.xml @@ -0,0 +1,18 @@ + + + 10.81360/4DVP-KR57 + + + Møller, Jørgen + Jørgen + Møller + + + + Economic Crisis and Democratic Breakdown in the Interwar Years: A Reassessment + Wirtschaftskrise und demokratischer Zusammenbruch in der Zwischenkriegszeit: Eine Neubewertung + + + 2015 + + \ No newline at end of file diff --git a/spec/readers/datacite_reader_spec.rb b/spec/readers/datacite_reader_spec.rb index a24a88e4..ab0a0bee 100644 --- a/spec/readers/datacite_reader_spec.rb +++ b/spec/readers/datacite_reader_spec.rb @@ -1801,4 +1801,12 @@ ] ) end + + it "blank publisher" do + input = fixture_path + "datacite_blank_publisher.xml" + subject = Bolognese::Metadata.new(input: input) + expect(subject.publisher).to eq( + { "publisherIdentifier" => "https://ror.org/04wxnsj81" } + ) + end end