-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking out PDCMetadata classes into thier own files #325
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love this!