-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking out PDCMetadata classes into thier own files
Also removing rubocop violations
- Loading branch information
1 parent
1d5ddf1
commit 4837a8b
Showing
6 changed files
with
170 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
# Class for storing an affiliation in our local representation | ||
module PDCMetadata | ||
# value: "datacite" | ||
# identifier: "https://ror.org/04aj4c181" | ||
# scheme: "ROR" | ||
# scheme_uri: "https://ror.org/" | ||
class Affiliation | ||
attr_accessor :value, :identifier, :scheme, :scheme_uri | ||
def initialize(value: nil, identifier: nil, scheme: nil, scheme_uri: nil) | ||
@value = value | ||
@identifier = identifier | ||
@scheme = scheme | ||
@scheme_uri = scheme_uri | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
# Class for storing a creator in our local representation | ||
module PDCMetadata | ||
# value: "Miller, Elizabeth" | ||
# name_type: "Personal" | ||
# given_name: "Elizabeth" | ||
# family_name: "Miller" | ||
class Creator | ||
attr_accessor :value, :name_type, :given_name, :family_name, :identifier, :affiliations, :sequence | ||
|
||
class << self | ||
def from_hash(creator) | ||
given_name = creator["given_name"] | ||
family_name = creator["family_name"] | ||
orcid = creator.dig("identifier", "scheme") == "ORCID" ? creator.dig("identifier", "value") : nil | ||
sequence = (creator["sequence"] || "").to_i | ||
PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence) | ||
end | ||
end | ||
|
||
# rubocop:disable Metrics/ParameterLists | ||
def initialize(value: nil, name_type: nil, given_name: nil, family_name: nil, identifier: nil, sequence: 0) | ||
@value = value | ||
@name_type = name_type | ||
@given_name = given_name | ||
@family_name = family_name | ||
@identifier = identifier | ||
@affiliations = [] | ||
@sequence = sequence | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
||
def orcid_url | ||
identifier&.orcid_url | ||
end | ||
|
||
def orcid | ||
identifier&.orcid | ||
end | ||
|
||
def self.new_person(given_name, family_name, orcid_id = nil, sequence = 0) | ||
full_name = "#{family_name}, #{given_name}" | ||
creator = Creator.new(value: full_name, name_type: "Personal", given_name: given_name, family_name: family_name, sequence: sequence) | ||
if orcid_id.present? | ||
creator.identifier = NameIdentifier.new_orcid(orcid_id.strip) | ||
end | ||
creator | ||
end | ||
|
||
def to_xml(builder) | ||
if name_type == "Personal" | ||
builder.creator("nameType" => "Personal") do | ||
builder.creatorName value | ||
builder.givenName given_name | ||
builder.familyName family_name | ||
identifier&.to_xml(builder) | ||
end | ||
else | ||
builder.creator("nameType" => "Organization") do | ||
builder.creatorName value | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
# Class for storing a named identifier for the creator in our local representation. This identifier can be a person or organization. | ||
# **Please Note:** | ||
# The class name NameIdentifier is being utilized becuase it matches with the DataCite Schema: https://support.datacite.org/docs/datacite-metadata-schema-v44-mandatory-properties#24-nameidentifier | ||
# It also matches with the DaCite xml mapping gem that we are utilizing: https://github.com/CDLUC3/datacite-mapping/blob/master/lib/datacite/mapping/name_identifier.rb | ||
module PDCMetadata | ||
# value: "0000-0001-5000-0007" | ||
# scheme: "ORCID" | ||
# scheme_uri: "https://orcid.org/"" | ||
class NameIdentifier | ||
attr_accessor :value, :scheme, :scheme_uri | ||
def initialize(value: nil, scheme: nil, scheme_uri: nil) | ||
@value = value | ||
@scheme = scheme | ||
@scheme_uri = scheme_uri | ||
end | ||
|
||
def orcid_url | ||
return nil unless scheme == "ORCID" | ||
"#{scheme_uri}/#{value}" | ||
end | ||
|
||
def orcid | ||
return nil unless scheme == "ORCID" | ||
value | ||
end | ||
|
||
# Convenience method since this is the most common (only?) identifier that we are currently supporting | ||
def self.new_orcid(value) | ||
NameIdentifier.new(value: value, scheme: "ORCID", scheme_uri: "https://orcid.org") | ||
end | ||
|
||
def to_xml(builder) | ||
builder.nameIdentifier( | ||
"schemeURI" => scheme_uri, | ||
"nameIdentifierScheme" => scheme | ||
) do | ||
builder.text value | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
# Class for storing a title in our local representation | ||
module PDCMetadata | ||
# value: "100 años de soledad" | ||
# title_type: "TranslatedTitle" | ||
class Title | ||
attr_accessor :title, :title_type | ||
def initialize(title:, title_type: nil) | ||
@title = title | ||
@title_type = title_type | ||
end | ||
|
||
def main? | ||
@title_type.blank? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters