Sha256: 98fced9904faf7771c3a39bc92c9fbf16cc28b28fa24d294732174341bd09511

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module ModsDisplay
  module RelatedItemConcerns
    private

    def render_nested_related_item?(item)
      item.constituent? || item.host?
    end

    class RelatedItemValue < SimpleDelegator
      def collection?
        @collection ||= typeOfResource_nodeset.first&.get_attribute('collection') == 'yes'
      end

      def constituent?
        @constituent ||= type_attribute == 'constituent'
      end

      def host?
        @host ||= type_attribute == 'host'
      end

      def location?
        @location ||= !collection? &&
                      !reference? &&
                      location_nodeset.length.positive? &&
                      titleInfo_nodeset.empty?
      end

      def reference?
        @reference ||= !collection? && type_attribute == 'isReferencedBy'
      end

      def typeOfResource_nodeset
        @typeOfResource_nodeset ||= xpath('mods:typeOfResource', mods: MODS_NS)
      end

      def location_nodeset
        @location_nodeset ||= xpath('mods:location', mods: MODS_NS)
      end

      def location_url_nodeset
        @location_url_nodeset ||= xpath('mods:location/mods:url', mods: MODS_NS)
      end

      def titleInfo_nodeset
        @titleInfo_nodeset ||= xpath('mods:titleInfo', mods: MODS_NS)
      end

      def note_nodeset
        @note_nodeset ||= xpath('mods:note', mods: MODS_NS)
      end

      def type_attribute
        @type_attribute ||= get_attribute('type')
      end

      def self.for_values(values)
        values.map { |value| new(value) }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mods_display-1.6.1 lib/mods_display/related_item_concerns.rb
mods_display-1.6.0 lib/mods_display/related_item_concerns.rb
mods_display-1.5.0 lib/mods_display/related_item_concerns.rb
mods_display-1.4.0 lib/mods_display/related_item_concerns.rb
mods_display-1.3.5 lib/mods_display/related_item_concerns.rb