Class: ModsDisplay::Name

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

Defined Under Namespace

Classes: Person

Instance Method Summary collapse

Methods inherited from Field

#initialize, #label

Constructor Details

This class inherits a constructor from ModsDisplay::Field

Instance Method Details

#fieldsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mods_display/fields/name.rb', line 3

def fields
  return_fields = @values.map do |value|
    role = nil
    person = nil
    if value.role.length > 0 and value.role.roleTerm.length > 0
      role = value.role.roleTerm.find do |term|
        term.attributes["type"].respond_to?(:value) and
        term.attributes["type"].value == "text"
      end
    end
    if value.displayForm.length > 0
      person = ModsDisplay::Name::Person.new(:name => value.displayForm.text, :role => role)
    else
      name_parts = value.namePart.map do |name_part|
        name_part.text
      end.join(", ")
      person = ModsDisplay::Name::Person.new(:name => name_parts, :role => role) unless name_parts.empty?
    end
    ModsDisplay::Values.new(:label => displayLabel(value) || name_label(value), :values => [person]) if person
  end.compact
  collapse_fields(return_fields)
end

#to_htmlObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mods_display/fields/name.rb', line 26

def to_html
  return nil if fields.empty? or @config.ignore?
  output = ""
  fields.each do |field|
    output << "<dt#{label_class} 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.role})" if val.role
          txt
        else
          val.to_s
        end
      end.join(@config.delimiter)
    output << "</dd>"
  end
  output
end