• 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/holding_requests_adapter.rb
1
# frozen_string_literal: false
2

3
# Adapter for SolrDocument instances and the Bibdata Class
4
class HoldingRequestsAdapter
×
5
  attr_reader :document
×
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)
×
11
    @document = document
×
12
    @bib_data_service = bib_data_service
×
13
  end
×
14

15
  # Retrieve the ID for the Solr Document
16
  # @return [String] the ID value
17
  def doc_id
×
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
×
24

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

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

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

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

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

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

64
  # Retrieve the physical holdings records sorted by location code
65
  # @return [Hash] sorted physical holding information
66
  def sorted_physical_holdings
×
67
    doc_holdings_physical.sort_by do |_id, h|
×
68
      @bib_data_service.holding_locations.keys.index(h['location_code']) || end_of_list
×
69
    end
×
70
  end
×
71

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

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

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

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

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

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

114
  def temp_location_code(holding)
×
115
    holding['temp_location_code']
×
116
  end
×
117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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