• 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/models/requests/requestable.rb
1
# frozen_string_literal: true
2
module Requests
×
3
  # This class describes a resource that a
4
  # library patron might wish to request
5
  class Requestable
×
6
    attr_reader :bib
×
7
    attr_reader :holding
×
8
    attr_reader :item
×
9
    attr_reader :location
×
10
    attr_reader :call_number
×
11
    attr_reader :title
×
12
    attr_reader :patron
×
13
    attr_reader :services
×
14

15
    delegate :illiad_request_url, :illiad_request_parameters, to: :@illiad
×
16
    delegate :eligible_for_library_services?, to: :@patron
×
17

18
    include Requests::Aeon
×
19

20
    # @param bib [Hash] Solr Document of the Top level Request
21
    # @param holding [Requests::Holding] Bibdata information on where the item is held, created with data from the parsed solr_document[holdings_1display] json
22
    # @param item [Hash] Item level data from bib data (https://bibdata.princeton.edu/availability?id= or mfhd=)
23
    # @param location [Hash] The hash for a bib data holding (https://bibdata.princeton.edu/locations/holding_locations)
24
    # @param patron [Patron] the patron information about the current user
25
    def initialize(bib:, holding: nil, item: nil, location: nil, patron:)
×
26
      @bib = bib
×
27
      @holding = holding
×
28
      # Item inherits from SimpleDelegator which requires at least one argument
29
      # The argument is the Object that SimpleDelegator will delegate to.
30
      @item = item.present? ? Item.new(item) : NullItem.new({})
×
31
      @location = location
×
32
      @services = []
×
33
      @patron = patron
×
34
      @call_number = @holding.holding_data['call_number_browse']
×
35
      @title = bib[:title_citation_display]&.first
×
36
      @illiad = Requests::Illiad.new(enum: item&.fetch(:enum, nil), chron: item&.fetch(:chron, nil), call_number:)
×
37
    end
×
38

39
    delegate :pick_up_location_code, :item_type, :enum_value, :cron_value, :item_data?,
×
40
             :temp_loc_other_than_resource_sharing?, :on_reserve?, :enumerated?, :item_type_non_circulate?, :partner_holding?,
×
41
             :id, :use_statement, :collection_code, :charged?, :status, :status_label, :barcode?, :barcode, :preservation_conservation?, to: :item
×
42

43
    delegate :annex?, :location_label, to: :location_object
×
44

45
    delegate :thesis?, to: :@holding
×
46

47
    delegate :numismatics?, to: :@holding
×
48

49
    # Reading Room Request
50
    def aeon?
×
51
      location_object.aeon? || (use_statement == 'Supervised Use')
×
52
    end
×
53

54
    def recap?
×
55
      return false unless location_valid?
×
56
      location_object.recap?
×
57
    end
×
58

59
    def recap_pf?
×
60
      return false unless recap?
×
61
      location_object.code == "firestone$pf"
×
62
    end
×
63

64
    def clancy_available?
×
65
      item_at_clancy? && clancy_item.available?
×
66
    end
×
67

68
    def recap_edd?
×
69
      return location[:recap_electronic_delivery_location] == true unless partner_holding?
×
70
      in_scsb_edd_collection? && !scsb_in_library_use?
×
71
    end
×
72

73
    def preservation?
×
74
      location_object.code == 'pres'
×
75
    end
×
76

77
    def circulates?
×
78
      item_type_non_circulate? == false && location[:circulates] == true
×
79
    end
×
80

81
    def location_code
×
82
      location_object.code
×
83
    end
×
84

85
    def always_requestable?
×
86
      location[:always_requestable] == true
×
87
    end
×
88

89
    def use_restriction?
×
90
      partner_holding? && use_statement.present?
×
91
    end
×
92

93
    def in_process?
×
94
      return false if !item? || partner_holding?
×
95
      in_process_statuses.include?(item[:status_label])
×
96
    end
×
97

98
    def on_order?
×
99
      return false unless item? && !partner_holding?
×
100
      item[:status_label] == 'Acquisition'
×
101
    end
×
102

103
    def item?
×
104
      item.present?
×
105
    end
×
106

107
    def pending?
×
108
      return false unless location_valid?
