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_contacts ⇒ Array<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_data ⇒ Array<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

#accesses ⇒ Array<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)


195
196
197
# File 'lib/cocina_display/concerns/accesses.rb', line 195

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

#contact_email_display_data ⇒ Array<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)


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

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

#download_rights ⇒ String?

Note:

Individual files may have differing download rights.

Note:

Collections have no download rights, so this is always nil for them.

Download rights for the object.

Examples:

"world", "stanford_only", "none", "location-based"

Returns:

  • (String, nil)


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

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

#downloadable? ⇒ Boolean

Is the object downloadable in some capacity?

Returns:

  • (Boolean)


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

def downloadable?
  download_rights.present? && download_rights != "none"
end

#license_display_data ⇒ Object



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)


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

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)


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

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

#location_only_viewable? ⇒ Boolean

Is the object viewable only if in a location?

Returns:

  • (Boolean)


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

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

#location_rights ⇒ String?

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

Examples:

"spec", "music", "ars", "art", "hoover", "m&m"

Returns:

  • (String, nil)


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

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

#stanford_access? ⇒ Boolean

Note:

Collections have no download rights, so only view rights are considered.

Is the object both viewable and downloadable by Stanford affiliates?

Returns:

  • (Boolean)


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

def stanford_access?
  return stanford_viewable? if collection?

  stanford_viewable? && stanford_downloadable?
end

#stanford_downloadable? ⇒ Boolean

Is the object downloadable by Stanford affiliates?

Returns:

  • (Boolean)


149
150
151
# File 'lib/cocina_display/concerns/accesses.rb', line 149

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)


137
138
139
# File 'lib/cocina_display/concerns/accesses.rb', line 137

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)


131
132
133
# File 'lib/cocina_display/concerns/accesses.rb', line 131

def stanford_only_downloadable?
  download_rights == "stanford"
end

#stanford_only_viewable? ⇒ Boolean

Is the object only viewable by Stanford affiliates?

Returns:

  • (Boolean)


125
126
127
# File 'lib/cocina_display/concerns/accesses.rb', line 125

def stanford_only_viewable?
  view_rights == "stanford"
end

#stanford_viewable? ⇒ Boolean

Is the object viewable by Stanford affiliates?

Returns:

  • (Boolean)


143
144
145
# File 'lib/cocina_display/concerns/accesses.rb', line 143

def stanford_viewable?
  world_viewable? || stanford_only_viewable?
end

#urls ⇒ Array<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_data ⇒ Array<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_rights ⇒ String?

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)


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

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)


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

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

#world_access? ⇒ Boolean

Note:

Collections have no download rights, so only view rights are considered.

Is the object both viewable and downloadable by anyone?

Returns:

  • (Boolean)


117
118
119
120
121
# File 'lib/cocina_display/concerns/accesses.rb', line 117

def world_access?
  return world_viewable? if collection?

  world_viewable? && world_downloadable?
end

#world_downloadable? ⇒ Boolean

Is the object downloadable by anyone?

Returns:

  • (Boolean)


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

def world_downloadable?
  download_rights == "world"
end

#world_viewable? ⇒ Boolean

Is the object viewable by anyone?

Returns:

  • (Boolean)


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

def world_viewable?
  view_rights == "world"
end