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

pulibrary / orangelight / 53a3144e-730b-483e-ac61-e4a67075b9ae

22 Jul 2025 06:25PM UTC coverage: 95.157%. Remained the same
53a3144e-730b-483e-ac61-e4a67075b9ae

Pull #5023

circleci

Ryan Jensen
Reduce size of call number to '--font-size-small'
Pull Request #5023: 5021.2 call num reduction

6071 of 6380 relevant lines covered (95.16%)

1514.0 hits per line

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

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

3
class OnlineHoldingsMarkupBuilder < HoldingRequestsBuilder
3✔
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)
3✔
9
    children = content_tag(
×
10
      :span, 'Link Missing',
11
      class: 'lux-text-style gray'
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)
3✔
27
    markup = if /Open access/.match? texts.first
50✔
28
               link_to(texts.first, url.to_s, target: '_blank', rel: 'noopener')
2✔
29
             elsif %r{(\/catalog\/.+?#view)} =~ url.to_s
48✔
30
               if texts.first == "arks.princeton.edu"
13✔
31
                 link_to('Digital content', ::Regexp.last_match(0))
1✔
32
               else
33
                 link_to(texts.first, ::Regexp.last_match(0))
12✔
34
               end
35
             else
36
               link_text = new_tab_icon(texts.first)
35✔
37
               link_to(link_text, EzProxyService.ez_proxy_url(url), target: '_blank', rel: 'noopener')
35✔
38
             end
39
    markup
50✔
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)
3✔
46
    if /go\.galegroup\.com.+?%257C/.match? url
46✔
47
      URI.decode_www_form_component(url)
1✔
48
    else
49
      url
45✔
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)
3✔
60
    markup = ''
112✔
61

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

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

73
    return content_tag(:ul, markup.html_safe) if electronic_access.many?
112✔
74
    markup
102✔
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)
3✔
82
    markup = ''
108✔
83

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

97
    markup
105✔
98
  end
99

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

105
  # Constructor
106
  # @param adapter [HoldingRequestsAdapter] adapter for the SolrDocument and Bibdata API
107
  def initialize(adapter)
3✔
108
    @adapter = adapter
107✔
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
3✔
114
    online_holdings_block
107✔
115
  end
116

117
  private
3✔
118

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

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

128
      if electronic_access_links.empty?
107✔
129
        elf_holdings.each_key do |holding_id|
76✔
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)
107✔
136

137
      markup
107✔
138
    end
139

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