Module: CocinaDisplay::Concerns::Accesses

Included in:
CocinaDisplay::CocinaRecord, RelatedResource
Defined in:
lib/cocina_display/concerns/accesses.rb

Overview

Methods for extracting access/location information from a Cocina object.

Instance Method Summary collapse

Instance Method Details

#access_contactsArray<Description::AccessContact>

All access contact metadata

Returns:



53
54
55
56
57
# File 'lib/cocina_display/concerns/accesses.rb', line 53

def access_contacts
  path("$.description.access.accessContact.*").map do |contact|
    CocinaDisplay::Description::AccessContact.new(contact)
  end
end

#access_display_dataArray<DisplayData>

Display data for all access metadata except contact emails

Returns:



7
8
9
10
11
12
# File 'lib/cocina_display/concerns/accesses.rb', line 7

def access_display_data
  CocinaDisplay::DisplayData.from_objects(accesses +
                                          access_contacts.reject(&:contact_email?) +
                                          purls +
                                          urls)
end

#accessesArray<Description::Access>

All access metadata except contact emails and URLs

Returns:



43
44
45
46
47
48
49
# File 'lib/cocina_display/concerns/accesses.rb', line 43

def accesses
  @accesses ||= Enumerator::Chain.new(
    path("$.description.access.physicalLocation.*"),
    path("$.description.access.digitalLocation.*"),
    path("$.description.access.digitalRepository.*")
  ).map { |a| CocinaDisplay::Description::Access.new(a) }
end

#citation_only_access?Boolean

Is the object only viewable for citation purposes?

Returns:

  • (Boolean)


188
189
190
# File 'lib/cocina_display/concerns/accesses.rb', line 188

def citation_only_access?
  view_rights == "citation-only"
end

#contact_email_display_dataArray<DisplayData>

Display data for all access contact email metadata

Returns:



16
17
18
# File 'lib/cocina_display/concerns/accesses.rb', line 16

def contact_email_display_data
  CocinaDisplay::DisplayData.from_objects(access_contacts.select(&:contact_email?))
end

Display data for the copyright statement. Exhibits and EarthWorks handle copyright like descriptive metadata.

Returns:



31
32
33
34
# File 'lib/cocina_display/concerns/accesses.rb', line 31

def copyright_display_data
  CocinaDisplay::DisplayData.from_strings([copyright],
    label: I18n.t("cocina_display.field_label.copyright"))
end

#dark_access?Boolean

Is the object “dark” (not viewable or downloadable by anyone)?

Returns:

  • (Boolean)


157
158
159
# File 'lib/cocina_display/concerns/accesses.rb', line 157

def dark_access?
  !viewable? && !downloadable?
end

#download_rightsString?

Note:

Individual files may have differing download rights.

Download rights for the object.

Examples:

“world”, “stanford_only”, “none”, “location-based”

Returns:

  • (String, nil)


78
79
80
# File 'lib/cocina_display/concerns/accesses.rb', line 78

def download_rights
  path("$.access.download").first
end

#downloadable?Boolean

Is the object downloadable in some capacity?

Returns:

  • (Boolean)


97
98
99
# File 'lib/cocina_display/concerns/accesses.rb', line 97

def downloadable?
  download_rights != "none"
end

#license_display_dataObject



36
37
38
39
# File 'lib/cocina_display/concerns/accesses.rb', line 36

def license_display_data
  CocinaDisplay::DisplayData.from_strings([license_description],
    label: I18n.t("cocina_display.field_label.license"))
end

#location_only_access?Boolean

Is the object only viewable and downloadable if in a location?

Returns:

  • (Boolean)


175
176
177
# File 'lib/cocina_display/concerns/accesses.rb', line 175

def location_only_access?
  location_only_viewable? && location_only_downloadable?
end

#location_only_downloadable?Boolean

Is the object downloadable only if in a location?

Returns:

  • (Boolean)


169
170
171
# File 'lib/cocina_display/concerns/accesses.rb', line 169

def location_only_downloadable?
  download_rights == "location-based"
end

#location_only_viewable?Boolean

Is the object viewable only if in a location?

Returns:

  • (Boolean)


163
164
165
# File 'lib/cocina_display/concerns/accesses.rb', line 163

def location_only_viewable?
  view_rights == "location-based"
end

#location_rightsString?

If access or download is location-based, which location has access.

Examples:

