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

pulibrary / bibdata / 1dcebae2-3318-4e77-bc53-82276e293354

02 May 2025 04:45PM UTC coverage: 28.256% (-63.9%) from 92.189%
1dcebae2-3318-4e77-bc53-82276e293354

push

circleci

sandbergja
Add basic infrastructure for compiling rust code

* Add a rake compile task to compile
* Run the rake task in CI
* Run the rake task before rspec tests with the rust tag, to provide quick feedback on rust changes in TDD cycles

2 of 7 new or added lines in 2 files covered. (28.57%)

2467 existing lines in 97 files now uncovered.

1089 of 3854 relevant lines covered (28.26%)

0.29 hits per line

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

29.63
/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✔
UNCOV
14
    @bib_id = bib_id
×
UNCOV
15
    @holding_id = holding_id
×
UNCOV
16
    @url_key = url_key
×
UNCOV
17
    @z_label = z_label
×
UNCOV
18
    @anchor_text = anchor_text
×
UNCOV
19
    @logger = logger
×
UNCOV
20
    process_url_key!
×
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✔
UNCOV
27
    default_link_args = { bib_id: @bib_id, holding_id: @holding_id, url_key: @url_key, z_label: @z_label, anchor_text: @anchor_text }
×
UNCOV
28
    new_link_args = default_link_args.merge link_args
×
UNCOV
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✔
UNCOV
36
    return unless @url_key
×
UNCOV
37
    return @url if @url
×
38

UNCOV
39
    if @url_key.valid_encoding?
×
UNCOV
40
      @url_key = normal_url.to_s
×
UNCOV
41
      if !@url_key&.match?(URI::DEFAULT_PARSER.make_regexp)
×
UNCOV
42
        @logger.error "#{@bib_id} - invalid URL for 856$u value: #{@url_key}"
×
UNCOV
43
        @url_key = nil
×
UNCOV
44
      elsif @url_key.start_with?(%r{http:/[A-Za-z]})
×
45
        # Misleading URL "http:/" instead of "http://"
UNCOV
46
        @logger.error "#{@bib_id} - invalid URL for 856$u value (http:/): #{@url_key}"
×
UNCOV
47
        @url_key = nil
×
48
      else
UNCOV
49
        @url = URI.parse(@url_key)
×
50
      end
51
    else
UNCOV
52
      @logger.error "#{@bib_id} - invalid character encoding for 856$u value (invalid bytes replaced by *): #{@url_key.scrub('*')}"
×
UNCOV
53
      @url_key = nil
×
54
    end
55
  rescue URI::InvalidURIError
UNCOV
56
    @logger.error "#{@bib_id} - invalid URL for 856$u value: #{@url_key}"
×
UNCOV
57
    @url_key = nil
×
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...
UNCOV
64
    return unless ark_class.princeton_ark? url: url
×
65

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

70
  # Generates the labels for the link markup
71
  # @return [Array<String>]
72
  def url_labels
1✔
UNCOV
73
    return @url_labels if @url_labels
×
74

75
    # Build the URL
UNCOV
76
    url_labels = [@anchor_text] # anchor text is first element
×
UNCOV
77
    url_labels << @z_label if @z_label # optional 2nd element if z
×
UNCOV
78
    @url_labels = url_labels
×
79
  end
80

81
  private
1✔
82

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

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

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

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

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

111
      # If a valid URL was extracted from the MARC metadata...
UNCOV
112
      return unless url&.host
×
113

UNCOV
114
      @anchor_text = url.host if @anchor_text.blank?
×
115
    end
116
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