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

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 relevant lines covered (0.48%)

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 grouped by Library and Location
65
  # Returns an array of Requests::HoldingGroup objects
66
  def grouped_physical_holdings
×
67
    doc_holdings_physical
×
68
      .map { |id, data| Requests::Holding.new(mfhd_id: id, holding_data: data) }
×
69
      .group_by(&:full_location_name)
×
70
      .map { |group_name, holdings| Requests::HoldingGroup.new(group_name:, holdings:) }
×
71
      .sort
×
72
  end
×
73

74
  # Retrieve the restrictions placed upon physical holdings
75
  # @return [Array<String>]
76
  def restrictions
×
77
    doc_holdings_physical.each_value.map { |holding| restrictions_for_holding(holding) }
×
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?
×
84
    @document.fetch('format', []).include?('Journal')
×
85
  end
×
86

87
  # Retrieve the publication date for the catalog record
88
  # @return [String] the date value
89
  def pub_date
×
90
    @document.key?('pub_date_start_sort') ? @document['pub_date_start_sort'] : 0
×
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)
×
101
    loc_code = holding.fetch('location_code', nil)
×
102
    return loc_code if loc_code.nil?
×
103
    @bib_data_service.holding_locations[loc_code.to_sym]
×
104
  end
×
105

106
  def temp_location_code(holding)
×
107
    holding['temp_location_code']
×
108
  end
×
109

110
  # Retrieve the call number from holding values
111
  # @param holding [Hash] the holding values
112
  # @return [String] the call number
113
  def call_number(holding)
×
114
    holding['call_number_browse'] || holding['call_number']
×
115
  end
×
116

117
  # Determine whether or not the holding is for a repository item
118
  # @return [TrueClass, FalseClass]
119
  def repository_holding?(holding)
×
120
    holding['dspace'] || holding['location_code'] == 'rare$num'
×
121
  end
×
122

123
  def sc_location_with_suppressed_button?(holding)
×
124
    additional_locations = ["rare$xmr", "mudd$scamudd", "rare$xrr", "rare$xgr", "rare$xcr", "mudd$phr"]
×
125
    holding['location_code'].start_with?('rare$sca') || additional_locations.include?(holding['location_code'])
×
126
  end
×
127

128
  # Determine whether or not the holding is for a SCSB items with ReCAP
129
  # @return [TrueClass, FalseClass]
130
  def scsb_holding?(holding)
×
131
    /^scsb.+/ =~ holding['location_code']
×
132
  end
×
133

134
  # Determine whether or not the holding has no child items
135
  # @return [TrueClass, FalseClass]
136
  def empty_holding?(holding)
×
137
    holding['items'].nil?
×
138
  end
×
139

140
  # Retrieve the restrictions for a given holding
141
  # Duplicates PhysicalHoldingsMarkupBuilder.scsb_list
142
  # @param holding [Hash]
143
  def restrictions_for_holding(holding)
×
144
    return [] unless holding.key? 'items'
×
145
    holding['items'].map { |values| values['use_statement'] }.compact_blank
×
146
  end
×
147

148
  # Determine whether or not the holding is explicitly marked as "Unavailable"
149
  # @return [TrueClass, FalseClass]
150
  def unavailable_holding?(holding)
×
151
    holding['dspace'] == false
×
152
  end
×
153

154
  # Determine whether or not the holding has a shelving title
155
  # @return [TrueClass, FalseClass]
156
  def shelving_title?(holding)
×
157
    !holding['shelving_title'].nil?
×
158
  end
×
159

160
  # Determine whether or not the holding has a location note
161
  # @return [TrueClass, FalseClass]
162
  def location_note?(holding)
×
163
    !holding['location_note'].nil?
×
164
  end
×
165

166
  # Determine whether or not the holding features a location
167
  # @return [TrueClass, FalseClass]
168
  def location_has?(holding)
×
169
    !holding['location_has'].nil?
×
170
  end
×
171

172
  # Determine whether or not the holding features a supplements note
173
  # @return [TrueClass, FalseClass]
174
  def supplements?(holding)
×
175
    holding['supplements']&.compact.present?
×
176
  end
×
177

178
  # Determine whether or not the holding features an index note
179
  # @return [TrueClass, FalseClass]
180
  def indexes?(holding)
×
181
    holding['indexes']&.compact.present?
×
182
  end
×
183

184
  # Determine whether or not the holding is for an Alma holding
185
  # @return [TrueClass, FalseClass]
186
  def alma_holding?(holding_id)
×
187
    return false if @document.fetch(:id, '').start_with?('SCSB')
×
188
    return false if %w[thesis numismatics visuals].include? holding_id
×
189
    true
×
190
  end
×
191
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