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

pulibrary / orangetheses / d7643155-150f-4689-a91e-119e5fbfab15

07 Oct 2024 08:29PM UTC coverage: 22.253% (-65.1%) from 87.344%
d7643155-150f-4689-a91e-119e5fbfab15

push

circleci

christinach
Remove pry-byebug

160 of 719 relevant lines covered (22.25%)

0.22 hits per line

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

38.24
/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
      @logger = logger
×
14
    end
15

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

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

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

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

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

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

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

39
      embargo_date_fields.first
×
40
    end
41

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

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

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

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

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

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

61
      !embargo_date.nil?
×
62
    end
63

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

67
      embargo_date > Time.now
×
68
    end
69

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

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

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

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

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

95
    def to_solr
1✔
96
      values = document.dup
×
97
      values['restrictions_note_display'] = restrictions_note_display
×
98
      values
×
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>."
×
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>."
×
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>."
×
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
×
125
        restrictions_access
×
126
      elsif walkin?
×
127
        walkin_restrictions
×
128
      elsif embargo_present?
×
129
        if !embargo_valid?
×
130
          logger.warn("Failed to parse the embargo date for #{id}")
×
131
          invalid_embargo_restrictions_note
×
132
        elsif embargo_active?
×
133
          embargo_restrictions_note
×
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