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

pulibrary / orangelight / 945dd592-0499-4eb8-9049-14b44f80dff0

24 Jul 2025 03:43PM UTC coverage: 95.167% (-0.2%) from 95.407%
945dd592-0499-4eb8-9049-14b44f80dff0

Pull #5051

circleci

Ryan Jensen
Fix alignment of availability cards and change media query breakpoint for vertical card display
Pull Request #5051: 5033 adjust search

6085 of 6394 relevant lines covered (95.17%)

1512.86 hits per line

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

92.31
/app/services/holding_requests_adapter.rb
1
# frozen_string_literal: false
2

3
# Adapter for SolrDocument instances and the Bibdata Class
4
class HoldingRequestsAdapter
3✔
5
  attr_reader :document
3✔
6

7
  # Construct the interface for the Solr Document and Bib. Data API
8
  # @param document [SolrDocument]
9
  # @param bib_data_service [Class] Class or singleton used for the bibliographic data service
10
  def initialize(document, bib_data_service)
3✔
11
    @document = document
238✔
12
    @bib_data_service = bib_data_service
238✔
13
  end
14

15
  # Retrieve the ID for the Solr Document
16
  # @return [String] the ID value
17
  def doc_id
3✔
18
    @document.fetch('id')
×
19
  end
20

21
  # Access the holding locations from Bib. Data
22
  # @return [Hash] location hash structure
23
  delegate :holding_locations, to: :@bib_data_service
3✔
24

25
  # Retrieve the holdings information from the Solr Document
26
  # @return [Hash] holdings values
27
  def doc_holdings
3✔
28
    @document.holdings_all_display
342✔
29
  rescue StandardError => error
30
    Rails.logger.warn error
4✔
31
    {}
4✔
32
  end
33

34
  # Retrieve the electronic access information
35
  # @return [String] electronic access value
36
  delegate :doc_electronic_access, to: :@document
3✔
37

38
  # Parse IIIF Manifest links from the electronic access information
39
  # @return [Hash] IIIF Manifests information
40
  delegate :iiif_manifests, to: :@document
3✔
41

42
  # Retrieve the electronic portfolio information
43
  # @return [String] electronic portfolio values
44
  delegate :electronic_portfolios, to: :@document
3✔
45
  delegate :sibling_electronic_portfolios, to: :@document
3✔
46

47
  # Retrieve only the ELF holding records
48
  # @return [Hash] ELF holding information
49
  def doc_holdings_elf
3✔
50
    doc_holdings.select do |_id, h|
108✔
51
      h.key?('location_code') && h['location_code'].start_with?('elf')
181✔
52
    end
53
  end
54

55
  # Retrieve only the records for physical holdings
56
  # @return [Hash] physical holding information
57
  def doc_holdings_physical
3✔
58
    doc_holdings.select do |_id, h|
234✔
59
      h.key?('location_code') && !h['location_code'].start_with?('elf')
384✔
60
    end
61
  end
62
  alias physical_holdings doc_holdings_physical
3✔
63

64
  # Retrieve the physical holdings records grouped by Library and Location
65
  # Returns an array of Requests::HoldingGroup objects
66
  def grouped_physical_holdings
3✔
67
    doc_holdings_physical
110✔
68
      .map { |id, data| Requests::Holding.new(mfhd_id: id, holding_data: data) }
189✔
69
      .group_by(&:full_location_name)
70
      .map { |group_name, holdings| Requests::HoldingGroup.new(group_name:, holdings:) }
156✔
71
      .sort
72
  end
73

74
  # Retrieve the restrictions placed upon physical holdings
75
  # @return [Array<String>]
76
  def restrictions
3✔
77
    doc_holdings_physical.each_value.map { |holding| restrictions_for_holding(holding) }
317✔
78
                         .flatten.compact.uniq
79
  end
80

81
  # Determine whether or not the catalog record is for a periodical
82
  # @return [TrueClass, FalseClass]
83
  def journal?
3✔
84
    @document.fetch('format', []).include?('Journal')
181✔
85
  end
86

87
  # Retrieve the publication date for the catalog record
88
  # @return [String] the date value
89
  def pub_date
3✔
90
    @document.key?('pub_date_start_sort') ? @document['pub_date_start_sort'] : 0
5✔
91
  end
92

93
  # Methods for holding values
94
  # Should these be refactored into static methods
95
  # (or should a decorator be used for holding values?)
96

97
  # Retrieve the location rules from holding values
98
  # @param holding [Hash] the holding values
99
  # @return [Hash] location values
100
  def holding_location_rules(holding)
3✔
101
    loc_code = holding.fetch('location_code', nil)
335✔
102
    return loc_code if loc_code.nil?
