class Resync::CapabilityList

A capability list. See section 9, “{www.openarchives.org/rs/1.0/resourcesync#CapabilityList Advertising Capabilities}”, in the ResourceSync specification.

Constants

CAPABILITY

The capability provided by this type.

Public Class Methods

new(resources: [], links: [], metadata: nil) click to toggle source

Creates a new BaseResourceList.

@param resources [Array<Resource>] The +<url>+ or +<sitemap>+ elements contained in this list.

All resources must have a capability, and there can be no more than one resource for each
specified capability.

@param links [Array<Link>] Related links (+<rs:ln>+). @param metadata [Metadata] Metadata about this list. The capability of the metadata must

be +'capabilitylist'+.

@raise [ArgumentError] if a provided resource does not have a capability attribute. @raise [ArgumentError] if more than one provided resource has the same capability attribute. @raise [ArgumentError] if the specified metadata does not have the correct capability attribute.

Calls superclass method
# File lib/resync/capability_list.rb, line 28
def initialize(resources: [], links: [], metadata: nil)
  super(resources: resources, links: links, metadata: metadata)
  @source_description = source_description_from(self.links)
end

Public Instance Methods

resource_for(capability:) click to toggle source

Gets the resource for the specified capability.

@param capability [String] The capability. @return [Resource] the resource providing the capability, or nil if

there is no resource with that capability in this list.
# File lib/resync/capability_list.rb, line 49
def resource_for(capability:)
  @capabilities[capability]
end
resources=(value) click to toggle source

Sets the resources list. nil is treated as an empty list. @raise [ArgumentError] if a provided resource does not have a capability attribute. @raise [ArgumentError] if more than one provided resource has the same capability attribute.

Calls superclass method
# File lib/resync/capability_list.rb, line 39
def resources=(value)
  @capabilities = to_capability_map(value || [])
  super(@capabilities.values)
end
source_description() click to toggle source

Gets the URI of the description of the source whose capabilities are identified by this list.

@return [URI] the URI of the description of the source whose capabilities are identified

by this list. See section 8,
"{http://www.openarchives.org/rs/1.0/resourcesync#SourceDesc Describing the Source}",
in the ResourceSync specification.
# File lib/resync/capability_list.rb, line 59
def source_description
  @source_description ||= source_description_from(links)
end

Private Instance Methods

source_description_from(links) click to toggle source
# File lib/resync/capability_list.rb, line 79
def source_description_from(links)
  return nil unless links
  desc = links.map { |link| link.uri if link.rel == 'up' }.compact.first
  raise ArgumentError, "No source descrption (<link rel='up'/>) provided" unless desc
  desc
end
to_capability_map(resources) click to toggle source

Conversions

# File lib/resync/capability_list.rb, line 68
def to_capability_map(resources)
  capabilities = {}
  (resources || []).each do |resource|
    capability = resource.capability
    raise ArgumentError, "No capability found for resource with URI #{resource.uri}" unless capability
    raise ArgumentError, "Duplicate resource for capability #{capability}" if capabilities.key?(capability)
    capabilities[capability] = resource
  end
  capabilities
end