• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 9cddc8c7-6fdb-4485-861e-31fa48956593

pending completion
9cddc8c7-6fdb-4485-861e-31fa48956593

Pull #900

circleci

mccalluc
Updates in form come through
Pull Request #900: Suppport organizational contributors

77 of 77 new or added lines in 6 files covered. (100.0%)

1818 of 1836 relevant lines covered (99.02%)

170.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.61
/app/models/pdc_metadata/creator.rb
1
# frozen_string_literal: true
2
# Class for storing a creator in our local representation
3
module PDCMetadata
1✔
4
  # value: "Miller, Elizabeth"
5
  # name_type: "Personal"
6
  # given_name: "Elizabeth"
7
  # family_name: "Miller"
8
  class Creator
1✔
9
    attr_accessor :value, :name_type, :given_name, :family_name, :identifier, :affiliations, :sequence, :type
1✔
10

11
    class << self
1✔
12
      def from_hash(creator)
1✔
13
        given_name = creator["given_name"]
2,682✔
14
        family_name = creator["family_name"]
2,682✔
15
        orcid = creator.dig("identifier", "scheme") == "ORCID" ? creator.dig("identifier", "value") : nil
2,682✔
16
        sequence = (creator["sequence"] || "").to_i
2,682✔
17
        PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence)
2,682✔
18
      end
19

20
      def individual_contributor_from_hash(contributor)
1✔
21
        given_name = contributor["given_name"]
46✔
22
        family_name = contributor["family_name"]
46✔
23
        orcid = contributor.dig("identifier", "scheme") == "ORCID" ? contributor.dig("identifier", "value") : nil
46✔
24
        sequence = (contributor["sequence"] || "").to_i
46✔
25
        type = contributor["type"]
46✔
26
        PDCMetadata::Creator.new_individual_contributor(given_name, family_name, orcid, type, sequence)
46✔
27
      end
28

29
      def organizational_contributor_from_hash(contributor)
1✔
30
        name = contributor["value"]
175✔
31
        ror = contributor.dig("identifier", "scheme") == "ROR" ? contributor.dig("identifier", "value") : nil
175✔
32
        type = contributor["type"]
175✔
33
        PDCMetadata::Creator.new_organizational_contributor(name, ror, type)
175✔
34
      end
35
    end
36

37
    # rubocop:disable Metrics/ParameterLists
38
    def initialize(value: nil, name_type: nil, given_name: nil, family_name: nil, identifier: nil, sequence: 0)
1✔
39
      @value = value
3,507✔
40
      @name_type = name_type
3,507✔
41
      @given_name = given_name
3,507✔
42
      @family_name = family_name
3,507✔
43
      @identifier = identifier
3,507✔
44
      @affiliations = []
3,507✔
45
      @sequence = sequence
3,507✔
46
    end
47
    # rubocop:enable Metrics/ParameterLists
48

49
    def orcid_url
1✔
50
      identifier&.orcid_url
1✔
51
    end
52

53
    def orcid
1✔
54
      identifier&.orcid
1,913✔
55
    end
56

57
    def ror_url
1✔
58
      identifier&.ror_url
×
59
    end
60

61
    def ror
1✔
62
      identifier&.ror
28✔
63
    end
64

65
    def compare_value
1✔
66
      "#{value} | #{sequence} | #{type}"
180✔
67
    end
68

69
    def self.new_person(given_name, family_name, orcid_id = nil, sequence = 0)
1✔
70
      full_name = "#{family_name}, #{given_name}"
3,286✔
71
      creator = Creator.new(value: full_name, name_type: "Personal", given_name: given_name, family_name: family_name, sequence: sequence)
3,286✔
72
      if orcid_id.present?
3,286✔
73
        creator.identifier = NameIdentifier.new_orcid(orcid_id.strip)
68✔
74
      end
75
      creator
3,286✔
76
    end
77

78
    def self.new_individual_contributor(given_name, family_name, orcid_id, type, sequence)
1✔
79
      # TODO: If type is always "Personal", it shouldn't be required as a parameter.
80
      contributor = new_person(given_name, family_name, orcid_id, sequence)
70✔
81
      contributor.type = type
70✔
82
      contributor
70✔
83
    end
84

85
    def self.new_organization(name, ror = nil)
1✔
86
      creator = Creator.new(value: name, name_type: "Organizational")
221✔
87
      if ror.present?
221✔
88
        creator.identifier = NameIdentifier.new_ror(ror.strip)
×
89
      end
90
      creator
221✔
91
    end
92

93
    def self.new_organizational_contributor(name, ror, type)
1✔
94
      # TODO: If type is always "Organizational", it shouldn't be required as a parameter.
95
      contributor = new_organization(name, ror)
221✔
96
      contributor.type = type
221✔
97
      contributor
221✔
98
    end
99
  end
100
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc