Class: OAI::Provider::Response::ListMetadataFormats

Inherits:
RecordResponse show all
Defined in:
lib/oai/provider/response/list_metadata_formats.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #provider

Instance Method Summary collapse

Methods inherited from RecordResponse

#data_for, #header_for, inherited

Methods inherited from Base

default_parameters, #initialize, required_parameters, #response, valid_parameters

Constructor Details

This class inherits a constructor from OAI::Provider::Response::Base

Instance Method Details

#to_xmlObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/oai/provider/response/list_metadata_formats.rb', line 5

def to_xml
  # Get a list of all the formats the provider understands.
  formats = provider.formats.values
  
  # if it's a doc-specific request
  if options.include?(:identifier)
    id = extract_identifier(options[:identifier])
    unless record = provider.model.find(id, options)
      raise OAI::IdException.new
    end
  
    # Remove any format that this particular record can't be provided in.
    formats.reject! { |f| !record_supports(record, f.prefix) }
    raise OAI::MetadataFormatException if formats.size == 0
  end
  response do |r|
    r.ListMetadataFormats do
      formats.each do |format|
        r.metadataFormat do 
          r.metadataPrefix format.prefix
          r.schema format.schema
          r.metadataNamespace format.namespace
        end
      end
    end
  end
end