×
109
      return false unless on_order? || in_process? || preservation?
×
110
      location[:library][:code] != 'recap' || location[:holding_library].present?
×
111
    end
×
112

113
    def ill_eligible?
×
114
      services.include?('ill')
×
115
    end
×
116

117
    def on_shelf?
×
118
      services.include?('on_shelf')
×
119
    end
×
120

121
    # assume numeric ids come from alma
122
    def alma_managed?
×
123
      bib[:id].to_i.positive?
×
124
    end
×
125

126
    def pick_up_locations
×
127
      return nil if location[:delivery_locations].empty?
×
128
      if partner_holding?
×
129
        scsb_pick_up_override(item[:collection_code])
×
130
      else
×
131
        location[:delivery_locations]
×
132
      end
×
133
    end
×
134

135
    # override the default delivery location for SCSB at certain collection codes
136
    def scsb_pick_up_override(collection_code)
×
137
      if ['AR', 'FL'].include? collection_code
×
138
        [Requests::BibdataService.delivery_locations[:PJ]]
×
139
      elsif collection_code == 'MR'
×
140
        [Requests::BibdataService.delivery_locations[:PK]]
×
141
      else
×
142
        location[:delivery_locations]
×
143
      end
×
144
    end
×
145

146
    def scsb_in_library_use?
×
147
      return false unless item?
×
148
      partner_holding? && (item[:use_statement] == "In Library Use" || collection_code == 'FL')
×
149
    end
×
150

151
    def holding_library_in_library_only?
×
152
      return false unless location["holding_library"]
×
153
      ["marquand", "lewis"].include?(holding_library) || recap_pf?
×
154
    end
×
155

156
    def holding_library
×
157
      location_object.holding_library&.dig(:code) || library_code
×
158
    end
×
159

160
    def ask_me?
×
161
      services.include?('ask_me')
×
162
    end
×
163

164
    def item_location_code
×
165
      item&.location || location_object.code
×
166
    end
×
167

168
    def held_at_marquand_library?
×
169
      library_code == 'marquand' && !recap?
×
170
    end
×
171

172
    def marquand_item?
×
173
      holding_library == 'marquand'
×
174
    end
×
175

176
    def clancy_item
×
177
      @clancy_item ||= Requests::ClancyItem.new(barcode:)
×
178
    end
×
179

180
    def item_at_clancy?
×
181
      held_at_marquand_library? && clancy_item.at_clancy?
×
182
    end
×
183

184
    def available?
×
185
      (always_requestable? && !held_at_marquand_library?) || item.available?
×
186
    end
×
187

188
    def cul_avery?
×
189
      item&.collection_code == 'AR'
×
190
    end
×
191

192
    def cul_music?
×
193
      item&.collection_code == 'MR'
×
194
    end
×
195

196
    def hl_art?
×
197
      item&.collection_code == 'FL'
×
198
    end
×
199

200
    def replace_existing_services(new_services)
×
201
      @services = new_services
×
202
    end
×
203

204
    private
×
205

206
      # Location data presented as an object, rather than a hash.
207
      # The goal is to gradually replace all uses of the hash with
208
      # this object, so that other classes don't need to know the
209
      # exact hash keys to use in order to get the needed data.
210
      def location_object
×
211
        @location_object ||= Location.new location
×
212
      end
×
213

214
      delegate :library_code, to: :location_object
×
215

216
      def in_scsb_edd_collection?
×
217
        scsb_edd_collection_codes =
×
218
          %w[AR BR CA CH CJ CP CR CU EN EV GC GE GS HS JC JD LD LE ML SW UT NA NH NL NP NQ NS NW GN JN JO PA PB PN GP JP] +
×
219
          %w[AH DL FL GUT HB HC HJ HK HL HS HW HY MCZ ML TZ WL] # Harvard collections available to digitize
×
220
        scsb_edd_collection_codes.include?(collection_code)
×
221
      end
×
222

223
      def location_valid?
×
224
        location_object.valid?
×
225
      end
×
226

227
      def in_process_statuses
×
228
        ["Acquisition technical services", "Acquisitions and Cataloging", "In Process"]
×
229
      end
×
230
  end
×
231
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