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

pulibrary / pdc_describe / bcfc06e8-a5d8-4369-a72f-de9ecf1ada29

pending completion
bcfc06e8-a5d8-4369-a72f-de9ecf1ada29

Pull #963

circleci

mccalluc
cursor css
Pull Request #963: Add row deletion and reordering to irb tables

1622 of 1848 relevant lines covered (87.77%)

66.84 hits per line

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

60.53
/app/models/ark.rb
1
# frozen_string_literal: true
2
require "ezid-client"
1✔
3

4
class Ark
1✔
5
  EZID_TEST_SHOULDER = "ark:/99999"
1✔
6

7
  # Mints a new EZID identifier, returns the id (e.g. "ark:/99999/fk4tq65d6k")
8
  def self.mint
1✔
9
    identifier = Ezid::Identifier.mint
×
10
    identifier.id
×
11
  end
12

13
  ##
14
  # Ezid::Identifier.find(ezid) only works if the ezid is formatted as an ark,
15
  # e.g., "ark:/99999/abc123"
16
  def self.format_ark(ark)
1✔
17
    return ark if ark.starts_with?("ark:/")
14✔
18
    "ark:/#{ark}"
×
19
  end
20

21
  def self.find(ezid)
1✔
22
    Ezid::Identifier.find(format_ark(ezid))
14✔
23
  rescue StandardError => error
24
    Rails.logger.error("Failed to find the EZID #{ezid}: #{error.class}: #{error.message}")
×
25
    nil
×
26
  end
27

28
  def self.update(ezid, new_url)
1✔
29
    return if ezid.start_with?(EZID_TEST_SHOULDER)
×
30
    identifier = Ezid::Identifier.find(ezid)
×
31
    if identifier.target != new_url
×
32
      identifier.target = new_url
×
33
      identifier.save!
×
34
    end
35
  end
36

37
  # Determines whether or not a given EZID string is a valid ARK
38
  # @param [ezid] [String] the EZID being validated
39
  # @return [Boolean]
40
  def self.valid?(ezid)
1✔
41
    # Always consider test ARKs valid
42
    return true if ezid.start_with?(EZID_TEST_SHOULDER)
15✔
43
    # Try and retrieve the ARK
44
    new(ezid)
14✔
45
    true
14✔
46
  rescue ArgumentError
47
    false
×
48
  end
49

50
  def self.valid_shoulder?(ezid)
1✔
51
    !ezid.include?(self::EZID_TEST_SHOULDER)
14✔
52
  end
53

54
  def initialize(ezid)
1✔
55
    @object = self.class.find(ezid)
14✔
56
    raise(ArgumentError, "Invalid EZID provided for an ARK: #{ezid}") if @object.nil? || !self.class.valid_shoulder?(ezid)
14✔
57
  end
58

59
  def object
1✔
60
    @object ||= self.class.find(ezid)
×
61
  end
62

63
  delegate :id, :metadata, to: :object
1✔
64

65
  def target
1✔
66
    metadata[Ezid::Metadata::TARGET]
×
67
  end
68

69
  def target=(value)
1✔
70
    metadata[Ezid::Metadata::TARGET] = value
×
71
  end
72

73
  def save!
1✔
74
    object.modify(id, metadata)
×
75
  end
76

77
  # ======================
78
  # If in the future we want to update the information of the ARK we can
79
  # implement a few methods as follow:
80
  #
81
  # Update the target URL of the ARK to point to a new URL
82
  # def self.update_target(id, new_url)
83
  #   identifier = Ezid::Identifier.find(id)
84
  #   identifier.target = new_url
85
  #   identifier.save
86
  # end
87
  #
88
  # Update the metadata for an ARK. See https://ezid.cdlib.org/doc/apidoc.html#metadata-profiles
89
  # for details on the profiles supported.
90
  #
91
  # def self.update_metadata(id)
92
  #   metadata = {
93
  #     profile: 'dc',
94
  #     dc_creator: 'somebody',
95
  #     dc_title: 'some title',
96
  #     dc_date: '2022-04-08',
97
  #   }
98
  #   identifier = Ezid::Identifier.modify(id, metadata)
99
  # end
100
  # ======================
101
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