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, #render_in

Constructor Details

This class inherits a constructor from ModsDisplay::Field

Instance Method Details

#fieldsObject



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

def fields
  return_fields = []
  @stanford_mods_elements.each do |subject_element|
    return_values = []
    label = displayLabel(subject_element) || I18n.t('mods_display.subject')
    return_text = []
    selected_subjects(subject_element).each do |child|
      if respond_to?(:"process_#{child.name}")
        method_send = send(:"process_#{child.name}", child)
        return_text << method_send unless method_send.to_s.empty?
      elsif element_text(child).include?('--')
        return_text << element_text(child).split('--').map(&:strip)
      else
        return_text << element_text(child) unless element_text(child).empty?
      end
    end
    return_values << return_text.flatten unless return_text.empty?
    return_fields << ModsDisplay::Values.new(label: label, values: return_values) unless return_values.empty?
  end
  collapse_fields return_fields
end

#process_hierarchicalGeographic(element) ⇒ Object



38
39
40
# File 'lib/mods_display/fields/subject.rb', line 38

def process_hierarchicalGeographic(element)
  values_from_subjects(element)
end

#process_name(element) ⇒ Object



42
43
44
45
46
# File 'lib/mods_display/fields/subject.rb', line 42

def process_name(element)
  name = ModsDisplay::Name.new([element]).fields.first

  name&.values&.first
end

#to_html(view_context = ApplicationController.renderer) ⇒ Object

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



28
29
30
31
32
33
34
35
36
# File 'lib/mods_display/fields/subject.rb', line 28

def to_html(view_context = ApplicationController.renderer)
  component = ModsDisplay::FieldComponent.with_collection(
    fields,
    delimiter: '<br />'.html_safe,
    value_transformer: ->(value) { value.join(' > ') }
  )

  view_context.render component, layout: false
end