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

Constructor Details

This class inherits a constructor from ModsDisplay::Field

Instance Method Details

#fieldsObject



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

def fields
  return_fields = @values.map do |value|
    roles = process_role(value)
    person = nil
    if value.displayForm.length > 0
      person = ModsDisplay::Name::Person.new(name: value.displayForm.text, roles: roles)
    elsif !name_parts(value).empty?
      person = ModsDisplay::Name::Person.new(name: name_parts(value), roles: roles)
    end
    ModsDisplay::Values.new(label: displayLabel(value) || name_label(value), values: [person]) if person
  end.compact
  collapse_fields(return_fields)
end

#to_htmlObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mods_display/fields/name.rb', line 18

def to_html
  return nil if fields.empty? || @config.ignore?
  output = ''
  fields.each do |field|
    output << "<dt#{label_class} #{sanitized_field_title(field.label)}>#{field.label}</dt>"
    output << "<dd#{value_class}>"
    output << field.values.map do |val|
      if @config.link
        txt = link_to_value(val.name)
        txt << " (#{val.roles.join(', ')})" if val.roles
        txt
      else
        val.to_s
      end
    end.join(@config.delimiter)
    output << '</dd>'
  end
  output
end