Skip to content

Commit

Permalink
Appease rubocop.
Browse files Browse the repository at this point in the history
  • Loading branch information
svogt0511 committed Nov 27, 2023
1 parent 9916391 commit 1782bb3
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ class Doi < ApplicationRecord
message: ->(errors) { errors },
schema: PUBLISHER_JSON_SCHEMA
}

def validate_publisher_obj?(doi)
doi.validatable? && doi.publisher_obj? && !(doi.publisher.blank? || doi.publisher.all?(nil))
end

validates :publisher_obj, if: ->(doi) { validate_publisher_obj?(doi) }, json: json_schema_validation

# from https://www.crossref.org/blog/dois-and-matching-regular-expressions/ but using uppercase
Expand Down Expand Up @@ -2459,29 +2459,28 @@ def handle_resource_type(types)
end

private
def update_publisher_from_hash
if !publisher_before_type_cast.values.all?(nil)
self.publisher_obj = {
name: publisher_before_type_cast.fetch(:name, nil),
lang: publisher_before_type_cast.fetch(:lang, nil),
schemeUri: publisher_before_type_cast.fetch(:schemeUri, nil),
publisherIdentifier: publisher_before_type_cast.fetch(:publisherIdentifier, nil),
publisherIdentifierScheme: publisher_before_type_cast.fetch(:publisherIdentifierScheme, nil)
}.compact
self.publisher = publisher_before_type_cast.dig(:name)
else
reset_publishers
end
end

def update_publisher_from_hash
if !publisher_before_type_cast.values.all?(nil)
self.publisher_obj = {
name: publisher_before_type_cast.fetch(:name, nil),
lang: publisher_before_type_cast.fetch(:lang, nil),
schemeUri: publisher_before_type_cast.fetch(:schemeUri, nil),
publisherIdentifier: publisher_before_type_cast.fetch(:publisherIdentifier, nil),
publisherIdentifierScheme: publisher_before_type_cast.fetch(:publisherIdentifierScheme, nil)
}.compact
self.publisher = publisher_before_type_cast.dig(:name)
else
reset_publishers
def update_publisher_from_string
self.publisher_obj = { name: publisher_before_type_cast }
self.publisher = publisher_before_type_cast
end

def reset_publishers
self.publisher_obj = nil
self.publisher = nil
end
end

def update_publisher_from_string
self.publisher_obj = { name: publisher_before_type_cast }
self.publisher = publisher_before_type_cast
end

def reset_publishers
self.publisher_obj = nil
self.publisher = nil
end
end

0 comments on commit 1782bb3

Please sign in to comment.