335✔
103
    @bib_data_service.holding_locations[loc_code.to_sym]
335✔
104
  end
105

106
  # Generate the label for a location from the holding values
107
  # @param holding [Hash] the holding values
108
  # @return [String] the location label
109
  # Record page location label display
110
  def holding_location_label(holding)
3✔
111
    # location is the information coming from bibdata
112
    location = holding_location_rules(holding)
×
113
    location.nil? ? alma_location_label_display_holding(holding) : alma_location_label_display_bibdata_location(location)
×
114
  end
115

116
  def temp_location_code(holding)
3✔
117
    holding['temp_location_code']
154✔
118
  end
119

120
  # Alma location display on record page using the location info from bibdata.
121
  # This is a location fall back if Javascript does not work.
122
  def alma_location_label_display_bibdata_location(location)
3✔
123
    [location['library']['label'], location['label']].select(&:present?).join(" - ")
×
124
  end
125

126
  # Alma location display on record page using the solr indexed holding
127
  # This is a location fall back if Javascript does not work and bibdata returns nil.
128
  def alma_location_label_display_holding(holding)
3✔
129
    [holding['library'], holding['location']].select(&:present?).join(' - ')
×
130
  end
131

132
  # Retrieve the call number from holding values
133
  # @param holding [Hash] the holding values
134
  # @return [String] the call number
135
  def call_number(holding)
3✔
136
    holding['call_number_browse'] || holding['call_number']
181✔
137
  end
138

139
  # Determine whether or not the holding is for a repository item
140
  # @return [TrueClass, FalseClass]
141
  def repository_holding?(holding)
3✔
142
    holding['dspace'] || holding['location_code'] == 'rare$num'
181✔
143
  end
144

145
  def sc_location_with_suppressed_button?(holding)
3✔
146
    additional_locations = ["rare$xmr", "mudd$scamudd", "rare$xrr", "rare$xgr", "rare$xcr", "mudd$phr"]
181✔
147
    holding['location_code'].start_with?('rare$sca') || additional_locations.include?(holding['location_code'])
181✔
148
  end
149

150
  # Determine whether or not the holding is for a SCSB items with ReCAP
151
  # @return [TrueClass, FalseClass]
152
  def scsb_holding?(holding)
3✔
153
    /^scsb.+/ =~ holding['location_code']
170✔
154
  end
155

156
  # Determine whether or not the holding has no child items
157
  # @return [TrueClass, FalseClass]
158
  def empty_holding?(holding)
3✔
159
    holding['items'].nil?
16✔
160
  end
161

162
  # Retrieve the restrictions for a given holding
163
  # Duplicates PhysicalHoldingsMarkupBuilder.scsb_list
164
  # @param holding [Hash]
165
  def restrictions_for_holding(holding)
3✔
166
    return [] unless holding.key? 'items'
195✔
167
    holding['items'].map { |values| values['use_statement'] }.compact_blank
13,867✔
168
  end
169

170
  # Determine whether or not the holding is explicitly marked as "Unavailable"
171
  # @return [TrueClass, FalseClass]
172
  def unavailable_holding?(holding)
3✔
173
    holding['dspace'] == false
334✔
174
  end
175

176
  # Determine whether or not the holding has a shelving title
177
  # @return [TrueClass, FalseClass]
178
  def shelving_title?(holding)
3✔
179
    !holding['shelving_title'].nil?
181✔
180
  end
181

182
  # Determine whether or not the holding has a location note
183
  # @return [TrueClass, FalseClass]
184
  def location_note?(holding)
3✔
185
    !holding['location_note'].nil?
181✔
186
  end
187

188
  # Determine whether or not the holding features a location
189
  # @return [TrueClass, FalseClass]
190
  def location_has?(holding)
3✔
191
    !holding['location_has'].nil?
181✔
192
  end
193

194
  # Determine whether or not the holding features a supplements note
195
  # @return [TrueClass, FalseClass]
196
  def supplements?(holding)
3✔
197
    holding['supplements']&.compact.present?
181✔
198
  end
199

200
  # Determine whether or not the holding features an index note
201
  # @return [TrueClass, FalseClass]
202
  def indexes?(holding)
3✔
203
    holding['indexes']&.compact.present?
181✔
204
  end
205

206
  # Determine whether or not the holding is for an Alma holding
207
  # @return [TrueClass, FalseClass]
208
  def alma_holding?(holding_id)
3✔
209
    return false if @document.fetch(:id, '').start_with?('SCSB')
181✔
210
    return false if %w[thesis numismatics visuals].include? holding_id
165✔
211
    true
153✔
212
  end
213

214
  # When the holding location code is invalid, the holding should appear last
215
  # @return Integer
216
  def end_of_list
3✔
217
    999
×
218
  end
219
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