Skip to content

Commit

Permalink
handle date errors in citeproc generation. datacite/lupo#590
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 24, 2020
1 parent 64dbc29 commit ca6bfd3
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 7 deletions.
12 changes: 7 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bolognese (1.8.1)
bolognese (1.8.2)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down Expand Up @@ -58,8 +58,9 @@ GEM
csl (~> 1.0)
diff-lcs (1.4.4)
docile (1.3.2)
ebnf (1.2.0)
ebnf (2.1.0)
rdf (~> 3.1)
scanf (~> 1.0)
sxp (~> 1.1)
edtf (3.0.5)
activesupport (>= 3.0, < 7.0)
Expand All @@ -79,7 +80,7 @@ GEM
concurrent-ruby (~> 1.0)
hashdiff (1.0.1)
htmlentities (4.3.4)
i18n (1.8.3)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
iso8601 (0.9.1)
json-canonicalization (0.2.0)
Expand Down Expand Up @@ -148,8 +149,8 @@ GEM
rdf (~> 3.1)
rdf-rdfa (~> 3.1)
rdf-xsd (~> 3.1)
rdf-turtle (3.1.1)
ebnf (~> 1.2)
rdf-turtle (3.1.2)
ebnf (~> 2.0)
rdf (~> 3.1, >= 3.1.2)
rdf-vocab (3.1.7)
rdf (~> 3.1, >= 3.1.2)
Expand All @@ -172,6 +173,7 @@ GEM
nokogiri (~> 1.6)
rspec (~> 3)
safe_yaml (1.0.5)
scanf (1.0.0)
simplecov (0.18.5)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/metadata_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def citeproc_hsh
"language" => language,
"author" => author,
"contributor" => to_citeproc(contributors),
"issued" => get_date(dates, "Issued") ? get_date_parts(get_date(dates, "Issued")) : get_date_parts(publication_year),
"issued" => get_date(dates, "Issued") ? get_date_parts(get_date(dates, "Issued")) : get_date_parts(publication_year.to_s),
"submitted" => Array.wrap(dates).find { |d| d["dateType"] == "Submitted" }.to_h.fetch("__content__", nil),
"abstract" => parse_attributes(descriptions, content: "description", first: true),
"container-title" => container_title,
Expand Down
2 changes: 2 additions & 0 deletions lib/bolognese/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@ def get_date_parts(iso8601_time)
month = iso8601_time[5..6].to_i
day = iso8601_time[8..9].to_i
{ 'date-parts' => [[year, month, day].reject { |part| part == 0 }] }
rescue TypeError
nil
end

def get_date_from_date_parts(date_as_parts)
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.1"
VERSION = "1.8.2"
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions spec/writers/citeproc_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@
expect(json["issued"]).to eq("date-parts" => [[2016, 12, 20]])
end

it "Another dataset" do
input = "10.26301/qdpd-2250"
subject = Bolognese::Metadata.new(input: input, from: "datacite")
json = JSON.parse(subject.citeproc)
expect(json["type"]).to eq("dataset")
expect(json["id"]).to eq("https://doi.org/10.26301/qdpd-2250")
expect(json["DOI"]).to eq("10.26301/qdpd-2250")
expect(json["title"]).to eq("USS Pampanito Submarine")
expect(json["author"]).to eq([{"literal"=>"USS Pampanito"}])
expect(json["publisher"]).to eq("Open Heritage 3D")
expect(json["issued"]).to eq("date-parts"=>[[2020]])
end

it "journal article" do
input = "10.7554/eLife.01567"
subject = Bolognese::Metadata.new(input: input, from: "crossref")
Expand Down

0 comments on commit ca6bfd3

Please sign in to comment.