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

pulibrary / orangetheses / 26706161-8696-498b-9937-36792a26a484

11 Oct 2024 10:04PM UTC coverage: 84.032% (-3.3%) from 87.326%
26706161-8696-498b-9937-36792a26a484

Pull #86

circleci

christinach
[#85] Remove pu. fields from def build_solr_document
 Theses fields are not included in the solr document and the theses.json file fails to index
Pull Request #86: Restructuring the generation of access restriction text during indexing and implementing a Rake Task for indexing OAI Items using a given Set ID

14 of 35 new or added lines in 4 files covered. (40.0%)

13 existing lines in 1 file now uncovered.

621 of 739 relevant lines covered (84.03%)

17.34 hits per line

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

79.17
/lib/orangetheses/dataspace_document.rb
1
# frozen_string_literal: true
2

3
require 'chronic'
1✔
4

5
module Orangetheses
1✔
6
  # Class modeling the behavior for Solr Documents generated with DataSpace Item
7
  #   metadata
8
  class DataspaceDocument
1✔
9
    attr_reader :document
1✔
10

11
    def initialize(document:, logger:)
1✔
12
      @document = document
11✔
13
      @logger = logger
11✔
14
    end
15

16
    def key?(value)
1✔
NEW
17
      document.key?(value)
×
18
    end
19

20
    def [](value)
1✔
NEW
21
      document[value]
×
22
    end
23

24
    def id
1✔
25
      document['id']
4✔
26
    end
27

28
    def embargo_lift_field
1✔
29
      return unless document.key?('pu.embargo.lift')
11✔
30

31
      @embargo_lift_field ||= document['pu.embargo.lift']
1✔
32
    end
33

34
    def embargo_terms_field
1✔
35
      return unless document.key?('pu.embargo.terms')
10✔
36

37
      @embargo_terms_field ||= document['pu.embargo.terms']
1✔
38
    end
39

40
    def embargo_date_fields
1✔
41
      @embargo_date_fields ||= embargo_lift_field || embargo_terms_field
25✔
42
    end
43

44
    def embargo_date_field
1✔
45
      return if embargo_date_fields.nil?
17✔
46

47
      embargo_date_fields.first
8✔
48
    end
49

50
    def embargo_date
1✔
51
      return if embargo_date_field.nil?
2✔
52

53
      @embargo_date ||= Chronic.parse(embargo_date_field)
2✔
54
    end
55

56
    def embargo_present?
1✔
57
      !embargo_date_field.nil?
13✔
58
    end
59

60
    def formatted_embargo_date
1✔
UNCOV
61
      return if embargo_date.nil?
×
62

UNCOV
63
      @formatted_embargo_date ||= embargo_date.strftime('%B %-d, %Y')
×
64
    end
65

66
    def embargo_valid?
1✔
67
      return false unless embargo_present?
2✔
68

69
      !embargo_date.nil?
2✔
70
    end
71

72
    def embargo_active?
1✔
UNCOV
73
      return false unless embargo_valid?
×
74

UNCOV
75
      embargo_date > Time.now
×
76
    end
77

78
    def location
1✔
79
      @location ||= document['pu.location']
11✔
80
    end
81

82
    def access_rights
1✔
83
      @access_rights ||= document['dc.rights.accessRights']
11✔
84
    end
85

86
    def restrictions_access
1✔
87
      values = [
UNCOV
88
        location,
×
89
        access_rights
90
      ]
UNCOV
91
      flattened = values.flatten
×
UNCOV
92
      flattened.compact
×
93
    end
94

95
    def walkin
1✔
96
      @walkin ||= document['pu.mudd.walkin']
11✔
97
    end
98

99
    def walkin?
1✔
100
      !walkin.nil? && walkin.first == 'yes'
11✔
101
    end
102

103
    def to_solr
1✔
104
      values = document.dup
11✔
105
      values['restrictions_note_display'] = restrictions_note_display
11✔
106
      values
11✔
107
    end
108

109
    private
1✔
110

111
    # rubocop:disable Layout/LineLength
112
    def walkin_restrictions
1✔
UNCOV
113
      "Walk-in Access. This thesis can only be viewed on computer terminals at the '<a href=\"http://mudd.princeton.edu\">Mudd Manuscript Library</a>."
×
114
    end
115
    # rubocop:enable Layout/LineLength
116

117
    # rubocop:disable Layout/LineLength
118
    def invalid_embargo_restrictions_note
1✔
119
      "This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/#{id}\"> Mudd Manuscript Library</a>."
2✔
120
    end
121
    # rubocop:enable Layout/LineLength
122

123
    # rubocop:disable Layout/LineLength
124
    def embargo_restrictions_note
1✔
UNCOV
125
      "This content is embargoed until #{formatted_embargo_date}. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/#{id}\"> Mudd Manuscript Library</a>."
×
126
    end
127
    # rubocop:enable Layout/LineLength
128

129
    # rubocop:disable Metrics/MethodLength
130
    # rubocop:disable Metrics/PerceivedComplexity
131
    def restrictions_note_display
1✔
132
      if location || access_rights
11✔
UNCOV
133
        restrictions_access
×
134
      elsif walkin?
11✔
UNCOV
135
        walkin_restrictions
×
136
      elsif embargo_present?
11✔
137
        if !embargo_valid?
2✔
138
          logger.warn("Failed to parse the embargo date for #{id}")
2✔
139
          invalid_embargo_restrictions_note
2✔
UNCOV
140
        elsif embargo_active?
×
UNCOV
141
          embargo_restrictions_note
×
142
        end
143
      end
144
    end
145
    # rubocop:enable Metrics/MethodLength
146
    # rubocop:enable Metrics/PerceivedComplexity
147
  end
148
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