Class: PDCMetadata::Creator
- Inherits:
-
Object
- Object
- PDCMetadata::Creator
- Defined in:
- app/models/pdc_metadata/creator.rb
Overview
value: “Miller, Elizabeth” name_type: “Personal” given_name: “Elizabeth” family_name: “Miller”
Instance Attribute Summary collapse
-
#affiliations ⇒ Object
Returns the value of attribute affiliations.
-
#family_name ⇒ Object
Returns the value of attribute family_name.
-
#given_name ⇒ Object
Returns the value of attribute given_name.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#name_type ⇒ Object
Returns the value of attribute name_type.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .from_hash(creator) ⇒ Object
- .individual_contributor_from_hash(contributor) ⇒ Object
- .new_individual_contributor(given_name, family_name, orcid_id, type, sequence) ⇒ Object
- .new_organization(value, ror = nil) ⇒ Object
- .new_organizational_contributor(value, ror, type) ⇒ Object
- .new_person(given_name, family_name, orcid_id = nil, sequence = 0, ror: nil, affiliation: nil) ⇒ Object
- .organizational_contributor_from_hash(contributor) ⇒ Object
Instance Method Summary collapse
- #affiliation ⇒ Object
- #affiliation_ror ⇒ Object
- #compare_value ⇒ Object
-
#initialize(value: nil, name_type: nil, given_name: nil, family_name: nil, identifier: nil, sequence: 0, affiliations: []) ⇒ Creator
constructor
rubocop:disable Metrics/ParameterLists.
- #orcid ⇒ Object
-
#orcid_url ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #ror ⇒ Object
- #ror_url ⇒ Object
Constructor Details
#initialize(value: nil, name_type: nil, given_name: nil, family_name: nil, identifier: nil, sequence: 0, affiliations: []) ⇒ Creator
rubocop:disable Metrics/ParameterLists
43 44 45 46 47 48 49 50 51 |
# File 'app/models/pdc_metadata/creator.rb', line 43 def initialize(value: nil, name_type: nil, given_name: nil, family_name: nil, identifier: nil, sequence: 0, affiliations: []) @value = value&.strip @name_type = name_type&.strip @given_name = given_name&.strip @family_name = family_name&.strip @identifier = identifier&.strip @affiliations = affiliations @sequence = sequence end |
Instance Attribute Details
#affiliations ⇒ Object
Returns the value of attribute affiliations.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def affiliations @affiliations end |
#family_name ⇒ Object
Returns the value of attribute family_name.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def family_name @family_name end |
#given_name ⇒ Object
Returns the value of attribute given_name.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def given_name @given_name end |
#identifier ⇒ Object
Returns the value of attribute identifier.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def identifier @identifier end |
#name_type ⇒ Object
Returns the value of attribute name_type.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def name_type @name_type end |
#sequence ⇒ Object
Returns the value of attribute sequence.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def sequence @sequence end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'app/models/pdc_metadata/creator.rb', line 9 def value @value end |
Class Method Details
.from_hash(creator) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/pdc_metadata/creator.rb', line 12 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 pdc_creator = PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence) pdc_creator.affiliations = (creator["affiliations"])&.map do |affiliation| PDCMetadata::Affiliation.new(value: affiliation["value"], identifier: affiliation["identifier"], scheme: affiliation["scheme"], scheme_uri: affiliation["scheme_uri"]) end pdc_creator end |
.individual_contributor_from_hash(contributor) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/models/pdc_metadata/creator.rb', line 25 def individual_contributor_from_hash(contributor) given_name = contributor["given_name"] family_name = contributor["family_name"] orcid = contributor.dig("identifier", "scheme") == "ORCID" ? contributor.dig("identifier", "value") : nil sequence = (contributor["sequence"] || "").to_i type = contributor["type"] PDCMetadata::Creator.new_individual_contributor(given_name, family_name, orcid, type, sequence) end |
.new_individual_contributor(given_name, family_name, orcid_id, type, sequence) ⇒ Object
97 98 99 100 101 |
# File 'app/models/pdc_metadata/creator.rb', line 97 def self.new_individual_contributor(given_name, family_name, orcid_id, type, sequence) contributor = new_person(given_name, family_name, orcid_id, sequence) contributor.type = type contributor end |
.new_organization(value, ror = nil) ⇒ Object
103 104 105 106 107 108 109 |
# File 'app/models/pdc_metadata/creator.rb', line 103 def self.new_organization(value, ror = nil) creator = Creator.new(value:, name_type: "Organizational") if ror.present? creator.identifier = NameIdentifier.new_ror(ror.strip) end creator end |
.new_organizational_contributor(value, ror, type) ⇒ Object
111 112 113 114 115 |
# File 'app/models/pdc_metadata/creator.rb', line 111 def self.new_organizational_contributor(value, ror, type) contributor = new_organization(value, ror) contributor.type = type contributor end |
.new_person(given_name, family_name, orcid_id = nil, sequence = 0, ror: nil, affiliation: nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/pdc_metadata/creator.rb', line 85 def self.new_person(given_name, family_name, orcid_id = nil, sequence = 0, ror: nil, affiliation: nil) full_name = "#{family_name&.strip}, #{given_name&.strip}" creator = Creator.new(value: full_name, name_type: "Personal", given_name:, family_name:, sequence:) if orcid_id.present? creator.identifier = NameIdentifier.new_orcid(orcid_id.strip) end if affiliation.present? || ror.present? creator.affiliations << Affiliation.new_affiliation(value: affiliation, ror:) end creator end |
.organizational_contributor_from_hash(contributor) ⇒ Object
34 35 36 37 38 39 |
# File 'app/models/pdc_metadata/creator.rb', line 34 def organizational_contributor_from_hash(contributor) value = contributor["value"] ror = contributor.dig("identifier", "scheme") == "ROR" ? contributor.dig("identifier", "value") : nil type = contributor["type"] PDCMetadata::Creator.new_organizational_contributor(value, ror, type) end |
Instance Method Details
#affiliation ⇒ Object
74 75 76 77 |
# File 'app/models/pdc_metadata/creator.rb', line 74 def affiliation return "" if affiliations.empty? affiliations.first.value end |
#affiliation_ror ⇒ Object
79 80 81 82 83 |
# File 'app/models/pdc_metadata/creator.rb', line 79 def affiliation_ror ror_affiliations = affiliations.select { |affiliation| affiliation.scheme == "ROR" } return "" if ror_affiliations.empty? ror_affiliations.first.identifier end |
#compare_value ⇒ Object
70 71 72 |
# File 'app/models/pdc_metadata/creator.rb', line 70 def compare_value "#{value} | #{sequence} | #{type} | #{affiliations.map(&:compare_value).join(',')} | #{orcid_url}" end |
#orcid ⇒ Object
58 59 60 |
# File 'app/models/pdc_metadata/creator.rb', line 58 def orcid identifier&.orcid end |
#orcid_url ⇒ Object
rubocop:enable Metrics/ParameterLists
54 55 56 |
# File 'app/models/pdc_metadata/creator.rb', line 54 def orcid_url identifier&.orcid_url end |
#ror ⇒ Object
66 67 68 |
# File 'app/models/pdc_metadata/creator.rb', line 66 def ror identifier&.ror end |
#ror_url ⇒ Object
62 63 64 |
# File 'app/models/pdc_metadata/creator.rb', line 62 def ror_url identifier&.ror_url end |