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

pulibrary / pdc_describe / 25744549-a0ce-4a94-be72-211b26360e47

04 Apr 2024 02:57PM UTC coverage: 95.316% (-0.5%) from 95.842%
25744549-a0ce-4a94-be72-211b26360e47

Pull #1739

circleci

JaymeeH
changing routes so that the next button on additional metadata goes to the readme
figuring out how to show the second pane by default for the additional metadata
Pull Request #1739: 1684 additional step

10 of 10 new or added lines in 1 file covered. (100.0%)

20 existing lines in 4 files now uncovered.

3215 of 3373 relevant lines covered (95.32%)

187.21 hits per line

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

95.77
/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"]
4,554✔
14
        family_name = creator["family_name"]
4,554✔
15
        orcid = creator.dig("identifier", "scheme") == "ORCID" ? creator.dig("identifier", "value") : nil
4,554✔
16
        sequence = (creator["sequence"] || "").to_i
4,554✔
17
        pdc_creator = PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence)
4,554✔
18
        pdc_creator.affiliations = (creator["affiliations"])&.map do |affiliation|
4,554✔
19
          PDCMetadata::Affiliation.new(value: affiliation["value"], identifier: affiliation["identifier"],
7✔
20
                                       scheme: affiliation["scheme"], scheme_uri: affiliation["scheme_uri"])
21
        end
22
        pdc_creator
4,554✔
23
      end
24

25
      def individual_contributor_from_hash(contributor)
1✔
26
        given_name = contributor["given_name"]
25✔
27
        family_name = contributor["family_name"]
25✔
28
        orcid = contributor.dig("identifier", "scheme") == "ORCID" ? contributor.dig("identifier", "value") : nil
25✔
29
        sequence = (contributor["sequence"] || "").to_i
25✔
30
        type = contributor["type"]
25✔
31
        PDCMetadata::Creator.new_individual_contributor(given_name, family_name, orcid, type, sequence)
25✔
32
      end
33

34
      def organizational_contributor_from_hash(contributor)
1✔
35
        value = contributor["value"]
4✔
36
        ror = contributor.dig("identifier", "scheme") == "ROR" ? contributor.dig("identifier", "value") : nil
4✔
37
        type = contributor["type"]
4✔
38
        PDCMetadata::Creator.new_organizational_contributor(value, ror, type)
4✔
39
      end
40
    end
41

42
    # rubocop:disable Metrics/ParameterLists
43
    def initialize(value: nil, name_type: nil, given_name: nil, family_name: nil, identifier: nil, sequence: 0, affiliations: [])
1✔
44
      @value = value&.strip
5,417✔
45
      @name_type = name_type&.strip
5,417✔
46
      @given_name = given_name&.strip
5,417✔
47
      @family_name = family_name&.strip
5,417✔
48
      @identifier = identifier&.strip
5,417✔
49
      @affiliations = affiliations
5,417✔
50
      @sequence = sequence
5,417✔
51
    end
52
    # rubocop:enable Metrics/ParameterLists
53

54
    def orcid_url
1✔
55
      identifier&.orcid_url
201✔
56
    end
57

58
    def orcid
1✔
59
      identifier&.orcid
2,597✔
60
    end
61

62
    def ror_url
1✔
63
      identifier&.ror_url
×
64
    end
65

66
    def ror
1✔
67
      identifier&.ror
2✔
68
    end
69

70
    def compare_value
1✔
71
      "#{value} | #{sequence} | #{type} | #{affiliations.map(&:compare_value).join(',')} | #{orcid_url}"
200✔
72
    end
73

74
    def affiliation
1✔
75
      return "" if affiliations.empty?
570✔
UNCOV
76
      affiliations.first.value
×
77
    end
78

79
    def affiliation_ror
1✔
80
      ror_affiliations = affiliations.select { |affiliation| affiliation.scheme == "ROR" }
319✔
81
      return "" if ror_affiliations.empty?
319✔
UNCOV
82
      ror_affiliations.first.identifier
×
83
    end
84

85
    def self.new_person(given_name, family_name, orcid_id = nil, sequence = 0, ror: nil, affiliation: nil)
1✔
86
      full_name = "#{family_name&.strip}, #{given_name&.strip}"
5,411✔
87
      creator = Creator.new(value: full_name, name_type: "Personal", given_name:, family_name:, sequence:)
5,411✔
88
      if orcid_id.present?
5,411✔
89
        creator.identifier = NameIdentifier.new_orcid(orcid_id.strip)
120✔
90
      end
91
      if affiliation.present? || ror.present?
5,411✔
92
        creator.affiliations << Affiliation.new_affiliation(value: affiliation, ror:)
1✔
93
      end
94
      creator
5,411✔
95
    end
96

97
    def self.new_individual_contributor(given_name, family_name, orcid_id, type, sequence)
1✔
98
      contributor = new_person(given_name, family_name, orcid_id, sequence)
46✔
99
      contributor.type = type
46✔
100
      contributor
46✔
101
    end
102

103
    def self.new_organization(value, ror = nil)
1✔
104
      creator = Creator.new(value:, name_type: "Organizational")
5✔
105
      if ror.present?
5✔
106
        creator.identifier = NameIdentifier.new_ror(ror.strip)
5✔
107
      end
108
      creator
5✔
109
    end
110

111
    def self.new_organizational_contributor(value, ror, type)
1✔
112
      contributor = new_organization(value, ror)
5✔
113
      contributor.type = type
5✔
114
      contributor
5✔
115
    end
116
  end
117
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