Class: ModsDisplay::Name

Inherits:
Field
  • Object
show all
Includes:
RelatorCodes
Defined in:
lib/mods_display/fields/name.rb

Defined Under Namespace

Classes: Person

Instance Method Summary collapse

Methods included from RelatorCodes

#relator_codes

Methods inherited from Field

#initialize, #label, #render_in

Constructor Details

This class inherits a constructor from ModsDisplay::Field

Instance Method Details

#fieldsObject

this returns a hash:

{ role1 label => [ ModsDisplay:Name:Person,  ModsDisplay:Name:Person, ...], role2 label => [ ModsDisplay:Name:Person,  ModsDisplay:Name:Person, ...] }


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mods_display/fields/name.rb', line 9

def fields
  return_fields = @values.map do |value|
    name_parts = ModsDisplay::NameFormatter.format(value)
    person = name_parts ? ModsDisplay::Name::Person.new(name: name_parts, name_identifiers: value.xpath('mods:nameIdentifier', mods: MODS_NS)) : nil
    # The person may have multiple roles, so we have to divide them up into an array
    role_labels(value).collect do |role_label|
      ModsDisplay::Values.new(label: displayLabel(value) || role_label, values: [person]) if person
    end
  end.flatten.compact
  collapse_roles(collapse_fields(return_fields))
end

#to_html(view_context = ApplicationController.renderer) ⇒ Object



21
22
23
24
25
# File 'lib/mods_display/fields/name.rb', line 21

def to_html(view_context = ApplicationController.renderer)
  component = ModsDisplay::FieldComponent.with_collection(fields, value_transformer: ->(value) { value.to_s })

  view_context.render component, layout: false
end