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

pulibrary / bibdata / 97cbe92d-c54f-45de-a4c8-e506299fcc4d

21 Dec 2023 09:42PM UTC coverage: 90.834% (-0.5%) from 91.287%
97cbe92d-c54f-45de-a4c8-e506299fcc4d

Pull #2284

circleci

sandbergja
Upgrade old gem dependencies

Removes the rerun gem, since it is no longer used.  Also, remove some leftover files from the spring gem.
Pull Request #2284: Upgrade old gem dependencies

3409 of 3753 relevant lines covered (90.83%)

334.45 hits per line

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

94.44
/marc_to_solr/lib/electronic_access_link.rb
1
require_relative 'normal_uri_factory'
1✔
2
require_relative 'uri_ark'
1✔
3

4
class ElectronicAccessLink
1✔
5
  attr_reader :bib_id, :holding_id, :url_key, :z_label, :anchor_text
1✔
6

7
  # Constructor
8
  # @param bib_id Bib record ID for an electronic holding referencing the linked resource
9
  # @param holding_id Holding record ID for an electronic holding referencing the linked resource
10
  # @param url_key the URL for the resource serving as a key
11
  # @param z_label the label for the resource link
12
  # @param anchor_text the text for the link markup (<a> element)
13
  def initialize(bib_id:, holding_id:, url_key:, z_label:, anchor_text:, logger: Logger.new(STDOUT))
1✔
14
    @bib_id = bib_id
53✔
15
    @holding_id = holding_id
53✔
16
    @url_key = url_key
53✔
17
    @z_label = z_label
53✔
18
    @anchor_text = anchor_text
53✔
19
    @logger = logger
53✔
20
    process_url_key!
53✔
21
  end
22

23
  # Clones a new instance of the ElectronicAccessLink
24
  # @param link_args arguments which override the attributes for this instance
25
  # @return [ElectronicAccessLink]
26
  def clone(link_args)
1✔
27
    default_link_args = { bib_id: @bib_id, holding_id: @holding_id, url_key: @url_key, z_label: @z_label, anchor_text: @anchor_text }
×
28
    new_link_args = default_link_args.merge link_args
×
29
    self.class.new(**new_link_args)
×
30
  end
31
  alias dup clone
1✔
32

33
  # Generates the URL from the string URL key
34
  # @return [URI::Generic]
35
  def url
1✔
36
    return unless @url_key
176✔
37
    return @url if @url
172✔
38

39
    if !@url_key.valid_encoding?
52✔
40
      @logger.error "#{@bib_id} - invalid character encoding for 856$u value (invalid bytes replaced by *): #{@url_key.scrub('*')}"
2✔
41
      @url_key = nil
2✔
42
    else
43
      @url_key = normal_url.to_s
50✔
44
      if !@url_key&.match?(URI.regexp)
49✔
45
        @logger.error "#{@bib_id} - invalid URL for 856$u value: #{@url_key}"
2✔
46
        @url_key = nil
2✔
47
      elsif @url_key.start_with?(/http:\/[A-Za-z]/)
47✔
48
        # Misleading URL "http:/" instead of "http://"
49
        @logger.error "#{@bib_id} - invalid URL for 856$u value (http:/): #{@url_key}"
2✔
50
        @url_key = nil
2✔
51
      else
52
        @url = URI.parse(@url_key)
45✔
53
      end
54
    end
55
  rescue URI::InvalidURIError
56
    @logger.error "#{@bib_id} - invalid URL for 856$u value: #{@url_key}"
1✔
57
    @url_key = nil
1✔
58
  end
59

60
  # Generates the ARK from the string URL key
61
  # @return [URI::ARK]
62
  def ark
1✔
63
    # If the URL is a valid ARK...
64
    return unless ark_class.princeton_ark? url: url
76✔
65

66
    # Cast the URL into an ARK
67
    @ark ||= ark_class.parse url:
43✔
68
  end
69

70
  # Generates the labels for the link markup
71
  # @return [Array<String>]
72
  def url_labels
1✔
73
    return @url_labels if @url_labels
107✔
74
    # Build the URL
75
    url_labels = [@anchor_text] # anchor text is first element
43✔
76
    url_labels << @z_label if @z_label # optional 2nd element if z
43✔
77
    @url_labels = url_labels
43✔
78
  end
79

80
  private
1✔
81

82
    # Accesses the Class used for URL normalization
83
    # @return [Class]
84
    def url_normalizer_factory_klass
1✔
85
      NormalUriFactory
50✔
86
    end
87

88
    # Constructs or accesses an instance of the URL normalizer
89
    # @return [NormalUriFactory]
90
    def url_normalizer_factory
1✔
91
      @url_normalizer ||= url_normalizer_factory_klass.new(value: @url_key)
50✔
92
    end
93

94
    # Constructs or accesses the normalized URL
95
    # @return [URI::Generic]
96
    def normal_url
1✔
97
      @normal_url ||= url_normalizer_factory.build
50✔
98
    end
99

100
    # Accesses the Class used for modeling ARKs
101
    # @return [Class]
102
    def ark_class
1✔
103
      URI::ARK
91✔
104
    end
105

106
    # Updates the object state based upon the url_key value
107
    def process_url_key!
1✔
108
      return unless @url_key
53✔
109

110
      # If a valid URL was extracted from the MARC metadata...
111
      return unless url&.host
52✔
112
      @anchor_text = url.host if @anchor_text.blank?
42✔
113
    end
114
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