Module: CocinaDisplay::Concerns::Contributors
- Included in:
- CocinaDisplay::CocinaRecord
- Defined in:
- lib/cocina_display/concerns/contributors.rb
Overview
Methods for finding and formatting names for contributors
Instance Method Summary collapse
-
#additional_contributor_names(with_date: false) ⇒ Array<String>
All contributor names except the main one, formatted for display.
-
#additional_contributors ⇒ Array<Contributor>
All contributors except the main one.
-
#conference_contributor_names ⇒ Array<String>
All names of contributors that are conferences, formatted for display.
-
#contributor_names_by_role(with_date: false) ⇒ Hash<String, Array<String>>
A hash mapping role names to the names of contributors with that role.
-
#contributors ⇒ Array<Contributor>
All contributors for the object, including authors, editors, etc.
-
#impersonal_contributor_names ⇒ Array<String>
All names of non-person contributors, formatted for display.
-
#main_contributor ⇒ Contributor?
Object representing the main contributor.
-
#main_contributor_name(with_date: false) ⇒ String?
The main contributor’s name, formatted for display.
-
#organization_contributor_names ⇒ Array<String>
All names of contributors that are organizations, formatted for display.
-
#person_contributor_names(with_date: false) ⇒ Array<String>
All names of authors who are people, formatted for display.
-
#publisher_contributors ⇒ Array<Contributor>
All contributors with a “publisher” role.
-
#publisher_names ⇒ Array<String>
All names of publishers, formatted for display.
-
#sort_contributor_name ⇒ String
A string value for sorting by contributor that sorts missing values last.
Instance Method Details
#additional_contributor_names(with_date: false) ⇒ Array<String>
All contributor names except the main one, formatted for display.
22 23 24 |
# File 'lib/cocina_display/concerns/contributors.rb', line 22 def additional_contributor_names(with_date: false) additional_contributors.map { |c| c.display_name(with_date: with_date) } end |
#additional_contributors ⇒ Array<Contributor>
All contributors except the main one.
111 112 113 114 |
# File 'lib/cocina_display/concerns/contributors.rb', line 111 def additional_contributors return [] if contributors.empty? || contributors.one? contributors - [main_contributor] end |
#conference_contributor_names ⇒ Array<String>
All names of contributors that are conferences, formatted for display.
55 56 57 |
# File 'lib/cocina_display/concerns/contributors.rb', line 55 def conference_contributor_names contributors.filter(&:conference?).map(&:display_name) end |
#contributor_names_by_role(with_date: false) ⇒ Hash<String, Array<String>>
A hash mapping role names to the names of contributors with that role.
62 63 64 65 66 67 68 69 |
# File 'lib/cocina_display/concerns/contributors.rb', line 62 def contributor_names_by_role(with_date: false) contributors.each_with_object({}) do |contributor, hash| contributor.roles.each do |role| hash[role.display_str] ||= [] hash[role.display_str] << contributor.display_name(with_date: with_date) end end end |
#contributors ⇒ Array<Contributor>
All contributors for the object, including authors, editors, etc. Checks both description.contributor and description.event.contributor.
84 85 86 87 88 89 |
# File 'lib/cocina_display/concerns/contributors.rb', line 84 def contributors @contributors ||= Enumerator::Chain.new( path("$.description.contributor.*"), path("$.description.event.*.contributor.*") ).map { |c| CocinaDisplay::Contributors::Contributor.new(c) } end |
#impersonal_contributor_names ⇒ Array<String>
All names of non-person contributors, formatted for display. This includes organizations, conferences, families, etc.
43 44 45 |
# File 'lib/cocina_display/concerns/contributors.rb', line 43 def impersonal_contributor_names contributors.reject(&:person?).map(&:display_name) end |
#main_contributor ⇒ Contributor?
Object representing the main contributor. Selected according to the following rules:
-
If there are contributors marked as primary, use the first one.
-
If there are no primary contributors, use the first contributor with no role.
-
If there are no contributors without a role, use the first contributor.
105 106 107 |
# File 'lib/cocina_display/concerns/contributors.rb', line 105 def main_contributor contributors.find(&:primary?).presence || contributors.find { |c| !c.role? }.presence || contributors.first end |
#main_contributor_name(with_date: false) ⇒ String?
The main contributor’s name, formatted for display.
15 16 17 |
# File 'lib/cocina_display/concerns/contributors.rb', line 15 def main_contributor_name(with_date: false) main_contributor&.display_name(with_date: with_date) end |
#organization_contributor_names ⇒ Array<String>
All names of contributors that are organizations, formatted for display.
49 50 51 |
# File 'lib/cocina_display/concerns/contributors.rb', line 49 def organization_contributor_names contributors.filter(&:organization?).map(&:display_name) end |
#person_contributor_names(with_date: false) ⇒ Array<String>
All names of authors who are people, formatted for display.
35 36 37 |
# File 'lib/cocina_display/concerns/contributors.rb', line 35 def person_contributor_names(with_date: false) contributors.filter(&:person?).map { |c| c.display_name(with_date: with_date) } end |
#publisher_contributors ⇒ Array<Contributor>
All contributors with a “publisher” role.
94 95 96 |
# File 'lib/cocina_display/concerns/contributors.rb', line 94 def publisher_contributors contributors.filter(&:publisher?) end |
#publisher_names ⇒ Array<String>
All names of publishers, formatted for display.
28 29 30 |
# File 'lib/cocina_display/concerns/contributors.rb', line 28 def publisher_names publisher_contributors.map(&:display_name) end |
#sort_contributor_name ⇒ String
A string value for sorting by contributor that sorts missing values last. Appends the sort title to break ties between contributor names. Ignores punctuation and leading/trailing spaces.
75 76 77 78 79 |
# File 'lib/cocina_display/concerns/contributors.rb', line 75 def sort_contributor_name sort_name = main_contributor&.display_name || "\u{10FFFF}" sort_name_title = [sort_name, sort_title].join(" ") sort_name_title.gsub(/[[:punct:]]*/, "").strip end |