“spec”, “music”, “ars”, “art”, “hoover”, “m&m”

Returns:

  • (String, nil)


85
86
87
# File 'lib/cocina_display/concerns/accesses.rb', line 85

def location_rights
  path("$.access.location").first
end

#stanford_access?Boolean

Is the object both viewable and downloadable by Stanford affiliates?

Returns:

  • (Boolean)


151
152
153
# File 'lib/cocina_display/concerns/accesses.rb', line 151

def stanford_access?
  stanford_viewable? && stanford_downloadable?
end

#stanford_downloadable?Boolean

Is the object downloadable by Stanford affiliates?

Returns:

  • (Boolean)


145
146
147
# File 'lib/cocina_display/concerns/accesses.rb', line 145

def stanford_downloadable?
  world_downloadable? || stanford_only_downloadable?
end

#stanford_only_access?Boolean

Is the object only viewable and downloadable by Stanford affiliates?

Returns:

  • (Boolean)


133
134
135
# File 'lib/cocina_display/concerns/accesses.rb', line 133

def stanford_only_access?
  stanford_only_viewable? && stanford_only_downloadable?
end

#stanford_only_downloadable?Boolean

Is the object only downloadable by Stanford affiliates?

Returns:

  • (Boolean)


127
128
129
# File 'lib/cocina_display/concerns/accesses.rb', line 127

def stanford_only_downloadable?
  download_rights == "stanford"
end

#stanford_only_viewable?Boolean

Is the object only viewable by Stanford affiliates?

Returns:

  • (Boolean)


121
122
123
# File 'lib/cocina_display/concerns/accesses.rb', line 121

def stanford_only_viewable?
  view_rights == "stanford"
end

#stanford_viewable?Boolean

Is the object viewable by Stanford affiliates?

Returns:

  • (Boolean)


139
140
141
# File 'lib/cocina_display/concerns/accesses.rb', line 139

def stanford_viewable?
  world_viewable? || stanford_only_viewable?
end

#urlsArray<Description::Url>

All access URL metadata

Returns:



61
62
63
64
65
# File 'lib/cocina_display/concerns/accesses.rb', line 61

def urls
  path("$.description.access.url.*").map do |url|
    CocinaDisplay::Description::Url.new(url)
  end
end

#use_and_reproduction_display_dataArray<CocinaDisplay::DisplayData>

Display data for the use and reproduction statement. Exhibits and EarthWorks handle useAndReproductionStatement like descriptive metadata.

Returns:



23
24
25
26
# File 'lib/cocina_display/concerns/accesses.rb', line 23

def use_and_reproduction_display_data
  CocinaDisplay::DisplayData.from_strings([use_and_reproduction],
    label: I18n.t("cocina_display.field_label.use_and_reproduction"))
end

#view_rightsString?

View rights for the object.

Examples:

“world”, “stanford_only”, “dark”, “location-based”

Returns:

  • (String, nil)


70
71
72
# File 'lib/cocina_display/concerns/accesses.rb', line 70

def view_rights
  path("$.access.view").first
end

#viewable?Boolean

Is the object viewable in some capacity?

Returns:

  • (Boolean)


91
92
93
# File 'lib/cocina_display/concerns/accesses.rb', line 91

def viewable?
  view_rights != "dark"
end

#viewable_at_location?(location) ⇒ Boolean

Is the object viewable at the given location?

Parameters:

  • location (String)

    The location to check

Returns:

  • (Boolean)


182
183
184
# File 'lib/cocina_display/concerns/accesses.rb', line 182

def viewable_at_location?(location)
  world_viewable? || stanford_viewable? || location_rights == location
end

#world_access?Boolean

Is the object both viewable and downloadable by anyone?

Returns:

  • (Boolean)


115
116
117
# File 'lib/cocina_display/concerns/accesses.rb', line 115

def world_access?
  world_viewable? && world_downloadable?
end

#world_downloadable?Boolean

Is the object downloadable by anyone?

Returns:

  • (Boolean)


109
110
111
# File 'lib/cocina_display/concerns/accesses.rb', line 109

def world_downloadable?
  download_rights == "world"
end

#world_viewable?Boolean

Is the object viewable by anyone?

Returns:

  • (Boolean)


103
104
105
# File 'lib/cocina_display/concerns/accesses.rb', line 103

def world_viewable?
  view_rights == "world"
end