Skip to content

Commit

Permalink
Consistently read publisher as a hash from DataCite JSON and and Cros…
Browse files Browse the repository at this point in the history
…sCite; adjust publisher reads for bibtex and the Metadata model
  • Loading branch information
codycooperross committed Nov 6, 2023
1 parent ca90d2c commit 62a2bde
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/bolognese/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ def dates
end

def publisher
@publisher ||=
if meta.fetch("publisher", nil).is_a?(Hash)
@publisher ||=
if meta.fetch("publisher", nil).respond_to?(:to_hash)
meta.fetch("publisher", nil)
elsif meta.fetch("publisher", nil).is_a?(String)
elsif meta.fetch("publisher", nil).respond_to?(:to_str)
{ "name" => meta.fetch("publisher", nil) }.compact
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/readers/bibtex_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def read_bibtex(string: nil, **options)
"titles" => meta.try(:title).present? ? [{ "title" => meta.try(:title).to_s }] : [],
"creators" => creators,
"container" => container,
"publisher" => meta.try(:publisher).present? ? { "name" => meta.try(:publisher).to_s }.compact : nil,
"publisher" => meta.try(:publisher).present? ? { "name" => meta.publisher.to_s } : nil,
"related_identifiers" => related_identifiers,
"dates" => dates,
"publication_year" => publication_year,
Expand Down
5 changes: 4 additions & 1 deletion lib/bolognese/readers/crosscite_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ def read_crosscite(string: nil, **options)
errors = jsonlint(string)
return { "errors" => errors } if errors.present?

string.present? ? Maremma.from_json(string) : {}
crosscite = string.present? ? Maremma.from_json(string) : {}
crosscite["publisher"] = normalize_publisher(crosscite.fetch("publisher", nil)) if crosscite.fetch("publisher", nil).present?

crosscite
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/bolognese/readers/datacite_json_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ def read_datacite_json(string: nil, **options)
errors = jsonlint(string)
return { "errors" => errors } if errors.present?

string.present? ? Maremma.from_json(string).transform_keys! { |key| key.underscore } : {}
datacite_json = string.present? ? Maremma.from_json(string).transform_keys! { |key| key.underscore } : {}
datacite_json["publisher"] = normalize_publisher(datacite_json.fetch("publisher", nil)) if datacite_json.fetch("publisher", nil).present?

datacite_json
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/bolognese/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,14 @@ def normalize_licenses(licenses)
nil
end

def normalize_publisher(publisher)
if publisher.respond_to?(:to_hash)
publisher
elsif publisher.respond_to?(:to_str)
{ "name" => publisher }
end
end

def to_datacite_json(element, options={})
a = Array.wrap(element).map do |e|
e.inject({}) {|h, (k,v)| h[k.dasherize] = v; h }
Expand Down

0 comments on commit 62a2bde

Please sign in to comment.