Sha256: 76a7ae828e2e519c3fac018989e0bf2613b1a576310abfe83b5c47b94d50826f

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module ModsDisplay
  class Location < Field
    def fields
      return_fields = []
      @values.each do |location|
        location.children.each do |child|
          next unless location_field_keys.include?(child.name.to_sym)

          if child.name.to_sym == :url
            loc_label = displayLabel(location) || I18n.t('mods_display.location')
            value = "<a href='#{element_text(child)}'>#{(displayLabel(child) || element_text(child)).gsub(/:$/, '')}</a>"
          else
            loc_label = location_label(child) || displayLabel(location) || I18n.t('mods_display.location')
            value = element_text(child)
          end
          return_fields << ModsDisplay::Values.new(
            label: loc_label || displayLabel(location) || I18n.t('mods_display.location'),
            values: [value]
          )
        end
      end
      collapse_fields(return_fields)
    end

    private

    def location_field_keys
      %i[physicalLocation url shelfLocator holdingSimple holdingExternal]
    end

    def location_label(element)
      if displayLabel(element)
        displayLabel(element)
      elsif element.attributes['type'].respond_to?(:value) && location_labels.key?(element.attributes['type'].value)
        location_labels[element.attributes['type'].value]
      end
    end

    def location_labels
      { 'repository' => I18n.t('mods_display.repository') }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mods_display-1.3.1 lib/mods_display/fields/location.rb
mods_display-1.3.0 lib/mods_display/fields/location.rb
mods_display-1.2.1 lib/mods_display/fields/location.rb
mods_display-1.2.0 lib/mods_display/fields/location.rb
mods_display-1.1.0 lib/mods_display/fields/location.rb