Skip to content

Commit

Permalink
DOI serializer.
Browse files Browse the repository at this point in the history
  • Loading branch information
svogt0511 committed Nov 28, 2023
1 parent b7db165 commit 06c5e31
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions app/serializers/datacite_doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,22 @@ class DataciteDoiSerializer
attribute :doi, &:uid

attribute :publisher do |object, params|
# publisher accessor will now always return a publisher object.
# new obj format only if ?publisher=true, otherwise serialize the old format (a string
if params && (params[:publisher] == "true")
if object.publisher.respond_to?(:to_hash)
object.publisher
elsif object.publisher.respond_to?(:to_str)
{ "name" => object.publisher }
end
# new - format obj only if ?publisher=true, otherwise serialize the old format (a string)
if object.publisher.nil?
nil
else
if object.publisher.respond_to?(:to_hash)
object.publisher["name"]
elsif object.publisher.respond_to?(:to_str)
object.publisher
if params&.dig(:publisher) == "true"
if object.publisher.respond_to?(:to_str)
{ "name" => object.publisher }
else
object.publisher
end
else
if object.publisher.respond_to?(:to_str)
object.publisher
else
object.publisher["name"]
end
end
end
end
Expand Down

0 comments on commit 06c5e31

Please sign in to comment.