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



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

def fields
  return_fields = @values.map do |value|
    person = if value.displayForm.length.positive?
               ModsDisplay::Name::Person.new(name: element_text(value.displayForm))
             elsif !name_parts(value).empty?
               ModsDisplay::Name::Person.new(name: name_parts(value))
             end
    # 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