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

pulibrary / orangelight / 68ac28bb-2073-4afd-8a94-7a58e5143a62

30 Oct 2024 11:05PM UTC coverage: 96.785% (-0.02%) from 96.807%
68ac28bb-2073-4afd-8a94-7a58e5143a62

push

circleci

web-flow
Merge pull request #4490 from pulibrary/where-to-find-it-search-results

[#4475] Remove stackmaps Where to Find It button from search results page

1 of 1 new or added line in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

6112 of 6315 relevant lines covered (96.79%)

1541.24 hits per line

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

95.45
/app/services/stackmap_service.rb
1
# frozen_string_literal: true
2

3
class StackmapService
3✔
4
  # A url to the stackmap for the bib record
5
  class Url
3✔
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)
3✔
11
      @document = document
18✔
12
      @loc = loc
18✔
13
      @cn = cn
18✔
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
3✔
19
      if valid?
13✔
20
        if StackmapService::Url.missing_stackmap_reserves.include? @loc
9✔
21
          StackmapService::Url.missing_stackmap_reserves[@loc]
1✔
22
        elsif stackmap_libs.include? lib
8✔
23
          stackmap_url
8✔
24
        else
UNCOV
25
          fallback_url
×
26
        end
27
      else
28
        fallback_url
4✔
29
      end
30
    end
31

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

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

45
    def self.missing_stackmap_reserves
3✔
46
      {
127✔
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
3✔
55

56
      def stackmap_url
3✔
57
        stackmap_url = 'https://princeton.stackmap.com/view/'
8✔
58
        stackmap_params = {
59
          callno:,
8✔
60
          location: @loc,
61
          library: holding_location[:library][:label]
62
        }
63
        "#{stackmap_url}?#{stackmap_params.to_query}"
8✔
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
3✔
69
        "/catalog/#{@document.to_param}"
4✔
70
      end
71

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

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

81
      def stackmap_libs
3✔
82
        %w[arch eastasian engineer lewis mendel plasma stokes firestone]
8✔
83
      end
84

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

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

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

97
      def valid?
3✔
98
        !holding_location.nil? && !@document.nil? && !callno.nil?
13✔
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