• 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/models/concerns/blacklight/marc/ctx_builder.rb
1
# frozen_string_literal: true
2
require 'openurl/context_object'
×
3

4
module Blacklight
×
5
  module Marc
×
6
    # Create a generic OpenUrl ContextObject
7
    class CtxBuilder
×
8
      def initialize(document:, format:)
×
9
        @document = document
×
10
        @format = format
×
11
      end
×
12

13
      def build
×
14
        ctx.referent.set_format(genre)
×
15
        apply_metadata
×
16
        ctx
×
17
      end
×
18

19
      def ctx
×
20
        @ctx ||= OpenURL::ContextObject.new
×
21
      end
×
22

23
      private
×
24

25
        def apply_metadata
×
26
          mapping.each do |key, value|
×
27
            ctx.referent.set_metadata(key.to_s, value)
×
28
          end
×
29
          add_identifiers
×
30
        end
×
31

32
        def add_identifiers
×
33
          id = @document['id']
×
34
          ctx.referent.add_identifier("https://catalog.princeton.edu/catalog/#{id}")
×
35
          ctx.referrer.add_identifier('info:sid/catalog.princeton.edu:generator')
×
36
          ctx.referent.add_identifier("info:oclcnum/#{@document['oclc_s'].first}") unless @document['oclc_s'].nil?
×
37
          ctx.referent.add_identifier("info:lccn/#{@document['lccn_s'].first}") unless @document['lccn_s'].nil?
×
38
        end
×
39

40
        def mapping
×
41
          {
×
42
            genre:,
×
43
            title:,
×
44
            creator: author,
×
45
            pub: publisher,
×
46
            format: @format,
×
47
            issn:,
×
48
            isbn:,
×
49
            date:
×
50
          }
×
51
        end
×
52

53
        def author
×
54
          @document['author_citation_display']&.first
×
55
        end
×
56

57
        def date
×
58
          @document['pub_date_display']&.first
×
59
        end
×
60

61
        def genre
×
62
          @format == 'conference' ? @format : 'unknown'
×
63
        end
×
64

65
        def isbn
×
66
          @document['isbn_s']&.first
×
67
        end
×
68

69
        def issn
×
70
          @document['issn_s']&.first
×
71
        end
×
72

73
        def oclc
×
74
          @document['oclc_s']&.first
×
75
        end
×
76

77
        def lccn
×
78
          @document['lccn_s']&.first
×
79
        end
×
80

81
        def publisher
×
82
          @document['pub_citation_display']&.first
×
83
        end
×
84

85
        # Truncate titles to avoid overly long OpenURLs
86
        def title
×
87
          @document['title_citation_display']&.first&.truncate(250)
×
88
        end
×
89
    end
×
90
  end
×
91
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