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

pulibrary / orangelight / f91a4bf0-7022-4328-960e-9776cc954f37

18 Jul 2025 08:51PM UTC coverage: 95.407% (-0.01%) from 95.419%
f91a4bf0-7022-4328-960e-9776cc954f37

Pull #5008

circleci

sandbergja
Exclude test from CI

It passes locally but not in ci

Co-authored-by: Christina Chortaria <christinach@users.noreply.github.com>
Pull Request #5008: [#4945] Display a holdings groups availability badge if the group is collapsed

6065 of 6357 relevant lines covered (95.41%)

1512.42 hits per line

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

97.44
/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
237✔
12
    @bib_data_service = bib_data_service
237✔
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|
109✔
51
      h.key?('location_code') && h['location_code'].start_with?('elf')
183✔
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|
233✔
59
      h.key?('location_code') && !h['location_code'].start_with?('elf')
380✔
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
108✔
68
      .map { |id, data| Requests::Holding.new(mfhd_id: id, holding_data: data) }
183✔
69
      .group_by(&:full_location_name)
70
      .map { |group_name, holdings| Requests::HoldingGroup.new(group_name:, holdings:) }
150✔
71
  end
72

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

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

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

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

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

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

115
  def temp_location_code(holding)
3✔
116
    holding['temp_location_code']
156✔
117
  end
118

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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