Skip to content

Commit

Permalink
correctly parse affiliation name #99
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 12, 2020
1 parent e21c858 commit 5293713
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bolognese (1.8.10)
bolognese (1.8.11)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down Expand Up @@ -187,7 +187,7 @@ GEM
thread_safe (~> 0.1)
unicode_utils (1.4.0)
vcr (3.0.3)
webmock (3.9.1)
webmock (3.9.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
15 changes: 14 additions & 1 deletion lib/bolognese/readers/crossref_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,26 @@ def crossref_people(bibliographic_metadata, contributor_role)
if a["surname"].present? || a["given_name"].present? || name_identifiers.present?
given_name = parse_attributes(a["given_name"])
family_name = parse_attributes(a["surname"])
affiliation = Array.wrap(a["affiliation"]).map do |a|
if a.is_a?(Hash) && a.key?("__content__") && a["__content__"].strip.blank?
nil
elsif a.is_a?(Hash) && a.key?("__content__")
{ "name" => a["__content__"] }
elsif a.is_a?(Hash)
a
elsif a.strip.blank?
nil
elsif a.is_a?(String)
{ "name" => a }
end
end.compact

{ "nameType" => "Personal",
"nameIdentifiers" => name_identifiers,
"name" => [family_name, given_name].compact.join(", "),
"givenName" => given_name,
"familyName" => family_name,
"affiliation" => Array.wrap(a["affiliation"]).map { |a| { "name" => a }}.presence,
"affiliation" => affiliation.presence,
"contributorType" => contributor_role == "editor" ? "Editor" : nil }.compact
else
{ "nameType" => "Organizational",
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bolognese
VERSION = "1.8.10"
VERSION = "1.8.11"
end

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions spec/readers/crossref_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,23 @@
expect(subject.date_registered).to eq("2019-11-02T09:30:06Z")
end

it "affiliation is space" do
input = "https://doi.org/10.1177/0042098011428175"
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.1177/0042098011428175")
expect(subject.url).to eq("http://journals.sagepub.com/doi/10.1177/0042098011428175")
expect(subject.types).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"JournalArticle", "resourceTypeGeneral"=>"Text", "ris"=>"JOUR", "schemaOrg"=>"ScholarlyArticle")
expect(subject.creators.length).to eq(1)
expect(subject.creators.first).to eq("familyName"=>"Petrovici", "givenName"=>"Norbert", "name"=>"Petrovici, Norbert", "nameType"=>"Personal")
expect(subject.titles).to eq([{"title"=>"Workers and the City: Rethinking the Geographies of Power in Post-socialist Urbanisation"}])
expect(subject.dates).to include({"date"=>"2011-12-22", "dateType"=>"Issued"})
expect(subject.publication_year).to eq("2011")
expect(subject.publisher).to eq("SAGE Publications")
expect(subject.agency).to eq("crossref")
expect(subject.date_registered).to eq("2017-12-17T00:37:32Z")
end

it "posted content copernicus" do
input = "https://doi.org/10.5194/CP-2020-95"
subject = Bolognese::Metadata.new(input: input)
Expand Down

0 comments on commit 5293713

Please sign in to comment.