Class: CocinaDisplay::License

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina_display/license.rb

Overview

A license associated with part or all of a Cocina object. This is the license entity used for translating a license URL into text for display.

Defined Under Namespace

Classes: LegacyLicenseError

Constant Summary collapse

LICENSE_FILE_PATH =
File.join(__dir__, "..", "..", "config", "licenses.yml").freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:) ⇒ License

Initialize a License from a license URL.

Parameters:

  • url (String)

    The license URL.

Raises:



24
25
26
27
28
29
30
# File 'lib/cocina_display/license.rb', line 24

def initialize(url:)
  raise LegacyLicenseError unless License.licenses.key?(url)

  attrs = License.licenses.fetch(url)
  @uri = url
  @description = attrs.fetch("description")
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/cocina_display/license.rb', line 10

def description
  @description
end

#uriObject (readonly)

Returns the value of attribute uri.



10
11
12
# File 'lib/cocina_display/license.rb', line 10

def uri
  @uri
end

Class Method Details

.licensesHash{String => Hash{String => String}}

A hash of license URLs to their description attributes

Returns:

  • (Hash{String => Hash{String => String}})


17
18
19
# File 'lib/cocina_display/license.rb', line 17

def self.licenses
  @licenses ||= YAML.safe_load_file(LICENSE_FILE_PATH)
end