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

returns a hash:

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


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

def fields
  return_fields = @stanford_mods_elements.map do |plain_name_element|
    name_parts = ModsDisplay::NameFormatter.format(plain_name_element)
    person = name_parts ? ModsDisplay::Name::Person.new(name: name_parts, name_identifiers: plain_name_element.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(plain_name_element).collect do |role_label|
      ModsDisplay::Values.new(label: displayLabel(plain_name_element) || role_label, values: [person]) if person
    end
  end.flatten.compact
  collapse_roles(collapse_fields(return_fields))
end

#to_html(view_context = ApplicationController.renderer) ⇒ Object



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

def to_html(view_context = ApplicationController.renderer)
  component = ModsDisplay::FieldComponent.with_collection(fields, value_transformer: lambda(&:to_s))

  view_context.render component, layout: false
end