Class: ModsDisplay::Name
- Includes:
- RelatorCodes
- Defined in:
- lib/mods_display/fields/name.rb
Defined Under Namespace
Classes: Person
Instance Method Summary collapse
-
#fields ⇒ Object
this returns a hash: { role1 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, …], role2 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, …] }.
- #to_html(view_context = ApplicationController.renderer) ⇒ Object
Methods included from RelatorCodes
Methods inherited from Field
#initialize, #label, #render_in
Constructor Details
This class inherits a constructor from ModsDisplay::Field
Instance Method Details
#fields ⇒ Object
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 20 21 22 23 |
# File 'lib/mods_display/fields/name.rb', line 9 def fields return_fields = @values.map do |value| name_identifiers = value.element_children.select { |child| child.name == 'nameIdentifier' } person = if value.displayForm.length.positive? ModsDisplay::Name::Person.new(name: element_text(value.displayForm), name_identifiers: name_identifiers) elsif !name_parts(value).empty? ModsDisplay::Name::Person.new(name: name_parts(value), name_identifiers: name_identifiers) 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
25 26 27 28 29 |
# File 'lib/mods_display/fields/name.rb', line 25 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 |