Class: CocinaDisplay::License
- Inherits:
-
Object
- Object
- CocinaDisplay::License
- 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
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.licenses ⇒ Hash{String => Hash{String => String}}
A hash of license URLs to their description attributes.
Instance Method Summary collapse
-
#initialize(url:) ⇒ License
constructor
Initialize a License from a license URL.
Constructor Details
#initialize(url:) ⇒ License
Initialize a License from a license URL.
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
10 11 12 |
# File 'lib/cocina_display/license.rb', line 10 def description @description end |
#uri ⇒ Object (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
.licenses ⇒ Hash{String => Hash{String => String}}
A hash of license URLs to their description attributes
17 18 19 |
# File 'lib/cocina_display/license.rb', line 17 def self.licenses @licenses ||= YAML.safe_load_file(LICENSE_FILE_PATH) end |