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

3
class StackmapService
×
4
  # A url to the stackmap for the bib record
5
  class Url
×
6
    # Constructor
7
    # @param document [SolrDocument] Solr document for bib record
8
    # @param loc [String] Bib record location code
9
    # @param cn [String] optional provided call number
10
    def initialize(document:, loc:, cn: nil)
×
11
      @document = document
×
12
      @loc = loc
×
13
      @cn = cn
×
14
    end
×
15

16
    # Return the correct stackmap url ased on the location information of the bib record
17
    # @return [String] stackmap url
18
    def url
×
19
      if valid?
×
20
        if StackmapService::Url.missing_stackmap_reserves.include? @loc
×
21
          StackmapService::Url.missing_stackmap_reserves[@loc]
×
22
        elsif stackmap_libs.include? lib
×
23
          stackmap_url
×
24
        else
×
25
          fallback_url
×
26
        end
×
27
      else
×
28
        fallback_url
×
29
      end
×
30
    end
×
31

32
    def preferred_callno
×
33
      if by_title_locations.include? @loc
×
34
        @document['title_display']
×
35
      else
×
36
        @cn || @document['call_number_browse_s']&.first
×
37
      end
×
38
    end
×
39

40
    def location_label
×
41
      return nil if holding_location.nil?
×
42
      holding_location[:label].presence || holding_location[:library][:label]
×
43
    end
×
44

45
    def self.missing_stackmap_reserves
×
46
      {
×
47
        'arch$res3hr' => 'https://library.princeton.edu/architecture',
×
48
        'stokes$respiapr' => 'https://library.princeton.edu/stokes',
×
49
        'plasma$res' => 'https://library.princeton.edu/plasma-physics',
×
50
        'lewis$gr' => 'https://library.princeton.edu/lewis'
×
51
      }
×
52
    end
×
53

54
    private
×
55

56
      def stackmap_url
×
57
        stackmap_url = 'https://princeton.stackmap.com/view/'
×
58
        stackmap_params = {
×
59
          callno:,
×
60
          location: @loc,
×
61
          library: holding_location[:library][:label]
×
62
        }
×
63
        "#{stackmap_url}?#{stackmap_params.to_query}"
×
64
      end
×
65

66
      # redirects to catalog record page if location or call number is missing_stackmap_reserves
67
      # takes user to catalog home page if @document (bibid) is missing
68
      def fallback_url
×
69
        "/catalog/#{@document.to_param}"
×
70
      end
×
71

72
      def bibid
×
73
        @bibid ||= @document[:id]
×
74
      end
×
75

76
      # use the optionally provided call number unless if by title location
77
      def callno
×
78
        @cn = preferred_callno
×
79
      end
×
80

81
      def stackmap_libs
×
82
        %w[arch eastasian engineer lewis mendel stokes firestone]
×
83
      end
×
84

85
      def by_title_locations
×
86
        %w[lewis$serial plasma$ps stokes$sprps stokes$spiaps]
×
87
      end
×
88

89
      def holding_location
×
90
        @holding_location ||= Bibdata.holding_locations[@loc]
×
91
      end
×
92

93
      def lib
×
94
        @lib ||= holding_location[:library][:code]
×
95
      end
×
96

97
      def valid?
×
98
        !holding_location.nil? && !@document.nil? && !callno.nil?
×
99
      end
×
100
  end
×
101
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