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

pulibrary / orangetheses / fc8557fc-0887-49ac-a9c1-0b6aeae04db7

10 Oct 2024 07:55PM UTC coverage: 85.521% (-1.8%) from 87.326%
fc8557fc-0887-49ac-a9c1-0b6aeae04db7

Pull #86

circleci

jrgriffiniii
troubleshooting the API request failures
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

12 of 31 new or added lines in 4 files covered. (38.71%)

4 existing lines in 1 file now uncovered.

632 of 739 relevant lines covered (85.52%)

17.9 hits per line

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

94.44
/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
13✔
13
      @logger = logger
13✔
14
    end
15

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

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

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

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

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

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

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

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

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

47
      embargo_date_fields.first
37✔
48
    end
49

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

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

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

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

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

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

69
      !embargo_date.nil?
9✔
70
    end
71

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

75
      embargo_date > Time.now
3✔
76
    end
77

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

82
    def access_rights
1✔
83
      @access_rights ||= document['dc.rights.accessRights']
12✔
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']
14✔
97
    end
98

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

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

109
    private
1✔
110

111
    # rubocop:disable Layout/LineLength
112
    def walkin_restrictions
1✔
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>."
2✔
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>."
3✔
120
    end
121
    # rubocop:enable Layout/LineLength
122

123
    # rubocop:disable Layout/LineLength
124
    def embargo_restrictions_note
1✔
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>."
2✔
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
12✔
UNCOV
133
        restrictions_access
×
134
      elsif walkin?
12✔
135
        walkin_restrictions
2✔
136
      elsif embargo_present?
10✔
137
        if !embargo_valid?
6✔
138
          logger.warn("Failed to parse the embargo date for #{id}")
3✔
139
          invalid_embargo_restrictions_note
3✔
140
        elsif embargo_active?
3✔
141
          embargo_restrictions_note
2✔
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