Class: ModsDisplay::Subject

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

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/subject.rb', line 3

def fields
  return_values = []
  @values.each do |value|
    return_text = []
    selected_subjects(value).each do |child|
      if self.respond_to?(:"process_#{child.name}")
        return_text << self.send(:"process_#{child.name}", child) unless self.send(:"process_#{child.name}", child).to_s.empty?
      else
        if child.text.include?("--")
          return_text << child.text.split("--").map{|t| t.strip }
        else
          return_text << child.text unless child.text.empty?
        end
      end
    end
    unless return_text.empty?
      return_values << return_text.flatten
    end
  end
  return [] if return_values.empty?
  [ModsDisplay::Values.new(:label => "Subject", :values => return_values)]
end

#process_hierarchicalGeographic(element) ⇒ Object



71
72
73
# File 'lib/mods_display/fields/subject.rb', line 71

def process_hierarchicalGeographic(element)
  values_from_subjects(element)
end

#process_name(element) ⇒ Object



75
76
77
# File 'lib/mods_display/fields/subject.rb', line 75

def process_name(element)
  ModsDisplay::Name.new([element], @config, @klass).fields.first.values.first
end

#to_htmlObject

Would really like to clean this up, but it works and is tested for now.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mods_display/fields/subject.rb', line 27

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}>"
      subs = []
      field.values.each do |subjects|
        buffer = []
        sub_parts = []
        subjects.each do |val|
          if val.is_a?(ModsDisplay::Name::Person)
            buffer << val.name
          else
            buffer << val
          end
          if @config.link and @config.hierarchical_link
            if val.is_a?(ModsDisplay::Name::Person)
              txt = link_to_value(val.name, buffer.join(' '))
              txt << " (#{val.role})" if val.role
              sub_parts << txt
            else
              sub_parts << link_to_value(val, buffer.join(' '))
            end
          elsif @config.link
            if val.is_a?(ModsDisplay::Name::Person)
              txt = link_to_value(val.name)
              txt << " (#{val.role})" if val.role
              sub_parts << txt
            else
              sub_parts << link_to_value(val.to_s)
            end
          else
            sub_parts << val.to_s
          end
        end
        subs << sub_parts.join(@config.delimiter)
      end
      output << subs.join("<br/>")
    output << "</dd>"
  end
  output
end