Class: CocinaDisplay::Contributors::Role

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ Role

Initialize a Role object with Cocina structured data.

Parameters:

  • cocina (Hash)

    The Cocina structured data for the role.



19
20
21
# File 'lib/cocina_display/contributors/role.rb', line 19

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (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_relatorsHash{String => String}

A hash mapping MARC relator codes to their names.

Returns:

  • (Hash{String => String})


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?

Returns:

  • (Boolean)


32
33
34
# File 'lib/cocina_display/contributors/role.rb', line 32

def author?
  /^(author|creator|primary investigator)/i.match? to_s
end

#funder?Boolean

Does this role indicate the contributor is a funder?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


38
39
40
# File 'lib/cocina_display/contributors/role.rb', line 38

def publisher?
  /^publisher/i.match? to_s
end

#to_sString?

The name of the role. Translates the MARC relator code if no value was present.

Returns:

  • (String, nil)

    A nil role is typically displayed in the UI as an “Associated with” relationship



26
27
28
# File 'lib/cocina_display/contributors/role.rb', line 26

def to_s
  cocina.fetch("value") { marc_value }
end