Class: CocinaDisplay::Contributors::Role
- Inherits:
-
Object
- Object
- CocinaDisplay::Contributors::Role
- Defined in:
- lib/cocina_display/contributors/role.rb
Overview
A role associated with a contributor.
Constant Summary collapse
- MARC_RELATORS_FILE_PATH =
File.join(__dir__, "..", "..", "..", "config", "marc_relators.yml").freeze
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
Returns the value of attribute cocina.
Class Method Summary collapse
-
.marc_relators ⇒ Hash{String => String}
A hash mapping MARC relator codes to their names.
Instance Method Summary collapse
-
#author? ⇒ Boolean
Does this role indicate the contributor is an author?.
-
#funder? ⇒ Boolean
Does this role indicate the contributor is a funder?.
-
#initialize(cocina) ⇒ Role
constructor
Initialize a Role object with Cocina structured data.
-
#publisher? ⇒ Boolean
Does this role indicate the contributor is a publisher?.
-
#to_s ⇒ String?
The name of the role.
Constructor Details
#initialize(cocina) ⇒ Role
Initialize a Role object with Cocina structured data.
19 20 21 |
# File 'lib/cocina_display/contributors/role.rb', line 19 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
Returns the value of attribute cocina.
9 10 11 |
# File 'lib/cocina_display/contributors/role.rb', line 9 def cocina @cocina end |
Class Method Details
.marc_relators ⇒ Hash{String => String}
A hash mapping MARC relator codes to their names.
13 14 15 |
# File 'lib/cocina_display/contributors/role.rb', line 13 def self.marc_relators @marc_relators ||= YAML.safe_load_file(MARC_RELATORS_FILE_PATH) end |
Instance Method Details
#author? ⇒ Boolean
Does this role indicate the contributor is an author?
32 33 34 |
# File 'lib/cocina_display/contributors/role.rb', line 32 def /^(author|creator|primary investigator)/i.match? to_s end |
#funder? ⇒ Boolean
Does this role indicate the contributor is a funder?
44 45 46 |
# File 'lib/cocina_display/contributors/role.rb', line 44 def funder? /^funder/i.match? to_s end |
#publisher? ⇒ Boolean
Does this role indicate the contributor is a publisher?
38 39 40 |
# File 'lib/cocina_display/contributors/role.rb', line 38 def publisher? /^publisher/i.match? to_s end |
#to_s ⇒ String?
The name of the role. Translates the MARC relator code if no value was present.
26 27 28 |
# File 'lib/cocina_display/contributors/role.rb', line 26 def to_s cocina.fetch("value") { marc_value } end |