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

pulibrary / orangelight / 62bad3f1-d46d-40af-822c-403d653da2a8

17 Jun 2025 05:30PM UTC coverage: 0.447% (-94.9%) from 95.337%
62bad3f1-d46d-40af-822c-403d653da2a8

push

circleci

maxkadel
Install chrome & chromedriver for smoke specs

43 of 9610 relevant lines covered (0.45%)

0.01 hits per line

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

0.0
/app/services/online_holdings_markup_builder.rb
1
# frozen_string_literal: false
2

3
class OnlineHoldingsMarkupBuilder < HoldingRequestsBuilder
×
4
  # Generate a block of markup for an online holding
5
  # @param bib_id [String] the ID for the SolrDocument
6
  # @param holding_id [String] the ID for the holding
7
  # @return [String] the markup
8
  def self.online_link(bib_id, holding_id)
×
9
    children = content_tag(
×
10
      :span, 'Link Missing',
×
11
      class: 'availability-icon badge bg-secondary'
×
12
    )
×
13
    # AJAX requests are made using availability.js here
14
    content_tag(:div, children.html_safe,
×
15
                class: 'holding-block',
×
16
                data: {
×
17
                  availability_record: true,
×
18
                  record_id: bib_id,
×
19
                  holding_id:
×
20
                })
×
21
  end
×
22

23
  # Generate the link for electronic access information within a record
24
  # @param url [String] the URL to the service endpoint
25
  # @param text [String] the label for the link
26
  def self.electronic_access_link(url, texts)
×
27
    markup = if /Open access/.match? texts.first
×
28
               link_to(texts.first, url.to_s, target: '_blank', rel: 'noopener')
×
29
             elsif %r{(\/catalog\/.+?#view)} =~ url.to_s
×
30
               if texts.first == "arks.princeton.edu"
×
31
                 link_to('Digital content', ::Regexp.last_match(0))
×
32
               else
×
33
                 link_to(texts.first, ::Regexp.last_match(0))
×
34
               end
×
35
             else
×
36
               link_text = new_tab_icon(texts.first)
×
37
               link_to(link_text, EzProxyService.ez_proxy_url(url), target: '_blank', rel: 'noopener')
×
38
             end
×
39
    markup
×
40
  end
×
41

42
  # Method for cleaning URLs
43
  # @param url [String] the URL for an online holding
44
  # @return [String] the cleaned URL
45
  def self.clean_url(url)
×
46
    if /go\.galegroup\.com.+?%257C/.match? url
×
47
      URI.decode_www_form_component(url)
×
48
    else
×
49
      url
×
50
    end
×
51
  end
×
52

53
  # Generate the markup for the electronic access block
54
  # First argument of link_to is optional display text. If null, the second argument
55
  # (URL) is the display text for the link.
56
  # Proxy Base is added to force remote access when appropriate
57
  # @param adapter [HoldingRequestsAdapter] the adapter for Solr and Bibdata
58
  # @return [String] the markup
59
  def self.urlify(adapter)
×
60
    markup = ''
×
61

62
    electronic_access = adapter.doc_electronic_access
×
63
    electronic_access.each do |url, electronic_texts|
×
64
      texts = electronic_texts.flatten
×
65
      url = clean_url(url)
×
66

67
      link = electronic_access_link(url, texts)
×
68
      link = "#{texts[1]}: " + link if texts[1]
×
69
      link = "<li>#{link}</li>" if electronic_access.count > 1
×
70
      markup << content_tag(:li, link.html_safe, class: 'electronic-access')
×
71
    end
×
72

73
    return content_tag(:ul, markup.html_safe) if electronic_access.count > 1
×
74
    markup
×
75
  end
×
76

77
  # Returns electronic portforlio link markup.
78
  # Replaces Umlaut AJAX data when using Alma.
79
  # @param adapter [HoldingRequestsAdapter] the adapter for Solr and Bibdata
80
  # @return [String] the markup
81
  def self.electronic_portfolio_markup(adapter)
×
82
    markup = ''
×
83

84
    portfolios = adapter.electronic_portfolios + adapter.sibling_electronic_portfolios
×
85
    return '' if portfolios.present? && portfolios[0].key?('thesis')
×
86
    portfolios.each do |portfolio|
×
87
      start_date = portfolio['start']
×
88
      end_date = portfolio['end']
×
89
      date_range = "#{start_date} - #{end_date}: " if start_date && end_date
×
90
      label = new_tab_icon("#{date_range}#{portfolio['title']}")
×
91
      link = link_to(label, portfolio["url"], target: '_blank', rel: 'noopener')
×
92
      link += " #{portfolio['desc']}"
×
93
      link = "#{link} (#{portfolio['notes'].join(', ')})" if portfolio['notes']&.any?
×
94
      markup << content_tag(:li, link.html_safe, class: 'electronic-access')
×
95
    end
×
96

97
    markup
×
98
  end
×
99

100
  def self.new_tab_icon(text)
×
101
    text = text.html_safe
×
102
    text + content_tag(:i, "", class: "fa fa-external-link new-tab-icon-padding", "aria-label": "opens in new tab", role: "img")
×
103
  end
×
104

105
  # Constructor
106
  # @param adapter [HoldingRequestsAdapter] adapter for the SolrDocument and Bibdata API
107
  def initialize(adapter)
×
108
    @adapter = adapter
×
109
  end
×
110

111
  # Builds the markup for online and physical holdings for a given record
112
  # @return [Array<String>] the markup for the online and physical holdings
113
  def build
×
114
    online_holdings_block
×
115
  end
×
116

117
  private
×
118

119
    # Generate the markup for the online holdings
120
    # @return [String] the markup
121
    def online_holdings
×
122
      markup = ''
×
123

124
      electronic_access_links = self.class.urlify(@adapter)
×
125
      markup << electronic_access_links
×
126
      elf_holdings = @adapter.doc_holdings_elf
×
127

128
      if electronic_access_links.empty?
×
129
        elf_holdings.each_key do |holding_id|
×
130
          markup << self.class.online_link(@adapter.doc_id, holding_id)
×
131
        end
×
132
      end
×
133

134
      # For Alma records, add links from the electronic portfolio field
135
      markup << self.class.electronic_portfolio_markup(@adapter)
×
136

137
      markup
×
138
    end
×
139

140
    # Generate the markup for the online holdings block
141
    # @return [String] the markup
142
    def online_holdings_block
×
143
      markup = ''
×
144
      children = online_holdings
×
145
      markup = self.class.content_tag(:ul, children.html_safe) unless children.empty?
×
146
      markup
×
147
    end
×
148
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