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

pulibrary / orangetheses / 3695068a-fea6-4cda-8ddb-e3cf6a70ab4e

10 Oct 2024 02:13PM UTC coverage: 85.402% (-1.9%) from 87.326%
3695068a-fea6-4cda-8ddb-e3cf6a70ab4e

Pull #86

circleci

jrgriffiniii
Resolving indexing bugs for the "location" field
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

5 of 24 new or added lines in 3 files covered. (20.83%)

4 existing lines in 1 file now uncovered.

626 of 733 relevant lines covered (85.4%)

17.89 hits per line

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

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

16
    def id
1✔
17
      document['id']
8✔
18
    end
19

20
    def embargo_lift_field
1✔
21
      return unless document.key?('pu.embargo.lift')
10✔
22

23
      @embargo_lift_field ||= document['pu.embargo.lift']
9✔
24
    end
25

26
    def embargo_terms_field
1✔
27
      return unless document.key?('pu.embargo.terms')
5✔
28

29
      @embargo_terms_field ||= document['pu.embargo.terms']
5✔
30
    end
31

32
    def embargo_date_fields
1✔
33
      @embargo_date_fields ||= embargo_lift_field || embargo_terms_field
78✔
34
    end
35

36
    def embargo_date_field
1✔
37
      return if embargo_date_fields.nil?
41✔
38

39
      embargo_date_fields.first
37✔
40
    end
41

42
    def embargo_date
1✔
43
      return if embargo_date_field.nil?
16✔
44

45
      @embargo_date ||= Chronic.parse(embargo_date_field)
16✔
46
    end
47

48
    def embargo_present?
1✔
49
      !embargo_date_field.nil?
19✔
50
    end
51

52
    def formatted_embargo_date
1✔
53
      return if embargo_date.nil?
2✔
54

55
      @formatted_embargo_date ||= embargo_date.strftime('%B %-d, %Y')
2✔
56
    end
57

58
    def embargo_valid?
1✔
59
      return false unless embargo_present?
9✔
60

61
      !embargo_date.nil?
9✔
62
    end
63

64
    def embargo_active?
1✔
65
      return false unless embargo_valid?
3✔
66

67
      embargo_date > Time.now
3✔
68
    end
69

70
    def location
1✔
71
      @location ||= document['pu.location']
12✔
72
    end
73

74
    def access_rights
1✔
75
      @access_rights ||= document['dc.rights.accessRights']
12✔
76
    end
77

78
    def restrictions_access
1✔
79
      values = [
UNCOV
80
        location,
×
81
        access_rights
82
      ]
UNCOV
83
      flattened = values.flatten
×
UNCOV
84
      flattened.compact
×
85
    end
86

87
    def walkin
1✔
88
      @walkin ||= document['pu.mudd.walkin']
14✔
89
    end
90

91
    def walkin?
1✔
92
      !walkin.nil? && walkin.first == 'yes'
12✔
93
    end
94

95
    def to_solr
1✔
96
      values = document.dup
12✔
97
      values['restrictions_note_display'] = restrictions_note_display
12✔
98
      values
12✔
99
    end
100

101
    private
1✔
102

103
    # rubocop:disable Layout/LineLength
104
    def walkin_restrictions
1✔
105
      "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✔
106
    end
107
    # rubocop:enable Layout/LineLength
108

109
    # rubocop:disable Layout/LineLength
110
    def invalid_embargo_restrictions_note
1✔
111
      "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✔
112
    end
113
    # rubocop:enable Layout/LineLength
114

115
    # rubocop:disable Layout/LineLength
116
    def embargo_restrictions_note
1✔
117
      "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✔
118
    end
119
    # rubocop:enable Layout/LineLength
120

121
    # rubocop:disable Metrics/MethodLength
122
    # rubocop:disable Metrics/PerceivedComplexity
123
    def restrictions_note_display
1✔
124
      if location || access_rights
12✔
UNCOV
125
        restrictions_access
×
126
      elsif walkin?
12✔
127
        walkin_restrictions
2✔
128
      elsif embargo_present?
10✔
129
        if !embargo_valid?
6✔
130
          logger.warn("Failed to parse the embargo date for #{id}")
3✔
131
          invalid_embargo_restrictions_note
3✔
132
        elsif embargo_active?
3✔
133
          embargo_restrictions_note
2✔
134
        end
135
      end
136
    end
137
    # rubocop:enable Metrics/MethodLength
138
    # rubocop:enable Metrics/PerceivedComplexity
139
  end
140
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